Exemple #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>
        /// Set the stretch type on the first selected image service layer in the first open 2D map.
        /// </summary>
        /// <param name="stretschType">The stretch type to set on the layer.</param>
        /// <param name="statsType">The stretch statistics type to set on the layer. This lets you pick between Dataset, Area of View (to enable DRA) or Custom statistics.</param>
        /// <returns></returns>
        public static async Task SetStretchTypeAsync(RasterStretchType stretschType, RasterStretchStatsType statsType = RasterStretchStatsType.Dataset)
        {
            try
            {
                // Get the first 2D map from the project that is called Map.
                Map _map = await GetMapFromProject(Project.Current, "Map");

                if (_map == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("SetStretchType: Failed to get map.");
                    return;
                }

                // Get the most recently selected layer.
                Layer firstSelectedLayer = MapView.Active.GetSelectedLayers().First();
                // Check if the first selected layer is an image service layer.
                if (firstSelectedLayer is ImageServiceLayer)
                {
                    // Set the colorizer on the most recently selected layer.
                    // The colorizer has to be set on the Main CIM Thread (MCT).
                    await QueuedTask.Run(() =>
                    {
                        // Get the colorizer from the selected layer.
                        CIMRasterColorizer newColorizer = ((BasicRasterLayer)firstSelectedLayer).GetColorizer();
                        // Set the stretch type and stretch statistics type on the colorizer.
                        // Theese parameters only apply to the Stretch and RGB colorizers.
                        if (newColorizer is CIMRasterRGBColorizer)
                        {
                            ((CIMRasterRGBColorizer)newColorizer).StretchType      = stretschType;
                            ((CIMRasterRGBColorizer)newColorizer).StretchStatsType = statsType;
                        }
                        else if (newColorizer is CIMRasterStretchColorizer)
                        {
                            ((CIMRasterStretchColorizer)newColorizer).StretchType = stretschType;
                            ((CIMRasterStretchColorizer)newColorizer).StatsType   = statsType;
                        }
                        else
                        {
                            MessageBox.Show("Selected layer must be visualized using the RGB or Stretch colorizer");
                        }
                        // Update the image service with the new colorizer
                        ((BasicRasterLayer)firstSelectedLayer).SetColorizer(newColorizer);
                    });
                }
            }
            catch (Exception exc)
            {
                // Catch any exception found and display a message box.
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Exception caught while trying to set stretch type: " + exc.Message);
                return;
            }
        }
Exemple #3
0
        /// <summary>
        /// Applies the RGB 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 SetToRGBColorizer(BasicRasterLayer basicRasterLayer)
        {
            // Defines parameters in colorizer definition.
            int bandIndexR = 2;
            int bandIndexG = 1;
            int bandIndexB = 0;
            RasterStretchType stretchType = RasterStretchType.MinimumMaximum;
            double            gammaR      = 2.0;
            double            gammaG      = 2.0;
            double            gammaB      = 2.0;

            await QueuedTask.Run(async() =>
            {
                // Creates a new RGB Colorizer Definition with defined parameters.
                RGBColorizerDefinition rgbColorizerDef = new RGBColorizerDefinition(bandIndexR, bandIndexG, bandIndexB, stretchType, gammaR, gammaG, gammaB);

                // Creates a new RGB colorizer using the colorizer definition created above.
                CIMRasterRGBColorizer newColorizer = await basicRasterLayer.CreateColorizerAsync(rgbColorizerDef) as CIMRasterRGBColorizer;

                // Sets the newly created colorizer on the layer.
                basicRasterLayer.SetColorizer(newColorizer);
            });
        }