[GIS] Performing Point Distance analysis using Basic level license of ArcGIS Desktop

arcgis-10.1arcgis-desktopdistancedistance matrixproximity

I am using ArcView (ArcGIS Desktop Basic) 10.1 and I need to perform a point distance analysis.

What are the steps to determine the distance from A to B-Z, B to A-Z, C to A-Z, etc?

Best Answer

The following code is not polished but should work to create the same output table as the Point Distance tool but requires ArcGIS 10.1 (or later) for Desktop and only a Basic level license:

import arcpy,math

# Set variables for input point feature classes and output table
ptFC1 = "C:/temp/test.gdb/PointFC1"
ptFC2 = "C:/temp/test.gdb/PointFC2"
outGDB = "C:/temp/test.gdb"
outTableName = "outTable"
outTable = outGDB + "/" + outTableName

arcpy.env.overwriteOutput = True

# Create empty output table
arcpy.CreateTable_management(outGDB,outTableName)
arcpy.AddField_management(outTable,"INPUT_FID","LONG")
arcpy.AddField_management(outTable,"NEAR_FID","LONG")
arcpy.AddField_management(outTable,"DISTANCE","DOUBLE")

# Create and populate two dictionaries with X and Y coordinates for each
# OBJECTID in second feature class using a SearchCursor
ptFC2XCoordDict = {}
ptFC2YCoordDict = {}
with arcpy.da.SearchCursor(ptFC2,["OBJECTID","SHAPE@XY"]) as cursor:
    for row in cursor:
        ptFC2XCoordDict[row[0]] = row[1][0]
        ptFC2YCoordDict[row[0]] = row[1][1]

# Open an InsertCursor ready to have rows written for each pair of OBJECTIDs
iCursor = arcpy.da.InsertCursor(outTable,["INPUT_FID","NEAR_FID","DISTANCE"])
# Use a SearchCursor to read the rows (and X,Y coordinates) of the first
# feature class
with arcpy.da.SearchCursor(ptFC1,["OBJECTID","SHAPE@XY"]) as cursor:
    for row in cursor:
        x1 = row[1][0]
        y1 = row[1][1]
        for i in range(len(ptFC2XCoordDict)):
            x2 = ptFC2XCoordDict[i+1]
            y2 = ptFC2YCoordDict[i+1]
            # Prepare and insert the InsertCursor row
            iRow = [row[0],i+1,math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))]
            iCursor.insertRow(iRow)
del iCursor

print "Done!"
Related Question