0

I am working on an arcpy script to create a polyline feature class with a single polyline feature between each 2 points in a sequence of points. I use a search cursor to first create a table with all the necessary data, including the start and end point coordinates for each record. Then I use an update cursor to load the data into a polyline feature class. The output feature class has a row for every record, but is missing the geometry for most, but not all of the polylines I want to create. I've tried rewriting it several ways, always with similar results. Any ideas on how to fix this?

rowsTbl = arcpy.da.SearchCursor(attributeTable, ['SURSEGUID', 'TRACKSEGMENT', 'START_TIME', 'END_TIME', 'START_X', 'START_Y', 'END_X', 'END_Y'])

#New polyline featureclass fields = ['SHAPE@', 'SURSEGUID', 'TRACKSEGMENT', 'START_TIME', 'END_TIME']

with arcpy.da.InsertCursor(tempOutFC, fields) as cursorTbl:
    for row in rowsTbl:
        array = arcpy.Array()
        point = arcpy.Point()
        point.X = (row[4])
        point.Y = (row[5])
        array.add(point)
        del point
        point = arcpy.Point()
        point.X = (row[6])
        point.Y = (row[7])
        array.add(point)
        del point

        #Create polyline from the array
        polyline = arcpy.Polyline(array)

        #Clear array for future use
        array.removeAll()
        #Append to the list of polyline objects

        cursorTbl.insertRow([polyline,row[0], row[1], row[2], row[3]])
        del polyline

del cursorTbl

Here's a screenshot of the attribute table I am trying to load: enter image description here As you can see, most output polylines are missing, although their records show up in the attribute table (with a shape length of zero). This is my output polyline feature class.

  • You need to creater separate insertcursor and insert row as you iterate through searchcursor – FelixIP Aug 12 '16 at 21:29
  • Your code should work, so I'm thinking it may be an issue in your START_X, START_Y etc. values – Midavalo Aug 12 '16 at 21:50
  • I added a screenshot of my attribute table. Those coordinates work fine for creating a point feature class, but not for the polylines. – spaine Aug 12 '16 at 21:58
  • Create unique ID for input table rows, project 2 sets of points, merge them and use points to lines tool. ArcGIS has a bad habit ignoring last decimals in degrees – FelixIP Aug 12 '16 at 22:42
2

Something like this:

cursorTbl=arcpy.da.InsertCursor(tempOutFC, fields)
point = arcpy.Point()
with arcpy.da.SearchCursor(attributeTable, [...]]) as rowsTbl:
    for row in rowsTbl:
        array = arcpy.Array()
        point.X = row[4]
        point.Y = row[5]
        array.add(point)
        point.X = row[6]
        point.Y = row[7]
        array.add(point)
        polyline = arcpy.Polyline(array)
        array.removeAll()
        cursorTbl.insertRow([polyline,row[0], row[1], row[2], row[3]])
del cursorTbl

Update on original answer:

Ignoring decimals when dealing with unknown projection is well known issue with ArcGIS How to handle coordinates accuracy in ArcGIS

this is why it creates 0 length polylines in your example.

So, add pairs of points manually (I have no clue how to do it using arcpy only, because add XY event tool is nowhere to be found. Perhaps creating PointGeometry, where one can define geographic projection can help), project them and use points to line tool

  • I tried this, with the same results. – spaine Aug 12 '16 at 22:10
  • 1
    Your data in decimal degrees and distance between points is about 0.0001 degress. If you output it into fgdb, this most likely creates 0 length polylines. – FelixIP Aug 12 '16 at 22:23
  • You are right, that was it. Once I changed the input data into a projected coordinate system, the script worked as expected. Thanks! – spaine Aug 12 '16 at 23:00
  • Thanks @Midavalo. I was looking at the overall context and it looked like resolved. – fatih_dur Aug 14 '16 at 12:33
  • @FelixIP, do you mind resubmiting/revising your answer with the info that you have given in your comment? I believe this is pretty critical. – fatih_dur Aug 14 '16 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.