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.
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".
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()
lines = 
with arcpy.da.SearchCursor(fc_points, ('SHAPE@')) as curs:
for row in curs:
pnt = row
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]),
# no intersecting within tolerance
def createVerticalLine(pnt, tolerance, sr):
return arcpy.Polyline(arcpy.Array([arcpy.Point(pnt.X, pnt.Y+tolerance),
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)
dist = getDistance(p, pnt)
if dist < min_dist:
nearest_pnt = p
min_dist = dist
def getDistance(p1, p2):
return math.sqrt((p1.X-p2.X)**2 + (p1.Y-p2.Y)**2)
if __name__ == '__main__':
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
Are you looking for a perpendicular line (90 degrees to the line, as I've added below) or a vertical line (as you've drawn)?
he wants normal to the x-axis rather than your example of normal to the line,
I need vertical line for each point and touch with line feature.
IProximityOperator proximity = <<PolylineFeature>>.ShapeCopy as IProximityOperator;
IPoint out_point = proximity.ReturnNearestPoint(<<input point>>, esriSegmentExtension.esriExtendTangentAtFrom);
Try this code, it will create perpendicular lines to given point.
True, but if you look at the examples you will see that it was not a perpendicular line the OP was looking for.
Retrieving data ...