Hi,
We are connecting to SDE with ArcGIS Pro SDK to retrieve the polygon layer. We also have a symbology file for the same polygon layer.
So, when using the symbology layer to render the polygon feature layer, we're having trouble with settings some of its properties. In symbology layer we have a Boolean field "HasAlignmentSheet" which determines the color of polygon features(This field is not present within the polygon data layer).
Can anyone please provide the basic sample to use the symbology layer's renderer with the feature layer.
We have tried and currently we are getting the below output.
The code we have used to renderer this :-
//Connecting to geodatabase to get the polygon layer
Geodatabase geodatabase = new Geodatabase("Database Connection Properties")
featureClassAsTable = geodatabase.OpenDataset<Table>("Polygon Layer");
featureClassOpenedAsTable = featureClassAsTable as FeatureClass;
var layer = MapGlobal.Instance.map.Layers[1] as FeatureLayer;
List<FeatureLayer> featLayers = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().ToList();
FeatureLayer inputLayer = featLayers[1];
string symbologyLayer = @"C:\ drive\A_SHEET_INDEX.lyr";
// using GP tool to add the symbology layer to the polygon layer
var parameters = Geoprocessing.MakeValueArray(inputLayer, symbologyLayer);
IGPResult pGPresult = await Geoprocessing.ExecuteToolAsync("management.ApplySymbologyFromLayer", parameters);
CIMUniqueValueRenderer UniqueValueRenderer = layer2.GetRenderer() as CIMUniqueValueRenderer;
// getting the two symbol from the symbology layer based on the field property "HasAlignmentSheet"
var hasNoAlignment = UniqueValueRenderer.Groups[0].Classes.Where(x => x.Label == "No Alignment Sheet").Select(y => y.Symbol).FirstOrDefault();
var hasAlignment = UniqueValueRenderer.Groups[0].Classes.Where(x => x.Label == "Has Alignment Sheet").Select(y => y.Symbol).FirstOrDefault();
// making changes in the renderer for the polygon layer
UniqueValueRenderer.DefaultSymbol = hasNoAlignment;
UniqueValueRenderer.UseDefaultSymbol = true;
//Setting the renderer for the polygon layer
layer2.SetRenderer(UniqueValueRenderer);
We are looking for the following output/ result
We want to remove the "all other values" from the symbology section as well as render the polygon features based on the Boolean field "HasAlignmentSheet" (we are fetching from the symbology layer)
Thanks
Solved! Go to Solution.
Try using a LayerDocument instead.
This snippet shows the workflow to follow: apply-symbology-to-a-layer-from-a-layer-file . Some more information can be found here: ProConcepts-Map-Authoring#layer-files-and-layer-packages
Hi
Instead of using the GP Tool to apply the symbology from lyrx file, I recommend using LayerDocuments.
You can apply symbology to a feature layer from an existing lyrx file by accessing the CIMFeatureLayer from the LayerDocument.
Here is a code snippet to help with this.
var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
QueuedTask.Run( () => {
//Create a LayerDocument from a Lyrx file.
var layerDocument = new LayerDocument(@"C:\Temp\Symbology.lyrx");
//Get the renderer used in the lyrx file using the CIMLayerDocument
//This lyrx file has a unique value renderer
var cimFeaturLayer = layerDocument.GetCIMLayerDocument().LayerDefinitions[0] as CIMFeatureLayer;
var rendererToUse = cimFeaturLayer.Renderer as CIMUniqueValueRenderer;
//You can make your changes to the renderer now
//rendererToUse.DefaultSymbol = ...
//Set the renderer to the feature layer
featureLayer.SetRenderer(rendererToUse);
});
Can you please try your workflow with this and see if you get the expected result? Please let me know if you get stuck.
Thanks!
Uma
Try using a LayerDocument instead.
This snippet shows the workflow to follow: apply-symbology-to-a-layer-from-a-layer-file . Some more information can be found here: ProConcepts-Map-Authoring#layer-files-and-layer-packages
Hi
Instead of using the GP Tool to apply the symbology from lyrx file, I recommend using LayerDocuments.
You can apply symbology to a feature layer from an existing lyrx file by accessing the CIMFeatureLayer from the LayerDocument.
Here is a code snippet to help with this.
var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
QueuedTask.Run( () => {
//Create a LayerDocument from a Lyrx file.
var layerDocument = new LayerDocument(@"C:\Temp\Symbology.lyrx");
//Get the renderer used in the lyrx file using the CIMLayerDocument
//This lyrx file has a unique value renderer
var cimFeaturLayer = layerDocument.GetCIMLayerDocument().LayerDefinitions[0] as CIMFeatureLayer;
var rendererToUse = cimFeaturLayer.Renderer as CIMUniqueValueRenderer;
//You can make your changes to the renderer now
//rendererToUse.DefaultSymbol = ...
//Set the renderer to the feature layer
featureLayer.SetRenderer(rendererToUse);
});
Can you please try your workflow with this and see if you get the expected result? Please let me know if you get stuck.
Thanks!
Uma
Thanks @CharlesMacleod and @UmaHarano , I tried using LayerDocument and CIMUniqueValueClass and it worked pretty fine for me. Thanks for your time and help!
Shabina