[GIS] get (USA) county neighbour relationship data

countygeographyrelationship-class

I need a graph where each node is a US county and each edge represents a border shared between counties. I do not particularly care about the absolute position or shape of each county (though that would be a plus).

Where can I find that information (for free)? Army Corp of Engineers? US Geo Survey?

Ideally, I could just get a csv list something like

  • FL-Polk, FL-Lake
  • FL-Polk, FL-Orange
  • FL-Polk, FL-Osceola
  • etc for every county, including "kitty-corner" borders, borders across water, or across state borders

I'm a programmer so expect I can handle any standard exchange format. (That could just be hubris though). (I don't have any cool GIS apps. Just humble scripting in perl and python.)

Best Answer

You could find a topological representation of county boundaries, such as the CTA boundary files (another source would be the OpenStreetMap, but that's not as complete) and then pick out all distinct pairs of county IDs on opposing sides of boundary lines - e.g. in the CTA files, there's these two fields in the link entity (as described in the documentation):

 (10)  county FIPS left    I6      48-53   
 (11)  county FIPS right   I6      54-59

EDIT: After request, here's the details on how to get the data:

  1. To get all county codes, go to the page linked above, click on the 'List of county codes'.

  2. To read the adjacent IDs, there's two options:

    • download the shapefile ("GO" button next to Download SCUL), open the zip and read the .dbf file (there's loads of programs that open it, e.g. Excel, and the file is basically fixed-width-row ASCII table, so you should be able to extract the last two columns easily)

    • or download the native format (i'd first try to see if the state boundaries contains the counties as well) open the .llr file, split it by lines (line ends with CR+LF = 0D 0A) and extract the ids from each line: left FIPS is in chars 48-53; right FIPS is in chars 54-59 (index of the first character in a line is 1)

Related Question