How to set the rotationfield for a featurelayer using ArcGIS Pro SDK for .NET?

496
2
Jump to solution
05-31-2021 05:12 AM
JFr87
by
New Contributor II

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:

JFr87_0-1622462930634.png

What I want to do is make the setting pictured above by using the ArcGIS Pro SDK for .NET.

 

Thanks in advance

0 Kudos
2 Solutions

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

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:

Wolf_0-1622558910532.png

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:

Wolf_1-1622559271110.png

 

View solution in original post

0 Kudos
JFr87
by
New Contributor II

Thanks a lot. With the above example I was able to deduce what was necessary to define the rotation field.

 

View solution in original post

0 Kudos
2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

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:

Wolf_0-1622558910532.png

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:

Wolf_1-1622559271110.png

 

0 Kudos
JFr87
by
New Contributor II

Thanks a lot. With the above example I was able to deduce what was necessary to define the rotation field.

 

0 Kudos