I have two nonparallel lines and I need to find the average line between them. This is proving to be more difficult than expected.
Is there a fairly simple way to do this?
I thought I could use a series of points for each line, then find the mid point of each set of points then created a line using said points, however this didn't work has I had hoped. The lines are not the same length fyi. I do have an ArcGIS Advanced license.
Answer
Neither of my suggestions works. I have my own script to handle this, but I am not prepared to share it. Let’s try to solve it with minimum scripting by using linear referencing:
## create anchor points at intersections
arcpy.Intersect_analysis("LINES", "D:/Scratch/mpoints.shp","ALL", output_type = "POINT")
arcpy.MultipartToSinglepart_management("mpoints","D:/Scratch/anchors.shp")
arcpy.DeleteIdentical_management("anchors","Shape")
# calculate their distance along the line
arcpy.AddField_management("anchors", "CHAINAGE", "DOUBLE")
Run this field calculator expression on field CHAINAGE
def Chainage(shp):
mxd = arcpy.mapping.MapDocument("CURRENT")
lr=arcpy.mapping.ListLayers(mxd,"lines")[0]
with arcpy.da.SearchCursor(lr, 'Shape@') as cursor:
for row in cursor: geom=row[0]
L=geom.measureOnLine (shp.firstPoint)
return int(L)
#-------------------------
Chainage(!Shape! )
#sort anchor points accordingly
arcpy.Sort_management("anchors","D:/Scratch/sorted.shp", "CHAINAGE ASCENDING")
Create multiple rows table in Excel. I've made it 1240 rows long (1274-35+1) in order to place points on the line at about 1 m apart:
and bring this table to mxd
# Place ‘equally’ spaced points on BLUE line
arcpy.CalibrateRoutes_lr("LINES", "Name", "sorted", "Name", "CHAINAGE","D:/Scratch/routes.shp")
arcpy.MakeRouteEventLayer_lr("routes", "Name", "from_Excel", "LINE POINT m", "BLUE_POINTS", point_event_type="POINT")
Repopulate NAME fields in “sorted” and “from_Excel” and create points on RED line.
# create cross-lines
arcpy.Merge_management("RED_POINTS;BLUE_POINTS", "D:/Scratch/merged.shp")
arcpy.PointsToLine_management("merged", "D:/Scratch/grey_sections.shp", Line_Field="M")
# compute their mid points and draw the line
arcpy.FeatureVerticesToPoints_management(“grey_sections", “D:/Scratch/mid_points.shp", "MID")
arcpy.PointsToLine_management("mid_points", "..Green_Line.shp", Sort_Field="M")
NOTES:
- to handle sharp turns one might convert red/blue lines to polygons and clip "grey" lines using these polygons. Use mid points of clipped version to construct final line
- Append anchor points to mid points, to force line going through all intersections. ArcGIS refuses to create "grey" line out of 2 coincident points
No comments:
Post a Comment