コード例 #1
0
        /// <summary>
        /// Applies the Stretch colorizer to the basic raster layer.
        /// </summary>
        /// <param name="basicRasterLayer">The basic raster layer is either a raster or image service layer, or the image sub-layer of the mosaic layer.</param>
        /// <returns></returns>
        public static async Task SetToStretchColorizer(BasicRasterLayer basicRasterLayer)
        {
            // Defines parameters in colorizer definition.
            int bandIndex = 0;
            RasterStretchType stretchType    = RasterStretchType.MinimumMaximum;
            double            gamma          = 2.0;
            string            colorRampStyle = "ArcGIS Colors";
            string            colorRampName  = "Aspect";

            await QueuedTask.Run(async() =>
            {
                // Gets a color ramp from a style.
                IList <ColorRampStyleItem> rampList = GetColorRampsFromStyleAsync(Project.Current, colorRampStyle, colorRampName);
                CIMColorRamp colorRamp = rampList[0].ColorRamp;

                // Creates a new Stretch Colorizer Definition with defined parameters.
                StretchColorizerDefinition stretchColorizerDef = new StretchColorizerDefinition(bandIndex, stretchType, gamma, colorRamp);

                // Creates a new stretch colorizer using the colorizer definition created above.
                CIMRasterStretchColorizer newColorizer = await basicRasterLayer.CreateColorizerAsync(stretchColorizerDef) as CIMRasterStretchColorizer;

                // Sets the newly created colorizer on the layer.
                basicRasterLayer.SetColorizer(newColorizer);
            });
        }
        /// <summary>
        /// Warning! You must call this method on the MCT!
        /// </summary>
        /// <returns></returns>
        private CIMRasterStretchColorizer CreateStretchRendererFromScratch(double min, double max)
        {
            //All of these methods have to be called on the MCT
            if (Module1.OnUIThread)
            {
                throw new CalledOnWrongThreadException();
            }

            var colors = getColors();

            var multiPartRamp = new CIMMultipartColorRamp
            {
                Weights = new double[colors.GetLength(0)]
            };

            CIMColorRamp[] rampValues = new CIMColorRamp[colors.GetLength(0)];
            for (int i = 0; i < colors.GetLength(0) - 1; i++)
            {
                var ramp = new CIMPolarContinuousColorRamp();
                var r    = colors[i, 0];
                var g    = colors[i, 1];
                var b    = colors[i, 2];
                ramp.FromColor = new CIMRGBColor()
                {
                    R = r, G = g, B = b
                };
                r            = colors[i + 1, 0];
                g            = colors[i + 1, 1];
                b            = colors[i + 1, 2];
                ramp.ToColor = new CIMRGBColor()
                {
                    R = r, G = g, B = b
                };
                ramp.PolarDirection      = PolarDirection.Clockwise;
                rampValues[i]            = ramp;
                multiPartRamp.Weights[i] = 1;
            }
            multiPartRamp.Weights[colors.GetLength(0) - 1] = 1;

            multiPartRamp.ColorRamps = rampValues;

            var colorizer = new CIMRasterStretchColorizer
            {
                ColorRamp              = multiPartRamp,
                StretchType            = RasterStretchType.StandardDeviations,
                StandardDeviationParam = 2,
                // in order to see the label on the layer we must add at least three values
                StretchClasses = new CIMRasterStretchClass[3]
            };

            colorizer.StretchClasses[0] = new CIMRasterStretchClass()
            {
                Value = min, Label = min.ToString()
            };
            colorizer.StretchClasses[1] = new CIMRasterStretchClass()
            {
                Value = max / 2
            };
            colorizer.StretchClasses[2] = new CIMRasterStretchClass()
            {
                Value = max, Label = max.ToString()
            };

            return(colorizer);
        }