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
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 13, 2014 at 20:47

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()
answered Nov 13, 2014 at 20:50
2
  • Son of a gun! I thought polygonArray.removeAll would reset the array. Thank You! Commented Nov 13, 2014 at 21:06
  • 1
    polygonArray.removeAll should be polygonArray.removeAll() This works with original code instead of recreating array. Commented Nov 13, 2014 at 21:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.