4

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.

5

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
maxDistance=100
mxd = arcpy.mapping.MapDocument("CURRENT")
# get lines
lines = arcpy.mapping.ListLayers(mxd,"lines")[0]
d=arcpy.Describe(lines)
fidLine = d.OIDFieldName
# get points
points = arcpy.mapping.ListLayers(mxd,"points")[0]
d=arcpy.Describe(points)
fidPoint = d.OIDFieldName
table = arcpy.mapping.ListTableViews(mxd,"nearLines")[0]
# process
curT=arcpy.da.InsertCursor(table,("POINTID","LINEID","DISTANCE"))
nodesDict={}
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():
            dist=shp.distanceTo(point)
            if dist > maxDistance:continue
            curT.insertRow((key,fid,dist))

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? – RG1991 Sep 28 '16 at 8:39
  • It means that you have empty geometries. Run repair geometry on both sets – FelixIP Sep 28 '16 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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