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

3301
2
Jump to solution
08-18-2016 03:33 PM
Comisión_Estatal_de_Aguasde_Qu
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.The lines would be like blue lines as shown in this picture

0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
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‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

2 Replies
DanPatterson_Retired
MVP Esteemed Contributor

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

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

View solution in original post