4

I have a polygon shapefile and I want to write a Python script to add a field named "area" and calculate its geometry areas.

The script is like this:

arcpy.AddField_management("wrfd01_layer_intersect","area","LONG","","","","","NON_NULLABLE","NON_REQUIRED")
arcpy.CalculateField_management("wrfd01_layer_intersect","area","!shape.area@squaremeters!")

When I run it the field adds, and you can see the process of calculating the geometry area.

However, in the attribute table, there are no values in the field "area".

How to solve this problem?

4

Try this instead:

arcpy.AddField_management("wrfd01_layer_intersect","area","DOUBLE","#","#","#","#","NULLABLE","NON_REQUIRED","#")
arcpy.CalculateField_management("wrfd01_layer_intersect","area","!shape.area@squaremeters!","PYTHON_9.3","#")

I think you need to use a DOUBLE instead of LONG to get the desired area values. I suspect your "no values" are roundings of floating point numbers to an integer value of 0 - but I cannot be sure.

To get the above syntax I used Copy As Python Snippet from a successful run of each tool using its tool dialog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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