# ArcPy - How to create a perpendicular line to an existing line since one especific point in ArcGIS

3301
2
08-18-2016 03:33 PM
New Contributor II

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.

Tags (1)
1 Solution

Accepted Solutions
MVP Honored Contributor

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‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``

2 Replies
MVP Esteemed Contributor

If memory serves

Near—Help | ArcGIS for Desktop followed by

once you have your from and to, xy coordinates

``>>> 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‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``