Points to polylines missing first segment and last 2 segments

2245
3
12-03-2014 08:36 AM
SharonLitteral
New Contributor II

I  have a python script that was creating points in memory and writing them to an arcpy.Array and then writing the array to an already existing feature class as a polyline.  When I looked at the line it was missing the first segment and the last 2 1/4 segments.  I changed the script to write the points to an existing featureclass (to verify that it was in fact looking at all of the points).  All of the points are there but the line is still incomplete.

Here is the code segment:

cur = arcpy.da.InsertCursor(outLineFC, ["SHAPE@"])
cur2 = arcpy.da.InsertCurson(outPointFC, ["SHAPE@"]

for coords in coordsList:
     print coords[0]
     print coords[1]
     print float(coords[2])
     print float(coords[3])
     print "next item"

     array.add(arcpy.Point(float(coords[3]), float(coords[2])))
     cur2.insertRow([arcpy.Point(float(coords[3]), float(coords[2]), ID=int(coords[1]))]))
if cur2:
     del cur2
cur.insertRow([arcpy.Polyline(array)])

Can anyone explain to me why it is writing all of the points in the order I would expect it to draw the line but not writing the first segment and the last 2 1/4 segments of the line?

Tags (3)
0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

not sure if I follow the workflow, but are the last 3 lines supposed to be indented? or stepped outside as you have?

0 Kudos
SharonLitteral
New Contributor II

Yes.  I read through the list of coordinates and add each one to the arcpy.array.  Not until I have finished with all of the coordinates do I write the array to the polyline.

0 Kudos
curtvprice
MVP Esteemed Contributor

The instructions are not very complete in the help.

Your code isn't showing how your array gets initialized, but if it's been around for a previous loop, it's important to remember to clear it out with array.RemoveAll().

Another thing to think about is that the XY resolution can truncate and modify coordinates if your coordinate values are very close together.  This truncation would happen (along with re-ordering of polygon coordinates and other geometric clean-up) when you create the feature with insertRow().

0 Kudos