Select to view content in your preferred language

Polygon Added to Feature Class has Zero Area and Length

472
1
05-23-2013 07:55 AM
RuthLeBlanc
Emerging Contributor
I'm copying features (polygons) from one feature class to a new feature class, using arcpy.Polygon() and an insert cursor. (I'm basically doing a copy, the hard way. But Append() wasn't working for me...long story, so here I am...) In my code below, the record for the polygon is added, but the area and length fields are zero.  When I print out the area and length values from the object created from Polygon(), I get zero values as well.  The last point in the array of points for the polygon is also the first point, so the polygon should be closed.  Any ideas/suggestions about what I'm doing wrong?
Here is my code:

import os, arcpy

coordList = [] 

copyFeats = arcpy.SearchCursor(r"C:\temp\GDBs\20130521203526.gdb\polygon")
for feat in copyFeats:
    poly = []
    for feat in feat.shape.getPart():
        for pnt in feat:
            poly.append([pnt.X,pnt.Y])
    coordList.append(poly)
            
print "coordList: %s" % str(coordList)

# Create empty Point and Array objects
point = arcpy.Point()
array = arcpy.Array()

# A list that will hold each of the Polygon objects
featureList = [] 
sr = arcpy.Describe(r"C:\temp\GDBs\20130515145336.gdb\polygon").spatialReference
for feature in coordList:
    # For each coordinate pair, set the x,y properties and add to the
    #  Array object.
    for coordPair in feature:
        point.X = coordPair[0]
        point.Y = coordPair[1]
        print "add %s to array" % (str(coordPair[0]) + ' ' + str(coordPair[1]))
        array.add(point)

    # Create a Polygon object based on the array of points
    print "creating polygon"
    polygon = arcpy.Polygon(array)
    print 'area: %s, length: %s' % (str(polygon.area),str(polygon.length))
    # Clear the array for future use
    array.removeAll()

    # Append to the list of Polygon objects
    featureList.append(polygon)

arcpy.CreateFeatureclass_management(r"C:\temp\GDBs\20130521203526.gdb", "polygon_py", "POLYGON", "","DISABLED","DISABLED", sr)

ins = arcpy.InsertCursor(r"C:\temp\barbados\GDBs\Ruth_20130521203526.gdb\polygon_py")
for poly in featureList:
    print "insert polygon"
    row = ins.newRow()
    row.shape = poly
    ins.insertRow(row)
   
del row
del ins
Tags (2)
0 Kudos
1 Reply
ChrisSnyder
Honored Contributor
Not sure what the issue is exactly, but why not just insert the original polygon objects into the new FC? I'm probably missing something, but I don't see the need to deconstruct them to their constituent points, and then recreate the polygons again. Why not just hand the polygons from the top search cursor directly to the insert cursor?

Maybe this would help: http://forums.arcgis.com/threads/66434-A-better-way-to-run-large-Append-Merge-jobs
0 Kudos