0

What is the correct format for finding perimeter as an expression for arcpy. I was able to use expression !shape.Area! to find the area of my polygon. However when I use the expression !shape.Perimeter! I get invalid expression. I've tried the following expressions;

!shape.Perimeter!@KILOMETERS!

!shape.geodesicPerimeter!

!shape.geodesicPerimeter@KILOMETERS!

These do not work. I was able to find the perimeter using the attribute table and right clicking and going to calculate geometry. Therefore I know its possible, just I require the syntax for my python code.

My python code that works for area looks like this.

arcpy.CalculateField_management("Iceberg","Area","!shape.geodesicArea@SQUAREKILOMETERS!","PYTHON_9.3","#")

However my python code for perimeter is not working and it looks like this;

arcpy.CalculateField_management("Iceberg","Area","!shape.geodesicperimeter@KILOMETERS!","PYTHON_9.3","#")

I must be missing something, and I've looked at some examples, and have also done, X and Y coordinates, all work, but I cannot get my perimeter to work :(

2 Answers 2

6

Try using the word "Length" (i.e. length of polylines, perimeter of polygons) instead of "Perimeter":

arcpy.CalculateField_management("Iceberg","Area","!shape.geodesicLength@KILOMETERS!","PYTHON_9.3","#")

I found the geodesicLength property documented in the Calculate Fields examples page:

Geodesic area and length can also be calculated using geodesicArea and geodesicLength properties with @ followed by a unit of measure keyword.

0
-2
geometries = arcpy.CopyFeatures_management("polygon_fc_name",arcpy.Geometry())
peri_tot=0
for geo in geometries:
    peri_tot += geo.length

print peri_tot
3
  • 1
    Please clarify your answer. Note that this question has already an accepted answer, so if your answer doesn't add anything, avoid giving a new answer Commented Sep 3, 2015 at 20:33
  • 1
    @FaridCher We do welcome additional answers to questions even if they have an accepted answer but you are right that this one seems to be trying to suggest an indirect workaround while offering no explanation as to why someone would use it in preference to the previous more direct answer.
    – PolyGeo
    Commented Nov 20, 2015 at 0:16
  • @PolyGeo , That's for sure. But as i mentioned his answer doesn't add anything to your answer. Thanks Commented Nov 20, 2015 at 0:30

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.