Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have start point and end point of a polyline. How can I get a point on that polyline from end points specified by the given distance.

enter image description here

How can I get this by using arcpy provided that this script should work on ArcView without importing any modules (Like this answer). I'm trying not to hard code values.

Related Question:

share|improve this question
are you not getting any results using object.interpolate(distance[, normalized=False])? –  vinayan May 31 '12 at 10:05
Where did you get object.interpolate(distance[, normalized=False]). Is it a method of arcpy? If that is, can you please post the link. I googled it, but didn't find it. –  user May 31 '12 at 10:09
it is shapely's method..toblerity.github.com/shapely/… think you tried it in the other question..not sure if you got results.. –  vinayan May 31 '12 at 10:29
Another related question is gis.stackexchange.com/questions/6476/…, which concerns the inverse of this problem (find the distance given the point). The two solutions are closely related: once the polyline is made measurable, all points along it can be addressed in terms of their distances (and arbitrary segments along it can be addressed by distance ranges). –  whuber May 31 '12 at 16:05
add comment

6 Answers

This sounds similar to "Linear Referencing" and that toolset would be available in ArcView. Additionally, you can script this tool very easily.

Link to ESRI Help for Linear Referencing

share|improve this answer
+1 This is the "right" approach in the sense of using a mature capability created expressly for this problem. –  whuber May 31 '12 at 16:06
add comment

Based on your needs, as @LouisH referred to, using Linear Referencing is definitely the way to go. I cobbled together some code that should meet your need of not hard-coding elements, but instead requesting them as parameters.

As explanation, the Linear referencing tool used below takes "Routes", in your case the line features, and places "Events", in your case the points, along them based on a distance field. This results in a FeatureLayer, which is stored in memory, which is the reason for the last function which copies the features to an output featureclass.

import arcpy
import os
from arcpy import env

#Working directory
wkspace        = arcpy.GetParameterAsText(0)
#Line feature class
rtecls         = arcpy.GetParameterAsText(1)
#Line Unique ID
rtecls_ID      = arcpy.GetParameterAsText(2)
#Table of points to be located
pnttbl         = arcpy.GetParameterAsText(3)
#Field in point table that references line point will be located along
pttbl_rteid    = arcpy.GetParameterAsText(4)
#Distance field in point table
pttbl_dst      = arcpy.GetParameterAsText(5)
#Output Layer, layer is stored in memory.  Features still need to be copied to feature class saved to disk
outlayer       = arcpy.GetParameterAsText(6)
#Output Feature Class - If shapefile, make sure to include ".shp" at the end.
outclass       = arcpy.GetParameterAsText(7)

#Type of feature being located
fttype = "POINT"

#Set Workspace
env.workspace = wkspace

#Build String for input parameters in Linear Referencing tool
pt_props = pttbl_rteid + " " + fttype + " " + pttbl_dst

#Output featureclass path
outfclass = wkspace + os.sep + outclass

# Execute MakeRouteEventLayer
arcpy.MakeRouteEventLayer_lr (rtecls, rtecls_ID, pnttbl, pt_props, outlayer)

#Save feature layer to feature class on disk
arcpy.CopyFeatures_management(outlayer, outfclass)

Edit - One thing to think about with this tool, and likely any operation to locate points based on the distance from the end of a line, is which end of the line you will start from. The linear referencing tool, for instance, works based on the digitized direction of a line. It will be important to ensure that you have some way of identifying which endpoint your measurements are based upon.

share|improve this answer
add comment

Solving a linear reference problem like this without importing any modules is beyond my range..

I have used Shapely(python package for manipulation and analysis of 2D geospatial geometries. And it is BSD licenced :-) )

download it from here . The 2.6 version which is the only one that supports arcgis 10 arcpy..It is a simple installation(1.5 MB size)

and now here is the arcpy script to achieve the purpose.. forgive my python..only today i learned about the loops, tuples etc :)

import arcpy
import math
from arcpy import env

env.workspace = r"C:\testshape"

desc = arcpy.Describe("Rivers.shp")
shapefieldname = desc.ShapeFieldName

