Using SearchCursor to get lines and input into GeneratePointsAlongLine

373
3
Jump to solution
07-08-2022 11:06 AM
GISLearner
New Contributor III

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)

0 Kudos
1 Solution

Accepted Solutions
RPGIS
by
Occasional Contributor III

If you are wanting to go the script route then this sounds like what you need to:

  • create a separate line feature class (inserting whatever necessary fields)
  • loop through your split_line feature class using a search cursor and use the insert cursor to append the line with the specified distance to the created line feature class and using the attributes as parameters for the tool
  • use the generate points along line tool on the newly appended feature class with the attributes from the search cursor
  • append the generated point feature class to your main point feature class (either using the append tool or another search and insert cursor)

View solution in original post

0 Kudos
3 Replies
RPGIS
by
Occasional Contributor III

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.

0 Kudos
GISLearner
New Contributor III

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. 

0 Kudos
RPGIS
by
Occasional Contributor III

If you are wanting to go the script route then this sounds like what you need to:

  • create a separate line feature class (inserting whatever necessary fields)
  • loop through your split_line feature class using a search cursor and use the insert cursor to append the line with the specified distance to the created line feature class and using the attributes as parameters for the tool
  • use the generate points along line tool on the newly appended feature class with the attributes from the search cursor
  • append the generated point feature class to your main point feature class (either using the append tool or another search and insert cursor)
0 Kudos