I'm writing an ArcPy script and iterating through a line feature class and I want to use each line as an input into the GeneratePointsAlongLine tool. How do I pull the line geometry from the SearchCursor?
I have tried 'SHAPE' and 'SHAPE@':
SHAPE gave me runtimeError: Object: Error in executing tool
SHAPE@ gave me ERROR 000530: Value is required Failed to execute (GeneratePointsAlongLines).
code:
with arcpy.da.SearchCursor(split_line, ['ORIG_SEQ','PointDist', 'SHAPE@']) as split:
for segment in split:
pointDistance = str(segment[1]) + " Miles"
arcpy.management.GeneratePointsAlongLines(segment[2], pointsAdded, "DISTANCE", pointDistance, None, "END_POINTS")
arcpy.management.Append(pointsAdded, allPoints)
Solved! Go to Solution.
If you are wanting to go the script route then this sounds like what you need to:
HI @GISLearner,
You don't need to script anything in order to run the tool. Unless you are looking to specifically generate points along certain lines, then you would simply need to create a separate feature class only for those lines.
Also, something to note, the way you have it scripted is incorrect. You cannot use record as an input for a tool. Tools are built in such a way that they will only take specific kinds of inputs (i.e. a feature class or layer). What you are trying to use the tool for isn't working because it isn't configured properly for the tool to run. You would need to use the split_line as the input. For examply:
with arcpy.da.SearchCursor(split_line, ['ORIG_SEQ','PointDist', 'SHAPE@']) as split:
for segment in split:
pointDistance = str(segment[1]) + " Miles"
arcpy.management.GeneratePointsAlongLines(split_line, pointsAdded,
"DISTANCE", pointDistance, None, "END_POINTS")
arcpy.management.Append(pointsAdded, allPoints)
I am still not following for certain parts of your script, but if you are looking to only include certain points as they pertain to certain lines, then you can create a script similar to the one you started with for the point feature class created by the tool. You would then append those points to another feature class based on what parameters you set.
Click here for help on with the tool that you are trying to use.
Hi @RPGIS,
I have a different distance for each row/line in split_line that I need to generate points along. So I'm iterating over each line and specifying the distance using the 'PointDist' field. I want to be able to bring the line itself so that the GeneratePointsAlongLine tool puts the points along that line. Using the split_line as the input generates points along all the lines in split_line.
If you are wanting to go the script route then this sounds like what you need to: