Here's my situation - I'm working on a project that requires 20,000+ short connector lines be created, each drawn from a point to a snapped location on a nearby polyline such that the resulting connector line is perpendicular to the polyline.

If done with arcpy, this requires a script that can a.) find the nearest polyline, b.) calculate the place on that polyline that will enable a perpendicular line to be created, c.) create temporary coordinates at that location, and d.) create the connector line.

Has anybody tried something like this? What specific commands might be necessary? Thanks in advance for your help.


4 Answers 4


Take a look at the script linked below. Maybe it will work for you, or maybe you will be able to modify them to fit your needs:

  • Link is broken :(
    – bertday
    Commented Feb 17, 2015 at 17:26

Sorry, got busy at work and couldn't post until now. Below is the script I rolled up from the suggestions.

It strikes me in hindsight that this might also be achieved with an edge snap instead of a near command - it looks like arcGIS basically performs a near command on the snap.


import arcpy, os

inPoints = arcpy.GetParameterAsText(0)
nearLines = arcpy.GetParameterAsText(1)
outFC = arcpy.GetParameterAsText(2)
scratchWorkspace = arcpy.GetParameterAsText(3)

# Get the scratch workspace.
#scratchWorkSace = env.scratchWorkspace

# Get the spatial reference of the input
spatialRef = arcpy.Describe(inPoints).spatialReference

# Determine the temporary output feature class path and name
tempFC = os.path.join(scratchWorkspace, "temp")

# Copy input point features to temporary feature class
arcpy.CopyFeatures_management(inPoints, tempFC)

# Add XY coordinates for point features

# Perform Near Analysis
arcpy.Near_analysis(tempFC, nearLines, "", "LOCATION", "NO_ANGLE")

# Create connector line FC using XY To Line
arcpy.XYToLine_management("tempFC", "outFC", "POINT_X", "POINT_Y", "NEAR_X", "NEAR_Y", "GEODESIC", "", "spatialRef")

except Exception, e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print "Line %i" % tb.tb_lineno
print e.message

Also, you can try the Near command. It will add the closest XY coordinate on the Line FC to the Point FC table. Most of the time this is perpendicular. Run Add XY coordinates to populate the Point xy coords. You can easily create a line connecting the two locations with "XY to Line", new in ArcGIS 10. Shouldn't take too much to test this.

  • If the line from the point to the "nearest" point along a polyline is not perpendicular to the polyline, then the "nearest" point is incorrect!
    – whuber
    Commented Oct 18, 2011 at 16:12
  • Thanks, everyone, for your quick responses. Armed with the above information, I've gotten everything working. Commented Oct 18, 2011 at 16:31
  • 1
    @MichaelLachman, could you post your solution either as an answer or as an update to your question?
    – blah238
    Commented Oct 18, 2011 at 17:21

If no perpendicular can be drawn within the two end points of a polyline segment then the nearest point is the closer end point. So, this statement is not always true:

"If the line from the point to the "nearest" point along a polyline is not perpendicular to the polyline, then the "nearest" point is incorrect!"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.