Select to view content in your preferred language

# Variable-Based Calculate Geometry

666
4
09-28-2023 11:49 AM
Occasional Contributor II

Is it possible to run Calculate Geometry Attributes, but based on a variable (i.e., another attribute with the CRS WKID) that would drive the calculation?

We have a polygonal feature service (in WGS 1984 WMAS) representing areas throughout several different states in the continental US.  In the feature layer we have a field with the WKID of the local State Plane system associated with each polygon feature.

Can we use the WKID to drive which CRS is used for which feature assuming we want to re-run calculate geometry for the entire dataset and not have to do each State Plane System's subset of features one by one?

Kindest Regards,

t
4 Replies
Esri Regular Contributor

@ThomasHamill If I am following your use case, the Coordinate System is parameter/variable for Calculate Geometry Attributes. I tested running the tool in batch mode:

and use Coordinate System as batch parameter

and use different Coordinate Systems:

Ayan Palit | Principal Consultant Esri
Occasional Contributor II

Hi @AyanPalit, thank you for your response.  This batch solution doesn't quite do what I'm looking for, I'm afraid.

Ideally, Calculate Geometry would run differently for subsets of features in a single feature layer conditionally, based on an attribute that stores the local CRS (with a WKID) of the feature.  For example, the tool would calculate the area unit (acres, square meters, square km, etc.) using State Plane Arizona West for features with '6409' in their WKID attribute, calculate the area using State Plane Colorado South for features with '6432' the WKID attribute, and so on...

It would be akin to having the Coordinate System parameter in the Calculate Geometry tool change or be data driven based on the WKID attribute in the feature class.  Does this make sense?

Kindest Regards,

t
MVP Notable Contributor

Have not tested this, but seems like it should be doable with python.

If you go to the history tab and right click on the Calculate Geometry Attributes job and select copy python command.  This will copy the python and you can extract the WKT value from there:

``````# query the features with matching WKID's then....

if WKID = 6432:

if WKID = 6409:

arcpy.management.CalculateGeometryAttributes("Parcels", "AREA_Ac AREA", '', "ACRES", wkt, "SAME_AS_INPUT")``````

which has the WKT in the command itself.

Then, you iterate through the list of WKID's in the table, query the feature class by the WKID field, then calculate the geometry substituting in the correct WKT for the WKID that is being queried.

R_

Occasional Contributor II

Thanks for the response, @RhettZufelt!  I will give this a try!

Kindest Regards,

t