1

I am tasked with programmatically getting the area of each individual part of a multi-part feature. I have a script already to read each individual part and print its XY coordinates and it works fine but for some reason can't seem to modify it to also print the areas too.

I have tried inserting the SHAPE@AREA token but receive errors that the "Float object is not iterable". I'm sure it's something simple I am just missing but I can't seem to find an example of this for multipart features. I can write a simple code that gives me total area but not the area of each part. Any suggestions? Here is my script before I include the SHAPE@AREA

import arcpy
from arcpy import env
env.workspace = "C:/Data/Exercise08"
fc = "Hawaii.shp"
cursor = arcpy.da.SearchCursor(fc, ["OID@", "SHAPE@"])
for row in cursor:
    print("Feature {0}: ".format(row[0]))
    partnum = 0
    for part in row[1]:
        print("Part {0}: ".format(partnum))
        for point in part:
            print("{0}, {1}".format(point.X, point.Y))
        partnum += 1
8

You can actually deal with each part of a multipart polygon by creating a separate polygon object. Take a look at the following code.

import arcpy
from arcpy import env
env.workspace = "C:/Data/Exercise08"
fc = "Hawaii.shp"
for row in arcpy.da.SearchCursor(fc, ["OID@", "SHAPE@"]):
    print("Feature {0}: ".format(row[0]))
    partnum = 0
    for part in row[1]:
        poly = arcpy.Polygon(part) # <--Create polygon object from part
        print("Part {0} area: {1}".format(partnum, poly.area))
        partnum += 1

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.