/// <summary> /// Applies the Unique Value 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 SetToUniqueValueColorizer(BasicRasterLayer basicRasterLayer) { // Creates a new UV Colorizer Definition using the default constructor. UniqueValueColorizerDefinition UVColorizerDef = new UniqueValueColorizerDefinition(); // Creates a new UV colorizer using the colorizer definition created above. CIMRasterUniqueValueColorizer newColorizer = await basicRasterLayer.CreateColorizerAsync(UVColorizerDef) as CIMRasterUniqueValueColorizer; // Sets the newly created colorizer on the layer. await QueuedTask.Run(() => { basicRasterLayer.SetColorizer(newColorizer); }); }
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)); }); }