[GIS] Setting units in ArcPy

arcgis-10.0arcpy

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?

Best Answer

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.

Related Question