Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
    
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 Nov 10 '10 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. –  Derek Swingley Nov 10 '10 at 19:26
    
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. –  Jason Scheirer Nov 17 '10 at 18:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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