I need to determine the shortest distance between each point within a single feature class. Near Analysis would have worked perfectly, but unfortunately you need to have an Advanced ArcGIS Licence and I only have a Standard Licence.

I found the following code on Stack Exchange written by PolyGeo:

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!"

The following reports the distance of the first point to the rest of the points:

I would like to amend the following to iterate through each point within the feature class to report the shortest distance between the points, greater than zero of course. Any advice in amending the following will be appreciated. I'm trying to use the results from this as a way of validating that none of the points are within 3m or less from each other and if there are the filtered list is processed further to move the points away from each other within bounding box for each point.

Peter

distance from the first point in a point file to all other points in the file.

the rest of the problem is homework :

"""

result

Now where are those close points and how many of them are there? slice and dice. b[:,2] is the distance column ... b[:,2] < 1000 are all the distances < 1000 m ... Therefore:

b[b[:,2]<1000] must be all the records where the distance is less than 1000m .. now what? save it to a featureclass. And yes you can get all fancy with inputs, retaining variable, etc. but that should suffice. It is pretty quick up about 50,000,000 origin destinations.

Check Numpy Repository or contact me for further information.