# Extracting polygons along a border

I have a shapefile of United States counties. Suppose I am interested in all counties in Georgia that border North Carolina and all counties in North Carolina that border Georgia. And, in particular, I'm interested in knowing which Georgia counties border which North Carolina counties. For example, suppose Rabun County, Georgia is along this border. I want to know which is the county that borders Rabun in North Carolina.

My ultimate goal is as follows: I believe that Rabun, Georgia borders both Clay, North Carolina and Macon, North Carolina. I would like to then create two files. One would be the line segment of the border segment between Rabun and Clay. The other would be the line segment of the border between Rabun and Macon. I know line segments can be isolated between two bordering geographic units by using intersect. For example, if I were to intersect Rabun and Clay as two separate files, I would isolate the line segment that is their shared border.

I would like to repeat this procedure for every other pair of counties along the Georgia and North Carolina (in addition to other borders, which is why I would like to streamline the process).

Are there hints for streamlining this process? I know how to do it by brute force, but I realize it can take awhile or be inaccurate. I was just wondering if there is a more efficient way to do this.

I juse ArcMap and ArcGIS 10.1.

Thank you!

-
Is there a reason you're isolating line segments or is that just a means of knowing which counties share a border? – Roy Oct 10 '12 at 17:56
Yes, there is a reason. I want to calculate distances. Like, say I want the distance of every county in Florida to each of these segments. Like the distance of Dade County, Florida to each segment, the distance of Jackson County, Florida to each segment, and so forth. I then want to know which segment yields the minimum distance for Dade County (and all other Florida counties) and what that distance is. – user1690130 Oct 10 '12 at 17:59
What's your means of measurement tho? As the crow flies, or travel based on actual roads? – Roy Oct 10 '12 at 18:01
Distance using the Near function. Under Proximity. Centroid to segment. – user1690130 Oct 10 '12 at 18:06
@Roy Would you still recommend the same procedure? Also, how would I implement the Cursor? – user1690130 Oct 10 '12 at 18:30

Share a line segment with (option)

With this method, the source and target features are considered as sharing a line segment if their geometries have at least two contiguous vertices in common.

The source and target features must be either lines or polygons.

The highlighted cyan features are selected because they share a line segment with a red feature.

http://resources.arcgis.com/en/help/main/10.1/index.html#//00s50000002q000000

to Automate the process use ModelBuilder http://resources.arcgis.com/en/help/main/10.1/index.html#//002w00000001000000

-
Thank you for your post! I don't I understand how to implement this at all, however. – user1690130 Oct 10 '12 at 17:23

Programatically you could use a Cursor with Select By location.

The output is really up to you as I'm not sure how you're planning on using the information. You could append all of the county names in a list and add it to a field. You could create a related table and add a record for each individual bordering county.

In order to select the counties of interest with arcpy build your code around this pseudo code:

1. Make a feature layer of all NC counties.
2. Make a feature layer of all GA counties.
3. Using a Search Cursor on the NC counties feature layer, loop through each polygon.
1. Select GA counties from feature layer that share a line segment with the current NC county.
2. Decide what you want to do with these counties (a few examples above)

Hopefully this should get you started:

``````import arcpy

stateField = '' # Enter the name of the field storing state name
states = ["Georgia", "North Carolina"] # The states used in the SQL query below

GAcounties = '"' + stateName + '" = ' + "'" + states[0] + "'"
NCcounties = '"' + stateName + '" = ' + "'" + states[1] + "'"

# Make a feature layer for counties in GA, and in NC
arcpy.MakeFeatureLayer_management(countiesFC, "GA", GAcounties)
arcpy.MakeFeatureLayer_management(countiesFC, "NC", NCcounties)

# Create a search cursor for the Georgia counties feature class
GAcursor = arcpy.SearchCursor("GA")

# Loop through each county in GA, select the NC counties that it shares a line segment with
for county in GAcursor:
arcpy.SelectLayerByLocation_management("NC", "SHARE_A_LINE_SEGMENT_WITH", county)

# Do stuff like arcpy.Intersect_analysis(), or arcpy.Copy_management()
``````
-
Steps 1 and 2 I can do. Step 3, though, I'm not sure how to implement. I went to Search by Location. I don't see where the Search Cursor is, however. I will add more detail to my initial post about what I'm trying to do. Thank you! – user1690130 Oct 10 '12 at 17:15
Haven't tested it, but it gives you the major jist. – Roy Oct 10 '12 at 18:37
Thank you for posting this! Do I copy and paste that program? Where do I put it in GIS and how do I execute it? Do I need to do anything else to direct the program to the inputs? – user1690130 Oct 10 '12 at 18:59
You'd run in in the Python window of ArcMap, but as I said it's not a complete solution. It's highly likely you'd need to have some scripting knowledge to debug / manipulate the script to do exactly what you're looking for. I didn't supply the field name that contains the state, nor did I include the path to your counties shapefile / feature class. – Roy Oct 10 '12 at 19:46

Let ArcGIS do all the work. 10.1 has a new tool called "Polygon Neighbors", under Analysis Tools, Proximity, that basically builds an adjacency table for you. You can review the resulting Table, deleting the entries where "Src" and "NBR" are from the same State.

-