I am trying to trim each polyline in a shapefile down to the first 15 feet of each line. The segmentAlongLine method was suggested to me, but this code is getting the AttributeError: 'list' object has no attribute 'segmentAlongLine'.

SHAPE@ in this case is a polyline object... Why is it calling it a list and why isn't segmentAlongLine working? I have found questions about this error but none of the answers seem to apply to my issue.

with arcpy.da.UpdateCursor(fc,"SHAPE@") as cursor:  
    for row in cursor:   
  • print(row) outputs (<Polyline object at 0x161d5c90[0x161d5d60]>,) for each of my 260,000 rows – ElizaC May 12 at 16:05

What if you try:

errors = []
with arcpy.da.UpdateCursor(fc,["SHAPE@", "OID@"]) as cursor:  
    for row in cursor:
        except AttributeError:

What is in errors list?

And you are not changing anything with your code. You need to assign row[0] a new value and cursor.updateRow(row)

  • print (errors) outputs [[None, 11035]] – ElizaC May 12 at 16:42
  • Then that rows geometry is broken/empty – BERA May 12 at 16:43
  • Thank you so much. I deleted that record and the script seemed to work successfully (no errors anyway) however... none of the lines actually shortened. The shapefile looks exactly the same. I can't imagine what the problem could be now. – ElizaC May 12 at 17:16

row is a list containing the shape of the feature. Use row[0].segmentAlongLine(0,15).

  • Thank you. I tried this and got "Attribute Error: 'NoneType' object has no attribute 'segmentAlongLine' ". Any ideas? – ElizaC May 12 at 15:29
  • Your list is empty – Ian Turton May 12 at 15:38
  • @ElizaC it means that the feature has an empty geometry. Because row[0] returns None. – Kadir Şahbaz May 13 at 4:37

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.