1

I am reading rows from a database with a field "Coords" that contains polygon coordinates in the format 40.090170,-83.007704|40.089878,-83.007724..... and inserting each row as a polygon.

The first feature is drawn correctly, the second feature is drawn but is connected to and duplicates the first feature, and the third contains all three and so on.

The coordinates are cumulative. I tried deleting variables between iterations, but that didn't help. What am I missing?

import pypyodbc
import arcpy
GdbFeat = r"\\server\Arc_Server_data\publish.gdb\OUPS"
spatialRef = arcpy.Describe(GdbFeat).spatialReference
conn = pypyodbc.win_connect_mdb(r"C:\GIS\db\COWOUPSx.mdb")
cursor = conn.cursor()
cursor.execute("SELECT TicketDate, TicketNum, Coords FROM Tickets WHERE (((TicketDate) = #11/15/2014#))")
rows = cursor.fetchall()
cursor.close
del cursor
conn.close
del conn
if rows:        
        polygonArray = arcpy.Array()
        for row in rows:                
                Coords = row[6]
                coordinatePairList = Coords.split("|")
                for coordinatePair in coordinatePairList:
                        coordinates = coordinatePair.split(",")
                        currentPoint = arcpy.Point(coordinates[1],coordinates[0])                        
                        polygonArray.add(currentPoint)                                               

                polygon = arcpy.Polygon(polygonArray, spatialRef)                
                polygonArray.removeAll                
                with arcpy.da.InsertCursor(GdbFeat, ("Shape@", "TicketDate", "TicketNum")) as Acursor:
                        Acursor.insertRow((polygon, row[0], row[1]))

                del Coords            
                del polygon
                del coordinatePairList
                del coordinatePair
                del coordinates
                del currentPoint

        del row
        del rows

1 Answer 1

4

You need to create a new array every iteration.

if rows:        
    polygonArray = arcpy.Array()
    for row in rows:

should be

if rows:        
    for row in rows:
        polygonArray = arcpy.Array()
2
  • Son of a gun! I thought polygonArray.removeAll would reset the array. Thank You!
    – Robb
    Commented Nov 13, 2014 at 21:06
  • 1
    polygonArray.removeAll should be polygonArray.removeAll() This works with original code instead of recreating array.
    – Robb
    Commented Nov 13, 2014 at 21:23

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.