Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a dataset of zipcodes.

I want to add a new field "NEIGHBORS" that includes bordering polygons in a comma delimited manner such as attached image:

bordering polygons added to field

share|improve this question

2 Answers 2

You could use the ArcGIS Polygon Neighbors Tool, in the Analysis, Proximity Toolset to determine which are the bordering polygons.

share|improve this answer

As answered by @klewis the Polygon Neighbors tool is the key for writing what polygons are neighbors of each other into a Table.

However, I suggest you wrap that tool inside Python code like the test code below to do the additional steps of adding the field to hold your comma delimited list of neighbors, and some cursor work to read the one-to-many relationship between polygons and their neighbors and flatten them into that field. This test starts by creating a 3x3 test data set.

To see the result open ArcMap and drag in and then label the testFishnet feature class on the NEIGHBORS field.

import arcpy

if arcpy.Exists(r"C:\Support\user4015\test.gdb"):
    arcpy.Delete_management(r"C:\Support\user4015\test.gdb")

arcpy.CreateFileGDB_management("C:/Support/user4015","test","CURRENT")

arcpy.CreateFishnet_management("C:/Support/user4015/test.gdb/testFishnet","0 0","0 1","1","1","3","3",
                               "#","NO_LABELS","#","POLYGON")
arcpy.AddField_management("C:/Support/user4015/test.gdb/testFishnet","NEIGHBORS","TEXT","#","#","#","#",
                          "NULLABLE","NON_REQUIRED","#")

arcpy.PolygonNeighbors_analysis("C:/Support/user4015/test.gdb/testFishnet",
                                "C:/Support/user4015/test.gdb/testNeighbors",
                                "OID","NO_AREA_OVERLAP","BOTH_SIDES","#","UNKNOWN","UNKNOWN")
arcpy.MakeTableView_management("C:/Support/user4015/test.gdb/testNeighbors","testNeighbors_View")

with arcpy.da.UpdateCursor("C:/Support/user4015/test.gdb/testFishnet",["OID","NEIGHBORS"]) as uCursor:
    for uRow in uCursor:
        arcpy.SelectLayerByAttribute_management("testNeighbors_View","NEW_SELECTION","src_OID = " + str(uRow[0]))
        with arcpy.da.SearchCursor("testNeighbors_View","nbr_OID") as sCursor:
            neighbors = ""
            for sRow in sCursor:
                neighbors = neighbors + "," + str(sRow[0])      
        uRow[1] = neighbors.strip(",")
        uCursor.updateRow(uRow)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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