I am using ArcMap 10.4.1 - Basic use.

I have to determine for each point (leak), how many lines (pipes) there are within a certain distance (Spatial join - within a distance of).

Then I have to proceed with this filtered dataset and determine the distance from that point to all lines within a certain distance. I want the same calculation method as closest, but then for all lines and not only the closest. Additionally, a line can be in a certain distance of multiple points.

As I make use of the basic license, I do not have the option of using the proximity toolbox (near tool). Is there a workaround to determine the distance from a point to all lines within a certain distance?

I already thought of the tool points to lines, but as this is a many-to-many relationship it is not possible directly.

1 Answer 1


Script below designed to run from mxd. It assumes that you have empty a table (“nearLines”) to populate in mxd:

table structure

Where pointID and lineID are fields to store OIDs of input layers (type long), Distance field type double.

import arcpy
# parameters to re-type
mxd = arcpy.mapping.MapDocument("CURRENT")
# get lines
lines = arcpy.mapping.ListLayers(mxd,"lines")[0]
fidLine = d.OIDFieldName
# get points
points = arcpy.mapping.ListLayers(mxd,"points")[0]
fidPoint = d.OIDFieldName
table = arcpy.mapping.ListTableViews(mxd,"nearLines")[0]
# process
with arcpy.da.SearchCursor(points,(fidPoint,"Shape@")) as cursor:
    for fid,shp in cursor:nodesDict[fid]=shp.firstPoint
with arcpy.da.SearchCursor(lines,(fidLine,"Shape@")) as cursor:
    for fid,shp in cursor:
        for key, point in nodesDict.iteritems():
            if dist > maxDistance:continue

I hope there are enough comments in script to understand it’s logic...

It took 1 min 8 seconds to process 1000 points and 1200 lines on my rather solid machine. I summarised nearLines table, points below coloured by count of lines within 100 m:

output example

Learn Python and you’ll be able to work around licensing limitations, e.g. this and sometimes absence of extension.

  • Thank you very much. I tried to execute the script and get following error: Traceback (most recent call last): File "C:\Users\rgys\Desktop\Distance.py", line 18, in <module> for fid,shp in cursor:nodesDict[fid]=shp.firstPoint AttributeError: 'NoneType' object has no attribute 'firstPoint' Do you have an idea what this means?
    – user81381
    Commented Sep 28, 2016 at 8:39
  • It means that you have empty geometries. Run repair geometry on both sets
    – FelixIP
    Commented Sep 28, 2016 at 8:47

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.