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.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
user81381
  • 155
  • 6

1 Answers1

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.

FelixIP
  • 22,922
  • 3
  • 29
  • 61
  • 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 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 Sep 28 '16 at 08:39
  • It means that you have empty geometries. Run repair geometry on both sets – FelixIP Sep 28 '16 at 08:47