Select to view content in your preferred language

Point Distance based on Attributes

3408
1
Jump to solution
05-26-2015 10:46 AM
GaryBarden
Regular Contributor

What's the easiest way to calculate the distance between 2 points, from 2 different features, that have matching attribute?

Gary Barden

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Gary,

You could accomplish this with a python script that uses the Point Distance tool.  Below is an example that creates an individual feature layer based on an attribute selection for each feature class, and then runs the point distance analysis on these two points.

import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
env.overwriteOutput = 1

fc1 = "pointA"
fc2 = "pointB"

#retrieve unique field values
valueList = []
with arcpy.da.SearchCursor(fc1, ["PIN"]) as cursor:
  for row in cursor:
    list.append(row[0])

del cursor

#run Point Distance analysis
firstTime = 1

for value in valueList:
  if firstTime == 1:
    arcpy.MakeFeatureLayer_management(fc1, "fcLyrA", "PIN = '" + value + "'")
    arcpy.MakeFeatureLayer_management(fc2, "fcLyrB", "PIN = '" + value + "'")
    arcpy.PointDistance_analysis("fcLyrA", "fcLyrB", r"IN_MEMORY\pointDistance")
    firstTime = 2
  else:
    arcpy.MakeFeatureLayer_management(fc1, "fcLyrA", "PIN = '" + value + "'")
    arcpy.MakeFeatureLayer_management(fc2, "fcLyrB", "PIN = '" + value + "'")
    arcpy.PointDistance_analysis("fcLyrA", "fcLyrB", r"IN_MEMORY\pointDistance_" + str(value))
    arcpy.Append_management(r"IN_MEMORY\pointDistance_" + str(value), r"IN_MEMORY\pointDistance")

#export table results    
arcpy.CopyRows_management(r"IN_MEMORY\pointDistance", "pointDistanceResults")

View solution in original post

1 Reply
JakeSkinner
Esri Esteemed Contributor

Hi Gary,

You could accomplish this with a python script that uses the Point Distance tool.  Below is an example that creates an individual feature layer based on an attribute selection for each feature class, and then runs the point distance analysis on these two points.

import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
env.overwriteOutput = 1

fc1 = "pointA"
fc2 = "pointB"

#retrieve unique field values
valueList = []
with arcpy.da.SearchCursor(fc1, ["PIN"]) as cursor:
  for row in cursor:
    list.append(row[0])

del cursor

#run Point Distance analysis
firstTime = 1

for value in valueList:
  if firstTime == 1:
    arcpy.MakeFeatureLayer_management(fc1, "fcLyrA", "PIN = '" + value + "'")
    arcpy.MakeFeatureLayer_management(fc2, "fcLyrB", "PIN = '" + value + "'")
    arcpy.PointDistance_analysis("fcLyrA", "fcLyrB", r"IN_MEMORY\pointDistance")
    firstTime = 2
  else:
    arcpy.MakeFeatureLayer_management(fc1, "fcLyrA", "PIN = '" + value + "'")
    arcpy.MakeFeatureLayer_management(fc2, "fcLyrB", "PIN = '" + value + "'")
    arcpy.PointDistance_analysis("fcLyrA", "fcLyrB", r"IN_MEMORY\pointDistance_" + str(value))
    arcpy.Append_management(r"IN_MEMORY\pointDistance_" + str(value), r"IN_MEMORY\pointDistance")

#export table results    
arcpy.CopyRows_management(r"IN_MEMORY\pointDistance", "pointDistanceResults")