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); }); }
/// <summary> /// Renders a feature layer using graduated colors to draw quantities. /// ![cb-colors.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/cb-colors.png "Graduated colors with natural breaks renderer.") /// </summary> /// <param name="featureLayer"></param> /// <returns> /// </returns> internal static async Task CBRendererGraduatedColors(FeatureLayer featureLayer) { await QueuedTask.Run(() => { GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition() { ClassificationField = SDKHelpers.GetNumericField(featureLayer), ClassificationMethod = ClassificationMethod.NaturalBreaks, BreakCount = 5, ColorRamp = SDKHelpers.GetColorRamp(), }; CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(gcDef); featureLayer?.SetRenderer(renderer); }); }
private CIMRenderer CreateniqueValueRendererForUSStatesUsingDefinition(FeatureLayer featureLayer) { //All of these methods have to be called on the MCT if (Module1.OnUIThread) { throw new CalledOnWrongThreadException(); } // color ramp CIMICCColorSpace colorSpace = new CIMICCColorSpace() { URL = "Default RGB" }; CIMContinuousColorRamp continuousColorRamp = new CIMLinearContinuousColorRamp(); continuousColorRamp.FromColor = CIMColor.CreateRGBColor(255, 255, 100); // yellow continuousColorRamp.ToColor = CIMColor.CreateRGBColor(255, 0, 0); // red continuousColorRamp.ColorSpace = colorSpace; CIMRandomHSVColorRamp randomHSVColorRamp = new CIMRandomHSVColorRamp() { ColorSpace = colorSpace, MinAlpha = 100, MaxAlpha = 100, MinH = 0, MaxH = 360, MinS = 15, MaxS = 30, MinV = 99, MaxV = 100, Seed = 0 }; UniqueValueRendererDefinition uvRendererDef = new UniqueValueRendererDefinition() { ColorRamp = continuousColorRamp, // randomHSVColorRamp, UseDefaultSymbol = true, ValueFields = new List <string> { "TOTPOP2010" } }; //Configure the Renderer using the layer and the contents of the STATENAM //field return(featureLayer.CreateRenderer(uvRendererDef)); }
/// <summary> /// Renders a feature layer using graduated symbols and natural breaks to draw quantities. /// ![cb-symbols.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/cb-symbols.png "Graduated symbols with natural breaks renderer.") /// </summary> /// <param name="featureLayer"></param> /// <returns> /// </returns> internal static async Task CBRendererGraduatedSymbols(FeatureLayer featureLayer) { await QueuedTask.Run(() => { GraduatedSymbolsRendererDefinition gsDef = new GraduatedSymbolsRendererDefinition() { ClassificationField = SDKHelpers.GetNumericField(featureLayer), //getting the first numeric field ClassificationMethod = ClassificationMethod.NaturalBreaks, MinimumSymbolSize = 4, MaximumSymbolSize = 50, BreakCount = 5, ColorRamp = SDKHelpers.GetColorRamp(), //getting a color ramp }; CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(gsDef); featureLayer?.SetRenderer(renderer); }); }
/// <summary> /// Renders a feature layer using graduated colors to draw quantities. The outline width is varied based on attributes. /// ![graduatedColorOutline.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/graduatedColorOutline.png "Graduated colors with natural breaks renderer.") /// </summary> /// <param name="featureLayer"></param> /// <returns></returns> internal static Task CBRendererGraduatedColorsOutline(FeatureLayer featureLayer) { return(QueuedTask.Run(() => { //Gets the first numeric field of the feature layer var firstNumericFieldOfFeatureLayer = SDKHelpers.GetNumericField(featureLayer); //Gets the min and max value of the field var minMax = SDKHelpers.GetFieldMinMax(featureLayer, firstNumericFieldOfFeatureLayer); GraduatedColorsRendererDefinition gcDef = new GraduatedColorsRendererDefinition() { ClassificationField = SDKHelpers.GetNumericField(featureLayer), ClassificationMethod = ClassificationMethod.NaturalBreaks, BreakCount = 5, ColorRamp = SDKHelpers.GetColorRamp() }; CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(gcDef); //Create array of CIMVisualVariables to hold the outline information. var visualVariables = new CIMVisualVariable[] { new CIMSizeVisualVariable { ValueExpressionInfo = new CIMExpressionInfo { Title = "Custom", Expression = "$feature.AREA", ReturnType = ExpressionReturnType.Default }, AuthoringInfo = new CIMVisualVariableAuthoringInfo { MinSliderValue = Convert.ToDouble(minMax.Item1), MaxSliderValue = Convert.ToDouble(minMax.Item2), ShowLegend = false, Heading = firstNumericFieldOfFeatureLayer }, VariableType = SizeVisualVariableType.Graduated, Target = "outline", MinSize = 1, MaxSize = 13, MinValue = Convert.ToDouble(minMax.Item1), MaxValue = Convert.ToDouble(minMax.Item2) }, }; renderer.VisualVariables = visualVariables; featureLayer?.SetRenderer(renderer); })); }
/// <summary> /// Renders a point feature layer using a continuous color gradient to represent density of points. /// </summary> /// <remarks> /// ![Heat map renderer](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/heat-map.png) /// </remarks> /// <param name="featureLayer"></param> /// <returns> /// </returns> internal static Task HeatMapRenderersAsync(FeatureLayer featureLayer) { return(QueuedTask.Run(() => { //defining a heatmap renderer that uses values from Population field as the weights HeatMapRendererDefinition heatMapDef = new HeatMapRendererDefinition() { Radius = 20, WeightField = SDKHelpers.GetNumericField(featureLayer), ColorRamp = SDKHelpers.GetColorRamp(), RendereringQuality = 8, UpperLabel = "High Density", LowerLabel = "Low Density" }; CIMHeatMapRenderer heatMapRndr = (CIMHeatMapRenderer)featureLayer.CreateRenderer(heatMapDef); featureLayer.SetRenderer(heatMapRndr); })); }
/// <summary> /// Renders a feature layer using unique values from one or multiple fields /// </summary> /// <remarks> /// ![Unique Value renderer](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/unique-value.png) /// </remarks> /// <param name="featureLayer"></param> /// <returns> /// ![Unique Value renderer](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/unique-value.png) /// </returns> internal static Task UniqueValueRendererAsync(FeatureLayer featureLayer) { return(QueuedTask.Run(() => { //construct unique value renderer definition UniqueValueRendererDefinition uvr = new UniqueValueRendererDefinition() { ValueFields = new string[] { SDKHelpers.GetDisplayField(featureLayer) }, //multiple fields in the array if needed. ColorRamp = SDKHelpers.GetColorRamp(), //Specify color ramp }; //Creates a "Renderer" var cimRenderer = featureLayer.CreateRenderer(uvr); //Sets the renderer to the feature layer featureLayer.SetRenderer(cimRenderer); })); }
/// <summary> /// Renders a feature layer using proportional symbols to draw quantities. /// ![Proportional Symbols renderer](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/proportional-renderer.png) /// </summary> /// <remarks></remarks> /// <param name="featureLayer"></param> /// <returns></returns> internal static Task ProportionalRenderer(FeatureLayer featureLayer) { return(QueuedTask.Run(() => { //Gets the first numeric field of the feature layer var firstNumericFieldOfFeatureLayer = SDKHelpers.GetNumericField(featureLayer); //Gets the min and max value of the field var sizes = SDKHelpers.GetFieldMinMax(featureLayer, firstNumericFieldOfFeatureLayer); ProportionalRendererDefinition prDef = new ProportionalRendererDefinition() { Field = firstNumericFieldOfFeatureLayer, MinimumSymbolSize = 4, MaximumSymbolSize = 50, LowerSizeStop = Convert.ToDouble(sizes.Item1), UpperSizeStop = Convert.ToDouble(sizes.Item2) }; CIMProportionalRenderer propRndr = (CIMProportionalRenderer)featureLayer.CreateRenderer(prDef); featureLayer.SetRenderer(propRndr); })); }
/// <summary> /// Renders a feature layer using an unclassed color gradient. /// ![cb-unclassed.png](http://Esri.github.io/arcgis-pro-sdk/images/Renderers/cb-unclassed.png "Class breaks unclassed renderer.") /// </summary> /// <param name="featureLayer"></param> /// <returns> /// </returns> internal static Task UnclassedRenderer(FeatureLayer featureLayer) { return(QueuedTask.Run(() => { //Gets the first numeric field of the feature layer var firstNumericFieldOfFeatureLayer = SDKHelpers.GetNumericField(featureLayer); //Gets the min and max value of the field var labels = SDKHelpers.GetFieldMinMax(featureLayer, firstNumericFieldOfFeatureLayer); UnclassedColorsRendererDefinition ucDef = new UnclassedColorsRendererDefinition() { Field = firstNumericFieldOfFeatureLayer, ColorRamp = SDKHelpers.GetColorRamp(), LowerColorStop = Convert.ToDouble(labels.Item1), UpperColorStop = Convert.ToDouble(labels.Item2), UpperLabel = labels.Item2, LowerLabel = labels.Item1, }; CIMClassBreaksRenderer renderer = (CIMClassBreaksRenderer)featureLayer.CreateRenderer(ucDef); featureLayer?.SetRenderer(renderer); })); }
private CIMRenderer CreateniqueValueRendererForUSHighwaysUsingDefinition(FeatureLayer featureLayer) { //All of these methods have to be called on the MCT if (Module1.OnUIThread) throw new CalledOnWrongThreadException(); // color ramp CIMICCColorSpace colorSpace = new CIMICCColorSpace() { URL = "Default RGB" }; CIMContinuousColorRamp continuousColorRamp = new CIMLinearContinuousColorRamp(); continuousColorRamp.FromColor = CIMColor.CreateRGBColor(0, 0, 255); // yellow continuousColorRamp.ToColor = CIMColor.CreateRGBColor(255, 0, 0); // red continuousColorRamp.ColorSpace = colorSpace; CIMRandomHSVColorRamp randomHSVColorRamp = new CIMRandomHSVColorRamp() { ColorSpace = colorSpace, MinAlpha = 100, MaxAlpha = 100, MinH = 0, MaxH = 360, MinS = 15, MaxS = 30, MinV = 99, MaxV = 100, Seed = 0 }; UniqueValueRendererDefinition uvRendererDef = new UniqueValueRendererDefinition() { ColorRamp = continuousColorRamp, //randomHSVColorRamp, UseDefaultSymbol = true, ValueFields = new string[] {"ROUTE_NUM"} }; //Configure the Renderer using the featureLayer and the contents of the STATENAM //field return featureLayer.CreateRenderer(uvRendererDef); }
private Task ChangeUSHighwaysLayerDataConnectionAsync(FeatureLayer featureLayer, string catalogPath) { return(QueuedTask.Run(() => { CIMDataConnection currentDataConnection = featureLayer.GetDataConnection(); string connection = System.IO.Path.GetDirectoryName(catalogPath); string suffix = System.IO.Path.GetExtension(connection).ToLower(); var workspaceConnectionString = string.Empty; WorkspaceFactory wf = WorkspaceFactory.FileGDB; if (suffix == ".sde") { wf = WorkspaceFactory.SDE; var dbGdbConnection = new DatabaseConnectionFile(new Uri(connection, UriKind.Absolute)); workspaceConnectionString = new Geodatabase(dbGdbConnection).GetConnectionString(); } else { var dbGdbConnectionFile = new FileGeodatabaseConnectionPath(new Uri(connection, UriKind.Absolute)); workspaceConnectionString = new Geodatabase(dbGdbConnectionFile).GetConnectionString(); } string dataset = System.IO.Path.GetFileName(catalogPath); // provide a replace data connection method CIMStandardDataConnection updatedDataConnection = new CIMStandardDataConnection() { WorkspaceConnectionString = workspaceConnectionString, WorkspaceFactory = wf, Dataset = dataset, DatasetType = esriDatasetType.esriDTFeatureClass }; featureLayer.SetDataConnection(updatedDataConnection); //For a RDBMS, it might look like this: //string connection = "C:\\Work\\temp.sde"; //Geodatabase sde = new Geodatabase(connection); //// provide a replace data connection method //CIMStandardDataConnection updatedDataConnection = new CIMStandardDataConnection(); //updatedDataConnection.WorkspaceConnectionString = sde.GetConnectionString(); //updatedDataConnection.WorkspaceFactory = WorkspaceFactory.SDE; //updatedDataConnection.Dataset = "vtest.usa.states"; //updatedDataConnection.DatasetType = esriDatasetType.esriDTFeatureClass; //// Alternatively, use Layer.FindAndReplaceWorkspacePath() ////Note: this will not allow changing the dataset name or workspace type //// ////string connection = "C:\\Work\\temp.sde"; ////Geodatabase sde = new Geodatabase(connection); ////featureLayer.FindAndReplaceWorkspacePath(((CIMStandardDataConnection)currentDataConnection).WorkspaceConnectionString, //// sde.GetConnectionString(), true); ////////////////////////////////////////////// ////Please Read //// //ok, so at this point we have a couple of bugs at 1.1 AND 1.2..... // //#1: if you switched to a Datasource that invalidates the Renderer, the Renderer does //not get invalidated in the UI //(eg You had a UniqueValueRenderer on a Field called "CATEGORY", the new datasource //does NOT have that field and so the renderer is invalid). // //#2: By default, Layers are added with a permanent cache. The cache is NOT automatically //invalidated so data (eg in the Attribute table, on the screen for draws) does NOT get //Refreshed so you have to invalidate the cache manually... //So, Bug #1 - we arbitrarily switch the Renderer to a simple renderer as a work around for that... featureLayer.SetRenderer(featureLayer.CreateRenderer(new SimpleRendererDefinition())); //Bug #2, we manually invalidate the cache featureLayer.ClearDisplayCache(); })); }
private Task ChangeUSHighwaysLayerDataConnectionAsync(FeatureLayer featureLayer, string catalogPath) { return QueuedTask.Run(() => { CIMDataConnection currentDataConnection = featureLayer.GetDataConnection(); string connection = System.IO.Path.GetDirectoryName(catalogPath); string suffix = System.IO.Path.GetExtension(connection).ToLower(); WorkspaceFactory wf = WorkspaceFactory.FileGDB; if (suffix == ".sde") { wf = WorkspaceFactory.SDE; } string dataset = System.IO.Path.GetFileName(catalogPath); // provide a replace data connection method CIMStandardDataConnection updatedDataConnection = new CIMStandardDataConnection() { WorkspaceConnectionString = new Geodatabase(connection).GetConnectionString(), WorkspaceFactory = wf, Dataset = dataset, DatasetType = esriDatasetType.esriDTFeatureClass }; featureLayer.SetDataConnection(updatedDataConnection); //For a RDBMS, it might look like this: //string connection = "C:\\Work\\temp.sde"; //Geodatabase sde = new Geodatabase(connection); //// provide a replace data connection method //CIMStandardDataConnection updatedDataConnection = new CIMStandardDataConnection(); //updatedDataConnection.WorkspaceConnectionString = sde.GetConnectionString(); //updatedDataConnection.WorkspaceFactory = WorkspaceFactory.SDE; //updatedDataConnection.Dataset = "vtest.usa.states"; //updatedDataConnection.DatasetType = esriDatasetType.esriDTFeatureClass; //// Alternatively, use Layer.FindAndReplaceWorkspacePath() ////Note: this will not allow changing the dataset name or workspace type //// ////string connection = "C:\\Work\\temp.sde"; ////Geodatabase sde = new Geodatabase(connection); ////featureLayer.FindAndReplaceWorkspacePath(((CIMStandardDataConnection)currentDataConnection).WorkspaceConnectionString, //// sde.GetConnectionString(), true); ////////////////////////////////////////////// ////Please Read //// //ok, so at this point we have a couple of bugs at 1.1 AND 1.2..... // //#1: if you switched to a Datasource that invalidates the Renderer, the Renderer does //not get invalidated in the UI //(eg You had a UniqueValueRenderer on a Field called "CATEGORY", the new datasource //does NOT have that field and so the renderer is invalid). // //#2: By default, Layers are added with a permanent cache. The cache is NOT automatically //invalidated so data (eg in the Attribute table, on the screen for draws) does NOT get //Refreshed so you have to invalidate the cache manually... //So, Bug #1 - we arbitrarily switch the Renderer to a simple renderer as a work around for that... featureLayer.SetRenderer(featureLayer.CreateRenderer(new SimpleRendererDefinition())); //Bug #2, we manually invalidate the cache featureLayer.ClearDisplayCache(); }); }