I have two shape files: one has point features indicating urban centers, the other is a polygon features file that has counties. Each county has one urban center. There are around 2800 counties. I want to find the distance between one urban center in a county to all of its neighboring urban centers (by this I mean centers located in counties that border the selected county)

For example, if county 1 borders county 3 and county 2, I would like to find the distance between urban center 1 (located in center 1) and center 3, and between center 1 and center 2. If county 7 borders county 8, 9 and 10, I want to find the distance between urban center 7 and centers 8,9 and 10.

So far I have tried the following:

  1. I have tried using the Near Generate Table and the Near tool. The problem with this is that I do not only want to find the distance between points that are closest to one another, but rather find the distance between a point and all of its neighboring points.
  2. I used the point distance tool, which gives me the point distance between every single point for all 2800 points, and this is very redundant and inefficient, since I only want to find the distance between neighboring point features.

Is there any way to do this in ArcGIS Desktop 10.3?


1 Answer 1


Solution below assumes:

  • you are using ArcGIS Desktop 10.3
  • you are working from mxd, name of polygon layer is PGONS, it has unique name stored in field PGON_ID and you transferred coordinates of centres into PGONS table and stored in fields as shown below:

enter image description here

arcpy.SpatialJoin_analysis("PGONS", "PGONS", "D:/Scratch/SJ.shp", join_operation="JOIN_ONE_TO_MANY", join_type="KEEP_ALL", field_mapping="""PGON_ID "PGON_ID" true true false 10 Text 0 0 ,First,#,PGONS,PGON_ID,-1,-1;POINT_X "POINT_X" true true false 19 Double 0 0 ,First,#,PGONS,POINT_X,-1,-1;POINT_Y "POINT_Y" true true false 19 Double 0 0 ,First,#,PGONS,POINT_Y,-1,-1;PGON_ID_1 "PGON_ID_1" true true false 10 Text 0 0 ,First,#,PGONS,PGON_ID,-1,-1;POINT_X_1 "POINT_X_1" true true false 19 Double 0 0 ,First,#,PGONS,POINT_X,-1,-1;POINT_Y_1 "POINT_Y_1" true true false 19 Double 0 0 ,First,#,PGONS,POINT_Y,-1,-1""", match_option="SHARE_A_LINE_SEGMENT_WITH", search_radius="", distance_field_name="")
arcpy.AddField_management(in_table="SJ", field_name="DISTANCE_M", field_type="LONG")
arcpy.CalculateField_management(in_table="SJ", field="DISTANCE_M", expression="sqr(( [POINT_X]- [POINT_X_1])^2+ ( [POINT_Y]- [POINT_Y_1])^2)", expression_type="VB", code_block="")
arcpy.SelectLayerByAttribute_management(in_layer_or_view="SJ", selection_type="NEW_SELECTION", where_clause=""""DISTANCE_M" =0""")                  

You can now summarise new layer called SJ using PGON_ID as case field and find statistics of distances to other polygons’ centres stored in field DISTANCE_M To implement solution use Python window and copy/paste line by line into it. You have to change 3rd parameter in first line that is an output of spatial join.

Picture shows PGONS labelled by distance to their neighbours:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.