示例#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);
            });
        }
        public async Task ApplyColorRampAsync(FeatureLayer featureLayer, string[] fields)
        {
            StyleProjectItem style =
                Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(s => s.Name == "ColorBrewer Schemes (RGB)");

            if (style == null)
            {
                return;
            }
            var colorRampList = await QueuedTask.Run(() => style.SearchColorRamps("Red-Gray (10 Classes)"));

            if (colorRampList == null || colorRampList.Count == 0)
            {
                return;
            }
            CIMColorRamp cimColorRamp = null;
            CIMRenderer  renderer     = null;
            await QueuedTask.Run(() =>
            {
                cimColorRamp    = colorRampList[0].ColorRamp;
                var rendererDef = new UniqueValueRendererDefinition(fields, null, cimColorRamp);
                renderer        = featureLayer?.CreateRenderer(rendererDef);
                featureLayer?.SetRenderer(renderer);
            });
        }
示例#3
0
        /// <summary>
        /// Applies the Classify 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 SetToClassifyColorizer(BasicRasterLayer basicRasterLayer)
        {
            // Defines values for parameters in colorizer definition.
            string fieldName = "Value";
            ClassificationMethod classificationMethod = ClassificationMethod.NaturalBreaks;
            int    numberofClasses = 7;
            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 Classify Colorizer Definition using defined parameters.
                ClassifyColorizerDefinition classifyColorizerDef = new ClassifyColorizerDefinition(fieldName, numberofClasses, classificationMethod, colorRamp);

                // Creates a new Classify colorizer using the colorizer definition created above.
                CIMRasterClassifyColorizer newColorizer = await basicRasterLayer.CreateColorizerAsync(classifyColorizerDef) as CIMRasterClassifyColorizer;

                // Sets the newly created colorizer on the layer.
                basicRasterLayer.SetColorizer(newColorizer);
            });
        }
 private static async void SetRasterColorByAttributeField(RasterLayer raster, string fieldName, StyleProjectItem styleProjItem)
 {
     await QueuedTask.Run(() =>
     {
         var ramps = styleProjItem.SearchColorRamps("Green Blues");
         CIMColorRamp colorRamp = ramps[0].ColorRamp;
         var colorizerDef       = new UniqueValueColorizerDefinition(fieldName, colorRamp);
         var colorizer          = raster.CreateColorizer(colorizerDef);
         // fix up colorizer ... due to a problem with getting the values for different attribute table fields:
         // we use the Raster's attribute table to collect a dictionary with the correct replacement values
         Dictionary <string, string> landuseToFieldValue = new Dictionary <string, string>();
         if (colorizer is CIMRasterUniqueValueColorizer uvrColorizer)
         {
             var rasterTbl = raster.GetRaster().GetAttributeTable();
             var cursor    = rasterTbl.Search();
             while (cursor.MoveNext())
             {
                 var row          = cursor.Current;
                 var correctField = row[fieldName].ToString();
                 var key          = row[uvrColorizer.Groups[0].Heading].ToString();
                 landuseToFieldValue.Add(key.ToLower(), correctField);
             }
             uvrColorizer.Groups[0].Heading = fieldName;
             for (var idxGrp = 0; idxGrp < uvrColorizer.Groups[0].Classes.Length; idxGrp++)
             {
                 var grpClass       = uvrColorizer.Groups[0].Classes[idxGrp];
                 var oldValue       = grpClass.Values[0].ToLower();
                 var correctField   = landuseToFieldValue[oldValue];
                 grpClass.Values[0] = correctField;
                 grpClass.Label     = $@"{correctField}";
             }
         }
         raster.SetColorizer(colorizer);
     });
 }
示例#5
0
        public static async Task SetToUniqueValueColorizer(string layerName, string styleCategory,
                                                           string styleName, string fieldName)
        {
            // Get the layer we want to symbolize from the map
            Layer oLayer =
                MapView.Active.Map.Layers.FirstOrDefault <Layer>(m => m.Name.Equals(layerName, StringComparison.CurrentCultureIgnoreCase));

            if (oLayer == null)
            {
                return;
            }
            RasterLayer rasterLayer = (RasterLayer)oLayer;

            StyleProjectItem style =
                Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(s => s.Name == styleCategory);

            if (style == null)
            {
                return;
            }
            var colorRampList = await QueuedTask.Run(() => style.SearchColorRamps(styleName));

            if (colorRampList == null || colorRampList.Count == 0)
            {
                return;
            }
            CIMColorRamp cimColorRamp = colorRampList[0].ColorRamp;

            // Creates a new UV Colorizer Definition using the default constructor.
            UniqueValueColorizerDefinition UVColorizerDef = new UniqueValueColorizerDefinition(fieldName, cimColorRamp);

            // Creates a new UV colorizer using the colorizer definition created above.
            CIMRasterUniqueValueColorizer newColorizer = await rasterLayer.CreateColorizerAsync(UVColorizerDef) as CIMRasterUniqueValueColorizer;

            // Sets the newly created colorizer on the layer.
            await QueuedTask.Run(() =>
            {
                rasterLayer.SetColorizer(MapTools.RecalculateColorizer(newColorizer));
            });
        }
示例#6
0
        /// <summary>
        /// Applies the Discrete Color 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 SetToDiscreteColorColorizer(BasicRasterLayer basicRasterLayer)
        {
            // Defines values for parameters in colorizer definition.
            int    numColors      = 50;
            string colorRampName  = "Aspect";
            string colorRampStyle = "ArcGIS Colors";

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

                // Creates a new Discrete Colorizer Definition using the default constructor.
                DiscreteColorizerDefinition discreteColorizerDef = new DiscreteColorizerDefinition(numColors, colorRamp);

                // Creates a new Discrete colorizer using the colorizer definition created above.
                CIMRasterDiscreteColorColorizer newColorizer = await basicRasterLayer.CreateColorizerAsync(discreteColorizerDef) as CIMRasterDiscreteColorColorizer;

                // 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);
        }
示例#8
0
        public async void Examples()
        {
            #region Get symbol from SymbolStyleItem
            SymbolStyleItem symbolItem = null;
            CIMSymbol       symbol     = await QueuedTask.Run <CIMSymbol>(() =>
            {
                return(symbolItem.Symbol);
            });

            #endregion

            #region Get color from ColorStyleItem
            ColorStyleItem colorItem = null;
            CIMColor       color     = await QueuedTask.Run <CIMColor>(() =>
            {
                return(colorItem.Color);
            });

            #endregion

            #region Get color ramp from ColorRampStyleItem
            ColorRampStyleItem colorRampItem = null;
            CIMColorRamp       colorRamp     = await QueuedTask.Run <CIMColorRamp>(() =>
            {
                return(colorRampItem.ColorRamp);
            });

            #endregion

            #region Get north arrow from NorthArrowStyleItem
            NorthArrowStyleItem northArrowItem = null;
            CIMNorthArrow       northArrow     = await QueuedTask.Run <CIMNorthArrow>(() =>
            {
                return(northArrowItem.NorthArrow);
            });

            #endregion

            #region Get scale bar from ScaleBarStyleItem
            ScaleBarStyleItem scaleBarItem = null;
            CIMScaleBar       scaleBar     = await QueuedTask.Run <CIMScaleBar>(() =>
            {
                return(scaleBarItem.ScaleBar);
            });

            #endregion

            #region Get label placement from LabelPlacementStyleItem
            LabelPlacementStyleItem     labelPlacementItem = null;
            CIMLabelPlacementProperties labelPlacement     = await QueuedTask.Run <CIMLabelPlacementProperties>(() =>
            {
                return(labelPlacementItem.LabelPlacement);
            });

            #endregion

            #region Get grid from GridStyleItem
            GridStyleItem gridItem = null;
            CIMMapGrid    grid     = await QueuedTask.Run <CIMMapGrid>(() =>
            {
                return(gridItem.Grid);
            });

            #endregion

            #region Get legend from LegendStyleItem
            LegendStyleItem legendItem = null;
            CIMLegend       legend     = await QueuedTask.Run <CIMLegend>(() =>
            {
                return(legendItem.Legend);
            });

            #endregion

            #region Get table frame from TableFrameStyleItem
            TableFrameStyleItem tableFrameItem = null;
            CIMTableFrame       tableFrame     = await QueuedTask.Run <CIMTableFrame>(() =>
            {
                return(tableFrameItem.TableFrame);
            });

            #endregion

            #region Get map surround from MapSurroundStyleItem
            MapSurroundStyleItem mapSurroundItem = null;
            CIMMapSurround       mapSurround     = await QueuedTask.Run <CIMMapSurround>(() =>
            {
                return(mapSurroundItem.MapSurround);
            });

            #endregion
        }