rows = arcpy.SearchCursor("Rivers.shp")

temptup = ()

# get ESRI geometries out of their cage..
for row in rows:

    feat = row.getValue(shapefieldname)
    partnum = 0
    for part in feat:
        for pnt in feat.getPart(partnum):
            if pnt:
                temptup += ((pnt.X, pnt.Y),)
                print "Interior Ring:"
        partnum += 1    

# and now the shapely magic :)

import shapely
from shapely.geometry import LineString
lnstr = LineString(temptup)
rsltPoint = lnstr.interpolate(0.5)

note : this will not work if the feature has curve segments

share|improve this answer
add comment

Might be an overkill, but if you have access to Network Analysis extension you could create network from your polylines and then create service areas around your input points, specifying SA size as the distance of interest. Here is a cursory example with 111 meters SA from the point:

enter image description here

Then you would have to find points where SA crosses the line.

share|improve this answer
add comment

I found this question trying to do what I think is the same thing. I wanted it all done via arcpy. Using Linear Referencing wasn't making sense to me because I don't already have the point events (and I couldn't figure out how to use LR to get them). The crux of what I ended up using was

    line = arcpy.Polyline(arrayPts)
    pt = line.positionAlongLine (0.99, 'True')

This requires Arc 10.1 or higher; I wasn't able to figure out whether this was available below the ArcInfo licensing level I have (OP specified ArcView).

In my example above, I wanted a point not at a fixed distance, but by a percentage of the overall line length. To do this, I supplied the second optional argument to positionAlongLine. You skip the second arg if you just want to specify an absolute distance. Here's the doc.

The fuller code sample is

import numpy
ptsList = list()
id = 0

with arcpy.da.SearchCursor('flFL', ["SHAPE@"]) as cursor:
    for row in cursor: 
        arrayPts = row[0].getPart()
        line = arcpy.Polyline(arrayPts)
        pt = line.positionAlongLine (0.99, 'True')
        ptsList.append((id, (pt.getPart().X, pt.getPart().Y)))
        id += 1

array = numpy.array([ptsList], \
numpy.dtype([('idfield',numpy.int32),('XY', '<f8', 2)]))

SR = arcpy.Describe("flFL").spatialReference
arcpy.da.NumPyArrayToFeatureClass(array, 'nsegSamplePts', ['XY'], SR)

'flFL' is my featureLayer of lines on which I want to locate the points. Runs pretty fast. NumPyArrayToFeatureClass was a very nice way to dump all my points back into a featureClass (thanks to my colleague Curtis for that part!). Had been experimenting w/Append_management but that was a fair bit slower.

share|improve this answer
+1 Thanks for sharing that. It looks like a good one-off solution when you don't want to invest the effort setting up a measured polyline. Note that this solution uses the implicit orientation of the polyline determined by the order in which its coordinates are stored. If care was not taken with that, you might wind up with points computed starting from the wrong end. Thus is would be nice to enhance this solution to enable the user (somehow) to stipulate--perhaps by means of inputting a point near one end--which is the beginning of the polyline. –  whuber Jan 23 at 23:46
That's definitely true. I'm using lines from a drainage network which are all (supposedly) oriented downstream, so I didn't have to deal with this. If the line orientation is not deliberate, it could be arranged as a pre-process to what I suggested above. If orientation is deliberate, then one could make a copy, re-orient, and use my recipe. The points will still line up on the original line featureclass properly, even if its orientation isn't conducive to the current analysis. –  Roland Jan 23 at 23:54
add comment

i think you can get it with Feature Vertices To Points (Data Management) method. you can get more info here.

or you can check out Split Line At Point (Data Management) here.

they are not enough entirely but you can write your own code...

i hope it helps you...

share|improve this answer
It seems like the problem with these options is that they require prior knowledge of the point location in order to split the line, or to add a vertice at the line prior to splitting it. That point location is what is Not known in the question above, so it is hard to apply either of these solutions. –  Get Spatial May 31 '12 at 15:16
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.