Select to view content in your preferred language

Acreage Script

1327
2
12-06-2013 06:50 AM
Lebowski
Frequent Contributor
I am currently building a model in model builder and I need to add a Python Script (unless someone know of Toolbox tool) that will add acreage to the attribute table. Does anyone have a script handy or know of somewhere I could find one for acreage?

Thanks,
Tags (2)
0 Kudos
2 Replies
T__WayneWhitley
Honored Contributor
Well, you've probably got it by now, but you can enter either the system Calculate Field tool directly, or add a script tool if that's what you prefer in your custom model...either way, you can access acreage by token with this python expression:

!shape.area@acres!

It's documented in many different places - this is probably your best bet:

Using the Calculate Field tool
Geodata » Data types » Tables
http://resources.arcgis.com/en/help/main/10.2/index.html#//005s00000029000000
0 Kudos
TonyAlmeida
MVP Regular Contributor
Here is one i use. The down side using python is that you have to indicate which layer you want add acreage to.

import arcpy
from arcpy import env
from arcpy import mapping

arcpy.env.overwriteOutput = True

# Set Local Variable
A = "CUPS" #Layer you want to updat acres
mxd = arcpy.mapping.MapDocument("CURRENT")
# Create attribute called Acres
try:
    if arcpy.Exists(A):
        arcpy.AddField_management(A, "Acres", "DOUBLE")
        print "Acres Attribute Added"
    else:
        print "Acres Field Not Added"       
except arcpy.ExecuteError:
    print "Error Occured Add Acres Attribute Failed"
    print (arcpy.GetMessages(2))
    
# Create curser to update acres field
cur = arcpy.UpdateCursor(A)

# Pass through each row to update acres value
try:
    if arcpy.Exists(A):
        for row in cur:
            row.Acres = row.Shape_Area /43560
            cur.updateRow(row)
            print "Acres Updated"
    else:
        print "Acres Not Updated Feature Class Does Not Exist"
except arcpy.ExecuteError:
    print "Error Occured Update Failed"
    print (arcpy.GetMessages(2))
del cur, row

arcpy.RefreshActiveView()
arcpy.RefreshTOC()
# Delete cursor and objects
del arcpy, env, A, mxd

0 Kudos