1

I have a polyline SHP (with only one feature) that I have converted to a route using arcpy.CreateRoutes_lr(). I have a separate points SHP that is spatially scattered about the line. I want to "collapse" the points onto the route, and then for each FID in the points file, find the distance of the collapsed point along my route, relative to the start of the route.

I tried Locate Features Along Routes just in ArcMap from the toolbox, as suggested by "gisnside" here, but the distance returned is the distance between the point and the line (exactly the same output as Near Analysis gives), not the distance of the collapsed point along the line.

Other details:

  • Both polyline and points SHPs are in the same UTM projection.
  • The "route_id" layer is correct in the route file.
  • All of the points have a unique integer id in a "pointid" field
  • Must be accomplished in ArcPy; process to run many times.

# file location setup
myline = r'mypath\line_projected.shp'
mypoints = r'mypath\points_prpjected.shp'

arcpy.AddGeometryAttributes_management(myline, "LENGTH_GEODESIC", Length_Unit = "METERS")
outroute = mypath + '\\' + 'myroute.shp'
arcpy.CreateRoutes_lr(myline, "route_id", outroute, "LENGTH", coordinate_priority = "LOWER_LEFT")
# ... what tool to use ...
1

Linear referencing is correct tool but requires calibration. With just one line simply run this in field calculator on numeric field of points table:

lineLayer="Line"
g=arcpy.Geometry()
theLine=arcpy.CopyFeatures_management(lineLayer,g)[0]
def Chainage(shp):
 return theLine.measureOnLine (shp.firstPoint)
#-----
Chainage(!Shape!)

Output for line with total length 2766 m:

enter image description here

  • Thanks @FelixIP. I have to do this in arcpy, not field calculator. Repeating this a few hundred times. I don't understand how your code fits into or follows mine? – AlexS1 Mar 27 at 15:46
  • I can clearly see my mistake now. – FelixIP Mar 27 at 20:00
0

Ended up figuring it out; it was a matter of getting the right out_event_properties in Locate Feature on Route. Code is below. No calibration needed, results ("MEAS" and "DISTANCE" fields) validated and verified.

# file location setup
myline = r'mypath\line_projected.shp'
mypoints = r'mypath\points_projected.shp'

arcpy.AddGeometryAttributes_management(myline, "LENGTH_GEODESIC", Length_Unit = "METERS")
myroute = r'mypath\route.shp'
arcpy.CreateRoutes_lr(myline, "route_id", myroute, "LENGTH", coordinate_priority="LOWER_LEFT")
pts2route = r'mypath\ptsroute_table'
arcpy.LocateFeaturesAlongRoutes_lr(mypoints, myroute, "route_id", "1000 Kilometers", pts2route, "RID POINT MEAS")

# table join to get the route fields onto my original "points_projected.shp"
# "MEAS" field created by LocateFeaturesAlongRoutes_lr and is length in meters on route
# "DISTANCE" field created by LocateFeaturesAlongRoutes_lr and is perpendicular distance left/right (up/down) between point and route
arcpy.JoinField_management(mypoints, "pointid", ptsonroute, "pointid", ["MEAS", "DISTANCE"])

# clean up to get rid of orphan table
arcpy.Delete_management(pts2route)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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