Create points along a line

4886
11
12-15-2013 05:11 PM
SévérianDuplaquet
New Contributor II
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
ModyBuchbinder
Esri Regular Contributor
Hi

Try to give the second parameter to the cursor as a python list (closed in square brackets).
You can try to use the densify GP Editing tool to create line with Vertices and then use  Feature Vertices to Points (GP Data Management -> Features) to create points form the Vertices.

Have fun
Mody
0 Kudos
SévérianDuplaquet
New Contributor II
Hi,

Thanks for the quick answer but it didn't work. In fact I already tried 😞

The densify + create points from vertice tools may probably not work as my polylines are not straight: I already have vertice on my lines. I also know the way to use "events" on "roads" but I haven't yet read the help on this because my script is almost done. If nothing work I will try other methods! I also tried to download the ET Geowizzard thing but it didn't want to be instal on my computer (a dll is missing or something like this)
0 Kudos
DanPatterson_Retired
MVP Emeritus
Does this tool set return the same results?  http://www.arcgis.com/home/item.html?id=78a1185b95eb4bf18c7340353ab2364d
0 Kudos
SévérianDuplaquet
New Contributor II
Hi Dan,

Thx for the tool. It takes me some time to understand how it works!
Anyway I gave it a try and that is almost what I want but there are still points which are incorect (I take a picture and circled). I want to avoid this kind of things 🙂

[ATTACH=CONFIG]29902[/ATTACH]

I have look at your code and that is way too hard for my current understanding. I'll however try to analyse it and maybe I can figure why my syntaxe is incorect 😞
0 Kudos
DanPatterson_Retired
MVP Emeritus
All densify programs will retain the original points and add auxiliary points as needed.   I sounds like you want to remove the points that make up the original shapefile, however, this will change the shape of the original polyline which is not appropriate nor desired.  You will need to filter out those points, however the interpoint distance between two densified points may not be accurate if you remove one of the original points.   You will have to clarify what you want to do if densification is not appropriate
0 Kudos
SévérianDuplaquet
New Contributor II
Alright, I am sorry if it wasn't clear.

I have done what I want to do mannually with the "editor". I have a polyline (a corridor for buses) and want to find stations every 500 meters. To do that I created an empty points.shp. Then I edited each feature of my polyline by using "construct points":

[ATTACH=CONFIG]29903[/ATTACH]

I obtained this kind of thing:

[ATTACH=CONFIG]29904[/ATTACH]


Now I want to do that for 400m, 450, etc...
I also would like to add other tools like buffer and calcululations around my stations.
Thus, I need an automatic process such as a script. And the "editor" toolbar doesn't work with modelbuilder.


So I've read that I could create a SearchCursor on my polyline.shp to get the "positionAlongLine"
Then I would use an InsertCursor on an empty point.shp

That's what my script tried to do 😮
0 Kudos
JulienRadoux
New Contributor
I think that you should try with linear referencing tools.
1) create route from your line
2) create a table with a list of locations along the route
3) create point events on your line

Hope this help
0 Kudos
GerryGabrisch
Occasional Contributor III
The tool here creates a new point file without altering the original feature geometries.


ftp://lnnr.lummi-nsn.gov/GIS_Scripts/CreatePointsAlongALine/
0 Kudos
SévérianDuplaquet
New Contributor II
Hi,

Thanks gabrisch for your tool! I tried to install it but I probably have done a mistake as arcCatalog or ArcMap crash almost instantly when I launch it. I don't even get an error information else than "ArcMap stopped to work etc." (Sorry, no Screenshot - it's useless and my windows is in french)

I also found something here : http://www.arcgis.com/home/item.html?id=a2a41c8345e24ab6a9dd2ae215710b39
However here also my installation method should have not worked

I tried the route methods. I have never used these kind of tools so I don't really know how to do but I have no location table for my events so I have to create and fill one with Distance. I'm not sure I can do this? (I haven't found a tool/method to add empty records to an empty table). I might be wrong but as I said I never used these tools.


Concerning my home script, I have changed some things in the 18th line :

with arcpy.da.SearchCursor(inLine, ['SHAPE@LENGTH','SHAPE@']) as cursor:


I deleted the spatial reference, and changed the " by '.
However now the error I got is :

<type 'exceptions.AttributeError'>: 'module' object has no attribute 'da'
Failed to execute (PointAlongLine).


If I understand well, it is because I haven't import the "da" module. So I tried something like "from arcpy import da" or even "from arcpy import *" but he is unable to found it.
I then reached my ArcGIS files and I can't find da.py or data_analysis.py or nothing like this in the arcpy folder.
I may have a trouble with my installation - it's an educational version for 1 year. If my "da" script is missing I probably can't launch your script???


Should I try to found another computer with arcGIS / contact the IT services / contact Esri?

Thanks
0 Kudos