Hello,

Can anyone suggest me to draw the perpendicular line for very point automatically using python/arcobject. That Perpendicular line touch with line feature. Kindly reference the below image.

Regards,

Raj

Hello,

Can anyone suggest me to draw the perpendicular line for very point automatically using python/arcobject. That Perpendicular line touch with line feature. Kindly reference the below image.

Regards,

Raj

- 4 people found this helpful
Darren Wiens posted some code here which should get you started. Your normals are to the X-axis rather than relative to the line. You can construct an intersecting line relative to that axis which should give you the necessary point intersection on your line and hence the point-line segment

- 6 people found this helpful
The code below seems to do the job, BUT this is based on a single line. If you have several polylines you will have to include logic to select the polyline to "snap to".

import arcpy def main(): fc_lines = r'D:\Xander\GeoNet\Perpendicular\data.gdb\lines' fc_points = r'D:\Xander\GeoNet\Perpendicular\data.gdb\points' fc_out = r'D:\Xander\GeoNet\Perpendicular\data.gdb\result' tolerance = 15000 # get first line polyline = arcpy.da.SearchCursor(fc_lines, ('SHAPE@')).next()[0] lines = [] with arcpy.da.SearchCursor(fc_points, ('SHAPE@')) as curs: for row in curs: pnt = row[0] line = createVerticalLine(pnt.firstPoint, tolerance, pnt.spatialReference) mp = getIntersectingPoints(line, polyline) if mp.pointCount > 0: pnt2 = getNearestPoint(mp, pnt.firstPoint) vert_line = arcpy.Polyline(arcpy.Array([pnt.firstPoint, pnt2]), pnt.spatialReference) lines.append(vert_line) else: # no intersecting within tolerance pass arcpy.CopyFeatures_management(lines, fc_out) def createVerticalLine(pnt, tolerance, sr): return arcpy.Polyline(arcpy.Array([arcpy.Point(pnt.X, pnt.Y+tolerance), arcpy.Point(pnt.X, pnt.Y-tolerance)]), sr) def getIntersectingPoints(line, polyline): return polyline.intersect(line, 1) def getNearestPoint(mp, pnt): nearest_pnt = None for p in mp: if nearest_pnt is None: nearest_pnt = p min_dist = getDistance(p, pnt) else: dist = getDistance(p, pnt) if dist < min_dist: nearest_pnt = p min_dist = dist return nearest_pnt def getDistance(p1, p2): import math return math.sqrt((p1.X-p2.X)**2 + (p1.Y-p2.Y)**2) if __name__ == '__main__': main()

The code below seems to do the job, BUT this is based on a single line. If you have several polylines you will have to include logic to select the polyline to "snap to".