Hi,
how do you set the rotationfield for a featurelayer using the ArcGIS Pro SDK for .NET? I guess it's possible somehow, but I didn't find any examples how to do this. It's possible to configure the field in the layer settings of ArcGIS Pro like this:
What I want to do is make the setting pictured above by using the ArcGIS Pro SDK for .NET.
Thanks in advance
Solved! Go to Solution.
The rotation information is stored in the layer's CIM definition. You can use the CIM Viewer tool to interrogate the layer's CIM defintion's content: Esri/arcgis-pro-sdk-cim-viewer (github.com)
Once you activate the tool and make the desired symbology settings manually, you can then 'show the CIM' to view the layer's CIM definition. It will look like this:
Once you have the CIM definition you can the write the code to get/set the CIM definition programmatically. In your case you are interested in the CIMRenderer. I supplied the code to read the CIM, but you can make changes to the renderer as well. There are some snippets and community samples on how to set a renderer. Once you make programmatic changes to the CIM you always have to use the corresponding 'Set' function to submit the changed CIM to the layer (i.e. GetRenderer() / SetRenderer(...)). Here is my sample [Button / OnClick] code to read the renderer's rotation settings:
protected override void OnClick()
{
var pointLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(fl => fl.Name.Contains("TestPoint")).FirstOrDefault();
if (pointLayer == null) return;
QueuedTask.Run(() =>
{
//Get simple renderer from the feature layer
CIMSimpleRenderer currentRenderer = pointLayer.GetRenderer() as CIMSimpleRenderer;
if (currentRenderer == null)
return;
// check if ArrayOfCIMVisualVariable exists
if (currentRenderer.VisualVariables != null)
{
// check if CIMRotationVisualVariable exists
foreach (var visualVar in currentRenderer.VisualVariables)
{
if (visualVar is CIMRotationVisualVariable cimRotationVisualVariable)
{
// rotation field info is under VisualVariableInfoZ
var varInfoZ = cimRotationVisualVariable.VisualVariableInfoZ;
// ValueExpressionInfo holds CIMExpressionInfo
var varExpInfo = varInfoZ.ValueExpressionInfo;
MessageBox.Show($@"{varExpInfo.Expression} rotation type: {cimRotationVisualVariable.RotationTypeZ}");
}
}
}
});
}
Using the code above on my sample data results in this:
Thanks a lot. With the above example I was able to deduce what was necessary to define the rotation field.
The rotation information is stored in the layer's CIM definition. You can use the CIM Viewer tool to interrogate the layer's CIM defintion's content: Esri/arcgis-pro-sdk-cim-viewer (github.com)
Once you activate the tool and make the desired symbology settings manually, you can then 'show the CIM' to view the layer's CIM definition. It will look like this:
Once you have the CIM definition you can the write the code to get/set the CIM definition programmatically. In your case you are interested in the CIMRenderer. I supplied the code to read the CIM, but you can make changes to the renderer as well. There are some snippets and community samples on how to set a renderer. Once you make programmatic changes to the CIM you always have to use the corresponding 'Set' function to submit the changed CIM to the layer (i.e. GetRenderer() / SetRenderer(...)). Here is my sample [Button / OnClick] code to read the renderer's rotation settings:
protected override void OnClick()
{
var pointLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(fl => fl.Name.Contains("TestPoint")).FirstOrDefault();
if (pointLayer == null) return;
QueuedTask.Run(() =>
{
//Get simple renderer from the feature layer
CIMSimpleRenderer currentRenderer = pointLayer.GetRenderer() as CIMSimpleRenderer;
if (currentRenderer == null)
return;
// check if ArrayOfCIMVisualVariable exists
if (currentRenderer.VisualVariables != null)
{
// check if CIMRotationVisualVariable exists
foreach (var visualVar in currentRenderer.VisualVariables)
{
if (visualVar is CIMRotationVisualVariable cimRotationVisualVariable)
{
// rotation field info is under VisualVariableInfoZ
var varInfoZ = cimRotationVisualVariable.VisualVariableInfoZ;
// ValueExpressionInfo holds CIMExpressionInfo
var varExpInfo = varInfoZ.ValueExpressionInfo;
MessageBox.Show($@"{varExpInfo.Expression} rotation type: {cimRotationVisualVariable.RotationTypeZ}");
}
}
}
});
}
Using the code above on my sample data results in this:
Thanks a lot. With the above example I was able to deduce what was necessary to define the rotation field.
Would you happen to remember what you did here? I'm looking to switch the rotation language to Arcade, and then populate with our rotation field in Arcade to satisfy it. Any help is much appreciated!