Thursday 19 September 2019

python - Determining Shape Area Field Name


I'm dealing with a varierty of spatial polygon files (shapefiles, file/personal gdb feature classes, sde feature classes (some with spatial views)) and depending on the file type, I get a mulittude of Shape Area feature class field names (the required field, not a created one)


So for example, the field names vary from "Shape_Area", "SHAPE_Area", "SHAPE.AREA", "GEOMETRY_Area", "GEOMETRY.AREA"


I'm writing a python script to pull out the area of all these types of feature classes and I do something along the lines of:


for field in arcpy.ListFields(fc):
if field.name in ["Shape_Area", "SHAPE_Area", "SHAPE.AREA", "GEOMETRY_Area", "GEOMETRY.AREA"]:

do something

I'm wondering if there's a more clever way of pulling out the shape area field, instead of just listing out all the ways it can be named? There doesn't seem to be a field property for something like Area. is there any other way of doing this?



Answer



What about the following:


fc = "path to input feature class"
desc = arcpy.Describe(fc)
areafieldname = desc.areaFieldName

Should work on various feature classes that have auto generated Area fields. This will exclude shapefiles.



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...