public static BitmapSource GetImageForLayer(GridLayer layer, Color lowcolor, Color highcolor, Color novaluecolor, double cutoff = 0, int intervals = 256)
        {
            var palette = CreateGradientPalette(lowcolor, highcolor, novaluecolor, intervals);
            var bmp     = new WriteableBitmap(layer.Width, layer.Height, 96, 96, PixelFormats.Indexed8, palette);

            var range = layer.GetRange();

            if (cutoff == 0 && range != null && range.Range > 0)
            {
                cutoff = range.Min;
            }

            double max = 0;

            if (range != null)
            {
                max = range.Max;
            }

            double dx = Math.Abs(max - cutoff) / (intervals - 1);

            byte[] array = new byte[layer.Width * layer.Height];
            byte   index = 0;

            for (int y = 0; y < layer.Height; y++)
            {
                for (int x = 0; x < layer.Width; x++)
                {
                    var value = layer.GetCellValue(x, (layer.Height - 1) - y);
                    if (value == layer.NoValueMarker)
                    {
                        index = 0;
                    }
                    else
                    {
                        if (value >= cutoff || cutoff == 0)
                        {
                            index = (byte)(((value - cutoff) / dx) + 1);
                        }
                        else
                        {
                            index = 0;
                        }
                    }
                    array[(y * layer.Width) + x] = index;
                }
            }

            Int32Rect r = new Int32Rect(0, 0, layer.Width, layer.Height);

            bmp.WritePixels(r, array, layer.Width, 0, 0);

            return(bmp);
        }
        public GridLayerProperties(GridLayer layer)
        {
            InitializeComponent();
            this.Layer = layer;
            _model     = new List <KeyValuePair <string, object> >();

            _model.Add(new KeyValuePair <string, object>("Width", layer.Width));
            _model.Add(new KeyValuePair <string, object>("Height", layer.Height));
            _model.Add(new KeyValuePair <string, object>("Top (Latitude)", layer.Latitude0));
            _model.Add(new KeyValuePair <string, object>("Left (Longitude)", layer.Longitude0));
            _model.Add(new KeyValuePair <string, object>("Cell size X", layer.DeltaLongitude));
            _model.Add(new KeyValuePair <string, object>("Cell size Y", layer.DeltaLatitude));

            var range = layer.GetRange();

            _model.Add(new KeyValuePair <string, object>("Minimum value", range.Min));
            _model.Add(new KeyValuePair <string, object>("Maximum value", range.Max));
            _model.Add(new KeyValuePair <string, object>("Range", range.Range));
            _model.Add(new KeyValuePair <string, object>("'No Value' value", layer.NoValueMarker));

            lvw.ItemsSource = _model;
        }
Пример #3
0
        public GridLayerProperties(GridLayer layer)
        {
            InitializeComponent();
            this.Layer = layer;
            _model = new List<KeyValuePair<string, object>>();

            _model.Add(new KeyValuePair<string, object>("Width", layer.Width));
            _model.Add(new KeyValuePair<string, object>("Height", layer.Height));
            _model.Add(new KeyValuePair<string, object>("Top (Latitude)", layer.Latitude0));
            _model.Add(new KeyValuePair<string, object>("Left (Longitude)", layer.Longitude0));
            _model.Add(new KeyValuePair<string, object>("Cell size X", layer.DeltaLongitude));
            _model.Add(new KeyValuePair<string, object>("Cell size Y", layer.DeltaLatitude));

            var range = layer.GetRange();

            _model.Add(new KeyValuePair<string, object>("Minimum value", range.Min));
            _model.Add(new KeyValuePair<string, object>("Maximum value", range.Max));
            _model.Add(new KeyValuePair<string, object>("Range", range.Range));
            _model.Add(new KeyValuePair<string, object>("'No Value' value", layer.NoValueMarker));

            lvw.ItemsSource = _model;
        }
Пример #4
0
        public static BitmapSource GetImageForLayer(GridLayer layer, Color lowcolor, Color highcolor, Color novaluecolor, double cutoff = 0, int intervals = 256)
        {
            var palette = CreateGradientPalette(lowcolor, highcolor, novaluecolor, intervals);
            var bmp = new WriteableBitmap(layer.Width, layer.Height, 96, 96, PixelFormats.Indexed8, palette);

            var range = layer.GetRange();

            if (cutoff == 0 && range != null && range.Range > 0) {
                cutoff = range.Min;
            }

            double max = 0;
            if (range != null) {
                max = range.Max;
            }

            double dx = Math.Abs(max - cutoff) / (intervals - 1);
            byte[] array = new byte[layer.Width * layer.Height];
            byte index = 0;
            for (int y = 0; y < layer.Height; y++) {
                for (int x = 0; x < layer.Width; x++) {
                    var value = layer.GetCellValue(x, (layer.Height - 1) - y);
                    if (value == layer.NoValueMarker) {
                        index = 0;
                    } else {
                        if (value >= cutoff || cutoff == 0) {
                            index = (byte) (((value - cutoff) / dx) + 1);
                        } else {
                            index = 0;
                        }
                    }
                    array[(y * layer.Width) + x] = index;
                }
            }

            Int32Rect r= new Int32Rect(0, 0, layer.Width, layer.Height);

            bmp.WritePixels(r, array, layer.Width, 0, 0);

            return bmp;
        }