Select to view content in your preferred language

Create points along a line

6152
11
12-15-2013 05:11 PM
SévérianDuplaquet
Emerging Contributor
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!
Tags (2)
11 Replies
GerryGabrisch
Frequent Contributor
Sorry for the problems.  I just tested the tool and it runs for me.
From the link download the toolbox  and the DivideLine.py into a new folder on your computer.  Add the toolbox to ArcToolbox and run like any scripting tool.
0 Kudos
SévérianDuplaquet
Emerging Contributor
It crashed again.
But I did a terrible mistake: I told you I used ArcGIS 10.1 (as I thought) but after checking again it is only 10.0.
I'll update it to 10.2 and check again. Sorry for the inconvennience and thank you all for your answers.
0 Kudos