Esempio n. 1
0
        private void btnEditColorClass_Click(object sender, EventArgs e)
        {
            GridColorClass cc = symbolsListView1.UserObject as GridColorClass;

            if (cc == null)
            {
                return;
            }

            FormGridColorClass dlg = new FormGridColorClass();

            dlg.ColorClass = cc;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                cc.MinValue = dlg.MinValue;
                cc.MaxValue = dlg.MaxValue;
                cc.Legend   = dlg.Label;

                symbolsListView1.ValueText =
                    cc.MinValue.ToString() + " - " + cc.MaxValue.ToString();
                symbolsListView1.LegendText =
                    cc.Legend;

                panelGrid.Refresh();
            }
        }
Esempio n. 2
0
        private void btnAddColorClass_Click(object sender, EventArgs e)
        {
            FormGridColorClass dlg = new FormGridColorClass();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                GridColorClass cc = new GridColorClass(
                    dlg.MinValue, dlg.MaxValue, GraphicsEngine.ArgbColor.White);
                cc.Legend = dlg.Label;

                _classes.Add(cc);

                SimpleFillSymbol symbol = new SimpleFillSymbol();
                symbol.OutlineColor = GraphicsEngine.ArgbColor.Transparent;
                symbol.Color        = cc.Color;

                symbolsListView1.addSymbol(
                    symbol,
                    new string[] { dlg.MinValue.ToString() + " - " + dlg.MaxValue.ToString(), dlg.Label },
                    cc
                    );

                panelGrid.Refresh();
            }
        }
Esempio n. 3
0
        private void btnRemoveColorClass_Click(object sender, EventArgs e)
        {
            GridColorClass cc = symbolsListView1.UserObject as GridColorClass;

            if (cc == null)
            {
                return;
            }

            _classes.Remove(cc);
            symbolsListView1.RemoveSelected();

            panelGrid.Refresh();
        }
Esempio n. 4
0
        private void panelGrid_Paint(object sender, PaintEventArgs e)
        {
            int height = panelGrid.Height - 20;

            if (height <= 0 || _max - _min <= 0)
            {
                return;
            }

            GridColorClass[] classes = this.GridColorClasses;
            for (int y = 0; y < height; y++)
            {
                double h = _max - (double)y * (_max - _min) / (double)height;
                using (Pen pen = new Pen(GridColorClass.FindColor(h, classes).ToGdiColor(), 1))
                {
                    e.Graphics.DrawLine(pen, 1, y + 10, 20, y + 10);
                }
            }

            using (Font font = new Font("Arial", 8))
            {
                using (SolidBrush brush = new SolidBrush(Color.Black))
                {
                    foreach (GridColorClass cc in _classes)
                    {
                        if (String.IsNullOrEmpty(cc.Legend))
                        {
                            continue;
                        }

                        double h = cc.MaxValue * 0.5 + cc.MinValue * 0.5;
                        int    y = (int)((_max - h) * (double)height / (_max - _min));

                        e.Graphics.DrawString(cc.Legend, font, brush, 22, y + 5);
                    }
                }
            }
        }
Esempio n. 5
0
        void symbolsListView1_OnSymbolClicked(ISymbol symbol)
        {
            if (!(symbol is SimpleFillSymbol))
            {
                return;
            }
            GridColorClass cc = symbolsListView1.UserObject as GridColorClass;

            if (cc == null)
            {
                return;
            }

            ColorDialog dlg = new ColorDialog();

            dlg.Color = cc.Color.ToGdiColor();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                cc.Color = dlg.Color.ToArgbColor();
                ((SimpleFillSymbol)symbol).Color = cc.Color;
            }

            panelGrid.Refresh();
        }
Esempio n. 6
0
        private void PaintHillShade(int x, int y, int wWidth, int wHeight, int iWidth, int iHeight, double mag, ICancelTracker cancelTracker)
        {
            if (CancelTracker.Canceled(cancelTracker) || _gDS == null)
            {
                return;
            }

            int        pixelSpace = 4;
            Bitmap     bitmap     = new Bitmap(iWidth, iHeight + 100, PixelFormat.Format32bppArgb);
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, iWidth, iHeight + 100), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            OSGeo.GDAL.Band band = null;

            try
            {
                int    stride = bitmapData.Stride;
                IntPtr buf    = bitmapData.Scan0;

                List <Color> colors = new List <Color>();
                using (band = _gDS.GetRasterBand(1))
                {
                    band.ReadRaster(x, y, wWidth, wHeight,
                                    buf,
                                    iWidth, iHeight, OSGeo.GDAL.DataType.GDT_CFloat32, pixelSpace, stride);

                    band.Dispose();
                }

                double cx = _tfw.cellX / mag;
                double cy = _tfw.cellY / mag;

                Vector3d sun = new Vector3d(_hillShade);
                sun.Normalize();
                int rowStride = stride / pixelSpace;

                Color col = Color.White;
                unsafe
                {
                    byte * ptr = (byte *)(bitmapData.Scan0);
                    float *v   = (float *)(bitmapData.Scan0);

                    for (int i = 0; i < iHeight; i++)
                    {
                        if (CancelTracker.Canceled(cancelTracker))
                        {
                            return;
                        }
                        for (int j = 0; j < iWidth; j++)
                        {
                            if ((_hasNoDataVal == 1 && *v == _nodata) ||
                                (_useIgnoreValue && *v == _ignoreValue))
                            {
                                ptr[0] = ptr[1] = ptr[2] = ptr[3] = 0;
                            }
                            else
                            {
                                double c = *v;

                                col = GridColorClass.FindColor(c, _colorClasses);
                                if (!_useHillShade)
                                {
                                    ptr[0] = (byte)col.B; ptr[1] = (byte)col.G; ptr[2] = (byte)col.R;
                                    ptr[3] = (byte)col.A; // alpha
                                }
                                else
                                {
                                    double c1 = (j < iWidth - 1) ? (*(v + 1)) : c;
                                    double c2 = (i < iHeight - 1) ? (*(v + rowStride)) : c;
                                    c1 = ((_hasNoDataVal != 0 && c1 == _nodata) ||
                                          (_useIgnoreValue && c1 == _ignoreValue)) ? c : c1;
                                    c2 = ((_hasNoDataVal != 0 && c2 == _nodata) ||
                                          (_useIgnoreValue && c2 == _ignoreValue)) ? c : c2;

                                    Vector3d v1 = new Vector3d(cx, 0.0, c1 - c); v1.Normalize();
                                    Vector3d v2 = new Vector3d(0.0, -cy, c2 - c); v2.Normalize();
                                    Vector3d vs = v2 % v1; vs.Normalize();
                                    double   h  = Math.Min(Math.Max(0.0, sun * vs), 1.0);
                                    //double h = Math.Abs(sun * vs);

                                    double a = col.A;
                                    double r = col.R * h;
                                    double g = col.G * h;
                                    double b = col.B * h;
                                    ptr[0] = (byte)b; ptr[1] = (byte)g; ptr[2] = (byte)r;
                                    ptr[3] = (byte)a; // alpha
                                }
                            }
                            ptr += pixelSpace;
                            v++;
                        }
                        ptr += bitmapData.Stride - (bitmapData.Width) * pixelSpace;
                        v    = (float *)ptr;
                    }
                }
                if (bitmap != null)
                {
                    bitmap.UnlockBits(bitmapData);
                }

                _bitmap = new Bitmap(iWidth, iHeight, PixelFormat.Format32bppArgb);
                using (Graphics gr = Graphics.FromImage(_bitmap))
                {
                    gr.DrawImage(bitmap, 0, 0);
                }
            }
            catch { }
            finally
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
            }
        }
