severian.duplaquet

Create points along a line

Discussion created by severian.duplaquet on Dec 15, 2013
Latest reply on Dec 17, 2013 by severian.duplaquet
Hello,

I'm sorry to waste your time with this redundant question but I have read many threads and all the arcGIS help I could...
My aim is to position points with a specified distance along a polyline. I want to use a script so then I can automatize the thing with a model builder or something. I have arcGIS 10.1 without spatial extensions or other things.

Here is my current code:

import arcpy
import os
import sys

#import parameters from textbox

inLine = arcpy.GetParameterAsText(0)
outPoints = arcpy.GetParameterAsText(1)
interval = arcpy.GetParameterAsText(2)
lineClusTol = arcpy.GetParameterAsText(3)

#Define the function

sr = arcpy.Describe(inLine).spatialReference
inLineName = arcpy.Describe(inLine).name
segPts = outPoints
icursor = arcpy.da.InsertCursor(segPts)
with arcpy.da.SearchCursor(inLine, ("SHAPE@LENGTH","SHAPE@"),, sr) as cursor:
 for row in cursor:
  length = row[0]
  noIntervals = int(math.floor(length / interval))
  lastSegLength = length - (interval * noIntervals)
  for x in range(1, noIntervals):
   newPt = row[1].positionAlongLine(interval * x)
   icursor.insertRow((newPt))
  if lastSegLength < lineClusTol:
   lastPt = row[1].positionAlongLine(interval * noIntervals + lastSegLength)
  else:
   lastPt = row[1].positionAlongLine(interval * noIntervals)
icursor.insertRow((lastPt))



And this line is the one which makes many trouble, because of a "syntax" error.

with arcpy.da.SearchCursor(inLine, ("SHAPE@LENGTH","SHAPE@"),, sr) as cursor:


If anyone could explain me where I'm wrong, it'd be wonderfull!
Thx!

Outcomes