Select to view content in your preferred language

Variable-Based Calculate Geometry

666
4
09-28-2023 11:49 AM
ThomasHamill
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?

ThomasHamill_0-1695926898060.png

 

Kindest Regards,

t
0 Kudos
4 Replies
AyanPalit
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:

AyanPalit_0-1695928517424.png

and use Coordinate System as batch parameter

AyanPalit_1-1695928638515.png

and use different Coordinate Systems:

AyanPalit_2-1695928689305.png

Ayan Palit | Principal Consultant Esri
ThomasHamill
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
0 Kudos
RhettZufelt
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:
   wkt = 'PROJCS["NAD_1983_2011_StatePlane_Colorado_South_FIPS_0503_Ft_US",GEOGCS["GCS_NAD_1983_2011",DATUM["D_NAD_1983_2011",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",3000000.000316083],PARAMETER["False_Northing",999999.999996],PARAMETER["Central_Meridian",-105.5],PARAMETER["Standard_Parallel_1",37.23333333333333],PARAMETER["Standard_Parallel_2",38.43333333333333],PARAMETER["Latitude_Of_Origin",36.66666666666666],UNIT["Foot_US",0.3048006096012192]]'

if WKID = 6409:
   wkt ='PROJCS["NAD_1983_2011_StatePlane_Arizona_West_FIPS_0203_Ft_Intl",GEOGCS["GCS_NAD_1983_2011",DATUM["D_NAD_1983_2011",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",700000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-113.75],PARAMETER["Scale_Factor",0.9999333333333333],PARAMETER["Latitude_Of_Origin",31.0],UNIT["Foot",0.3048]]'

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_

ThomasHamill
Occasional Contributor II

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

Kindest Regards,

t
0 Kudos