Esempio n. 7
0
        private IRasterPaintContext PaintHillShade(int x, int y, int wWidth, int wHeight, int iWidth, int iHeight, double mag, ICancelTracker cancelTracker)
        {
            if (CancelTracker.Canceled(cancelTracker) || _gDS == null)
            {
                return(null);
            }

            int pixelSpace = 4;

            using (var bitmap = GraphicsEngine.Current.Engine.CreateBitmap(iWidth, iHeight + 100, GraphicsEngine.PixelFormat.Rgba32))
            {
                var bitmapData          = bitmap.LockBitmapPixelData(GraphicsEngine.BitmapLockMode.ReadWrite, GraphicsEngine.PixelFormat.Rgba32);
                OSGeo_v1.GDAL.Band band = null;

                try
                {
                    int    stride = bitmapData.Stride;
                    IntPtr buf    = bitmapData.Scan0;

                    List <ArgbColor> colors = new List <ArgbColor>();
                    using (band = _gDS.GetRasterBand(1))
                    {
                        band.ReadRaster(x, y, wWidth, wHeight,
                                        buf,
                                        iWidth, iHeight, OSGeo_v1.GDAL.DataType.GDT_CFloat32, pixelSpace, stride);

                        band.Dispose();
                    }

                    double cx = _tfw.cellX / mag;
                    double cy = _tfw.cellY / mag;

                    Vector3d sun = new Vector3d(_hillShade);
                    sun.Normalize();
                    int rowStride = stride / pixelSpace;

                    ArgbColor col = ArgbColor.White;
                    unsafe
                    {
                        byte * ptr = (byte *)(bitmapData.Scan0);
                        float *v   = (float *)(bitmapData.Scan0);

                        float floatNodata = (float)_nodata;

                        for (int i = 0; i < iHeight; i++)
                        {
                            if (CancelTracker.Canceled(cancelTracker))
                            {
                                return(null);
                            }

                            for (int j = 0; j < iWidth; j++)
                            {
                                if ((_hasNoDataVal == 1 && *v == floatNodata) ||
                                    (_useIgnoreValue && *v == _ignoreValue))
                                {
                                    ptr[0] = ptr[1] = ptr[2] = ptr[3] = 0;
                                }
                                else
                                {
                                    double c = *v;

                                    col = GridColorClass.FindColor(c, _colorClasses);
                                    if (!_useHillShade)
                                    {
                                        ptr[0] = col.B; ptr[1] = col.G; ptr[2] = col.R;
                                        ptr[3] = col.A; // alpha
                                    }
                                    else
                                    {
                                        double c1 = (j < iWidth - 1) ? (*(v + 1)) : c;
                                        double c2 = (i < iHeight - 1) ? (*(v + rowStride)) : c;
                                        c1 = ((_hasNoDataVal != 0 && c1 == floatNodata) ||
                                              (_useIgnoreValue && c1 == _ignoreValue)) ? c : c1;
                                        c2 = ((_hasNoDataVal != 0 && c2 == floatNodata) ||
                                              (_useIgnoreValue && c2 == _ignoreValue)) ? c : c2;

                                        Vector3d v1 = new Vector3d(cx, 0.0, c1 - c); v1.Normalize();
                                        Vector3d v2 = new Vector3d(0.0, -cy, c2 - c); v2.Normalize();
                                        Vector3d vs = v2 % v1; vs.Normalize();
                                        double   h  = Math.Min(Math.Max(0.0, sun * vs), 1.0);
                                        //double h = Math.Abs(sun * vs);

                                        double a = col.A;
                                        double r = col.R * h;
                                        double g = col.G * h;
                                        double b = col.B * h;
                                        ptr[0] = (byte)b; ptr[1] = (byte)g; ptr[2] = (byte)r;
                                        ptr[3] = (byte)a; // alpha
                                    }
                                }
                                ptr += pixelSpace;
                                v++;
                            }
                            ptr += bitmapData.Stride - (bitmapData.Width) * pixelSpace;
                            v    = (float *)ptr;
                        }
                    }
                    if (bitmap != null)
                    {
                        bitmap.UnlockBitmapPixelData(bitmapData);
                        bitmapData = null;
                    }

                    var contextBitmap = GraphicsEngine.Current.Engine.CreateBitmap(iWidth, iHeight, GraphicsEngine.PixelFormat.Rgba32);
                    using (var gr = contextBitmap.CreateCanvas())
                    {
                        gr.DrawBitmap(bitmap, new GraphicsEngine.CanvasPoint(0, 0));
                    }

                    return(new RasterPaintContext(contextBitmap));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (bitmap != null && bitmapData != null)
                    {
                        bitmap.UnlockBitmapPixelData(bitmapData);
                    }
                }
            }
        }