Example of geometry token syntax?

1381
4
12-01-2018 05:45 PM
JonahLay1
New Contributor II

Hello,

 I'm trying to find the area of various polygons in a shapefile using a script cursor. I assume I use "SHAPE@AREA" according to this: Reading geometries—ArcPy Get Started | ArcGIS Desktop 

However, I also want to specify the units (acres). Right now, I get a lot of numbers that don't seem to make much sense. It looks like I need the getArea method to specify the units: Polygon—ArcPy classes | ArcGIS Desktop 

Basically, I'm wondering, how does the getArea method work? Are there examples of the syntax?

Many thanks!

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

If the numbers are small based on what you expect, I think you are most likely working with data that are in decimal degrees.  Your life would be a lot simpler if your script simply called

Add Geometry Attributes—Data Management toolbox | ArcGIS Desktop 

and returned the area units in what you want, accounting for the projection that your data need to be in.  If you try to do this through an update or other cursor, you will have to account for the projection as well as the unit change.  

If you just need the information to be temporary, you can always add

Delete Field—Data Management toolbox | ArcGIS Desktop 

to your workflow to remove the previously added field.

In short, it will cut down on potential errors.  (both tools exist in arcmap and ArcGIS pro)

JonahLay1
New Contributor II

Thank you Dan! Is there anyway I can add the areas to a new field? I would like to customize the field name and populate it with the areas.

0 Kudos
DanPatterson_Retired
MVP Emeritus

The aforementioned tool produces a new field which you can provide a name for and get the units your want if you specify the parameters you need

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Calculate Field—Data Management toolbox | ArcGIS Desktop  can take care of this for you, e.g..:  !shape.area@ACRES!

Python expressions can use the geometry area and length properties with an areal or linear unit to convert the value to a different unit of measure (for example, !shape.length@kilometers!). If the data is stored in a geographic coordinate system and a linear unit is supplied (for example, miles), the length will be calculated using a geodesic algorithm. Using areal units on geographic data will yield questionable results as decimal degrees are not consistent across the globe.