Using C# with ArcGISRuntime, how do I use a StretchRenderer to make a grayscale color ramp?

05-02-2017 07:16 AM
Occasional Contributor

Using C# with ArcGISRuntime I need to display raster data on a map.  Right now I have the following code that successfully displays an elevation raster (DEM) on the map.  However, I have other rasters that are not displayed correctly using this color ramp.  When I bring them into Arc Map, they are displayed the way I want them, as grayscale images.  How can I define a StretchRenderer that would be a grayscale color ramp, that would make these rasters appear the same as they do when bringing them into Arc Map?

        private void AddRasterLayer(string rasterPath, string id)
            var newRaster = new Raster(rasterPath);           
            var newRasterLayer = new RasterLayer(newRaster);
            newRasterLayer.Id = id;

            // Code to get the min and max values for the MinMaxStretchParameters object
            double[,] rasterArray = Conversions.RasterToArray(rasterPath);
            double max = SoilMoisturePreprocessing.Max2d(rasterArray);
            double[] minVals = { 0 };// 0
            double[] maxVals = { (int)max + 1 };
            MinMaxStretchParameters minMaxParams = new MinMaxStretchParameters(minVals, maxVals);

            ColorRamp elevationColorRamp = ColorRamp.Create(PresetColorRampType.Elevation);
            var rendrr = new StretchRenderer(minMaxParams, null, true, elevationColorRamp);
            newRasterLayer.Renderer = rendrr;
            newRasterLayer.Opacity = 0.6;

            var mapViewModel = ServiceLocator.Current.GetInstance<MapViewModel>();

0 Replies