6

I want to calculate the area of each polygon in a shapefile.

How do I control what the units of measurement are?

def getArea(shapefile):
    """Print area of polygons"""

    Rows = ARCPY.SearchCursor( shapefile ) 

    for row in Rows:

        tmp_area = row.area # this assumes a field name 'area' exists
        print str(tmp_area) 

I looked to see if there is any setting in the arcpy.env. module but could not find one. If I do set the units in my python script, does that mean that all aspects of the shapefile remain unchanged? For example, if the shapefile had units of feet, in my script I change the units to KM, will the shapefile still have units of feet afterwards?

1 Answer 1

7

Units are always tied to your coordinate system. Assuming we're talking about a projected coordinate system, the units are in the units used by the spatial reference of your dataset. If you're dataset is in meters, your area will be in square meters. You should be able to get this info from your dataset's spatial reference. You can get your dataset's spatial reference with:

sr = arcpy.Describe(dataset).spatialReference
unit = sr.linearUnitName 

To answer your second question, calculating area in some unit other than what your spatial reference uses will not modify the underlying data. The only way to change the units the data uses is to use the project tool.

3
  • Thanks for the answer Swingley. I just have one question regarding this. If I use the 'Calculate Field (Data Management)' can I specify the units? For example the help here suggests that the area calculation can allow a unit to be specified: help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… Perhaps it is identifying what the unit of measurement is, and converting it into the chosen unit.
    – djq
    Commented Nov 10, 2010 at 19:15
  • Glad to help. If you're using calculate field, then yes, you can specify a unit. I'm pretty sure ArcGIS is just doing the conversion for you when it does the area calculation. Commented Nov 10, 2010 at 19:26
  • 1
    You can also pass in a spatial reference to Search Cursors, so you could open up a .prj file that uses the linear unit of your choice and pass it through to the cursor to have your geometries reprojected the way you want. Commented Nov 17, 2010 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.