Tuesday, August 15, 2017

ArcGIS Point Distance Without an Advanced License

The point distance tool generates a table that contains data on distances between points of two feature classes. Below is a function that will create the same table and doesn't require an advanced ArcGIS license.
The code:


import os
import arcpy

def PointDistance (inFeat, nearFeat, outTable):
    #create table
    tabPath, tabName = os.path.split (outTable)
    arcpy.CreateTable_management (tabPath, tabName)
    #add fields
    fldDi = {"INPUT_FID" : "LONG",
             "NEAR_FID" : "LONG",
             "DISTANCE" : "DOUBLE"}
    for fld in ["INPUT_FID", "NEAR_FID", "DISTANCE"]:
        arcpy.AddField_management (outTable, fld, fldDi [fld])
    with arcpy.da.InsertCursor (outTable, ["INPUT_FID",
                                           "NEAR_FID",
                                           "DISTANCE"
                                           ]) as iCurs:
        with arcpy.da.SearchCursor (inFeat,
                                    ["OID@",
                                     "SHAPE@"
                                     ]) as inCurs:
            with arcpy.da.SearchCursor (nearFeat,
                                        ["OID@",
                                         "SHAPE@"]
                                        ) as nearCurs:
                for inOid, inGeom in inCurs:
                    for nearOid, nearGeom in nearCurs:
                        row = (inOid, nearOid,
                               inGeom.angleAndDistanceTo (nearGeom) [1])
                        iCurs.insertRow (row)
profile for Emil Brundage at Geographic Information Systems Stack Exchange, Q&A for cartographers, geographers and GIS professionals

2 comments: