AnsweredAssumed Answered

da.InsertCursor - Empty Polygon Geometry

Question asked by chi.zhang on Jan 31, 2019
Latest reply on Feb 2, 2019 by rvburton

I need to take vertex coordinates and draw them as polygons using da.InsertCursor. However, it is giving me random results. The script keeps running but many features show empty geometry:

 

 

Here is the code I use with 2 ticket examples - one can be inserted with geometry but the other one not.

# Define Ticket
class Ticket(object):
    id = 0
    coordinates = ""
    cleanCoordinates = []

    def __init__(self, id):
        self.id = id

# Sample tickets
ticket1 = Ticket(30190000001)
ticket1.coordinates = "39.938690/-75.153437,39.938634/-75.152868,39.936101/-75.153427,39.936228/-75.153883"
ticket1.cleanCoordinates = [c.split("/") for c in ticket1.coordinates.split(",")]
ticket2 = Ticket(30190000002)
ticket2.coordinates = "40.013851/-75.200242,40.015240/-75.198461,40.017056/-75.201218,40.015774/-75.203267,40.015158/-75.204930"
ticket2.cleanCoordinates = [c.split("/") for c in ticket2.coordinates.split(",")]
resultsPolygon = [ticket1, ticket2]

# Delete old features in the table
ticketPolygonTrack = "PAOneCall_Boundary_Track_test"
arcpy.DeleteFeatures_management(ticketPolygonTrack)

# Insert tickets
ticketPolygonTrackFields = ["POCS_NUMBER", "SHAPE@"]
cursorPolygon = arcpy.da.InsertCursor(ticketPolygonTrack, ticketPolygonTrackFields)
for j in resultsPolygon:
    print("Polygon: " + str(j.id))
    array = arcpy.Array()
    pointObject = arcpy.Point()

    for coords in j.cleanCoordinates:
        pointObject.X = float(coords[1])
        pointObject.Y = float(coords[0])
        array.add(pointObject)

    polygonObject = arcpy.Polygon(array)
    row = (str(j.id), polygonObject)
    cursorPolygon.insertRow(row)
del cursorPolygon

print("Finished.")

 

Here is the results for this script:

 

The feature class projection is WGS 1984.

 

Any help would be appreciated. Thanks!

Outcomes