1

How to make this script take a list of distances along a selected line and create a point featureclass with points at these distances?

import arcpy
from arcpy import env
import os

arcpy.env.overwriteOutput = True
arcpy.env.workspace = "in memory"

arcpy.FeatureClassToFeatureClass_conversion("PolyLineDataSet",    
r"C:\Users\Default.gdb","SelectedLine",)

arcpy.CreateFeatureclass_management(r"C:\Users\Default.gdb",
"PointsOnLines","POINT","","DISABLED","DISABLED",3600)

cursor = arcpy.da.InsertCursor("PointsOnLines",["SHAPE@XY"])
distances = [30,60,90]
for distance in distances: 
    for row in arcpy.da.SearchCursor("SelectedLine", ["SHAPE@"]):  
       point = cursor.insertRow(row[0].positionAlongLine(distance["SHAPE@XY"])   

After running this I end up with this error.

Runtime error 
Traceback (most recent call last):
File "<string>", line 20, in <module>
TypeError: 'PointGeometry' object has no attribute '__getitem__'
2

I think this line:

point = cursor.insertRow(row[0].positionAlongLine(distance["SHAPE@XY"]) 

should be:

cursor.insertRow((row[0].positionAlongLine(distance),))

As a side note if you read the help page Accessing data using cursors you will see best practise using the with statement. This guarantees the cursor being released correctly, as it stands your code is not "cleaning up" after itself and this may cause problems later on in the code.

  • 1
    Most likely cursor.insertRow((row[0].positionAlongLine(distance),)) – FelixIP May 9 '16 at 0:44

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.