Hello! I am currently generating a layer parallel to a layer of existing lines , from a point layer lines . Can someone please help me to resolve this situation ? Thank you very much.
Solved! Go to Solution.
This is possible with Python and Basic license, although untested for large datasets (I did run this against 1000+ points and it was fine).
First step is to dissolve all roads into a single feature, although you could loop through them with added code.
>>> points = "points_select" # points layer
... sr = arcpy.Describe(points).spatialReference # get CRS
... lines = "roads_select" # roads feature class containing single, merged feature for all roads
... out_lines = [] # output list
... line_geom = [i[0] for i in arcpy.da.SearchCursor(lines,'SHAPE@',spatial_reference=sr)] # the road feature
... with arcpy.da.SearchCursor(points,'SHAPE@') as cursor: # loop through points
... for row in cursor:
... end = line_geom[0].queryPointAndDistance(row[0])[0].centroid # get nearest point on line
... start = row[0].centroid
... out_lines.append(arcpy.Polyline(arcpy.Array([start,end]),sr)) # connect the dots and add to line list
... arcpy.CopyFeatures_management(out_lines,r'in_memory\out_lines') # write line list to disk
If memory serves
Near—Help | ArcGIS for Desktop followed by
XY To Line—Help | ArcGIS for Desktop
once you have your from and to, xy coordinates
... cavaet... you have the advanced license for ArcMap
This is possible with Python and Basic license, although untested for large datasets (I did run this against 1000+ points and it was fine).
First step is to dissolve all roads into a single feature, although you could loop through them with added code.
>>> points = "points_select" # points layer
... sr = arcpy.Describe(points).spatialReference # get CRS
... lines = "roads_select" # roads feature class containing single, merged feature for all roads
... out_lines = [] # output list
... line_geom = [i[0] for i in arcpy.da.SearchCursor(lines,'SHAPE@',spatial_reference=sr)] # the road feature
... with arcpy.da.SearchCursor(points,'SHAPE@') as cursor: # loop through points
... for row in cursor:
... end = line_geom[0].queryPointAndDistance(row[0])[0].centroid # get nearest point on line
... start = row[0].centroid
... out_lines.append(arcpy.Polyline(arcpy.Array([start,end]),sr)) # connect the dots and add to line list
... arcpy.CopyFeatures_management(out_lines,r'in_memory\out_lines') # write line list to disk