You are not logged in.

#1 2022-01-18 16:59:16

PWalsh
Member
Registered: 2022-01-14
Posts: 4

How to produce an .osm file containing county borders

Hi folks--
For an already existing in-house process, I need to refresh a very out-dated file.
What I need is a .osm file containing the boundaries for all US counties. (I need this in order to resolve county FIPS codes (aka SAME codes) into boundaries.)
One approach that I've tried is to iterate over a list of the FIPS codes that I need to resolve, and for every code, retrieve the boundaries, e.g (in pseudo-code):

    for every fips_code:
        query the overpass-api for:   
                relation["nist:fips_code"=fips_code];
                out geom;

This approach would result in over 3000 hits against the overpass-api, and has other downsides as well.

The second approach would be a single query for all admin-level=6 objects in the U.S., which is something like:

    {{geocodeArea:UnitedStates (?) }}->.searchArea;
    relation["admin_level"="6"];
    out geom;

This approach would have the effect of asking for a large dataset all at once (looking beyond the fact I don't currently know how to correctly ask for "all county-level objects in the United States."

Are there better alternatives?

(I've found websites offering up various extracts from OSM that would probably contain what I need, but none of them seem to be in the .osm format that our current process needs. And if we can devise a query that successfully pulls the data we want, we slightly prefer that approach.)

Thanks for any advice/info/guidance,

Phil Walsh

Offline

#2 2022-01-18 19:32:57

PWalsh
Member
Registered: 2022-01-14
Posts: 4

Re: How to produce an .osm file containing county borders

A third approach, that I did not expect to work but actually does, it to create a script calling out each individual fips-code, and retrieving them all in a union. This is surprisingly fast:

(
relation["nist:fips_code"="01001"];
relation["nist:fips_code"="01003"];
relation["nist:fips_code"="01005"];
relation["nist:fips_code"="01007"];
relation["nist:fips_code"="01009"];
relation["nist:fips_code"="01011"];
relation["nist:fips_code"="01013"];
[...3000 lines deleted...]
);
out geom;

and doesn't even require anything other than the default values for 'timeout' and 'maxsize.'

I can generate the lines of the script and execute it in python, so barring some other hurdles, this seems to be very workable.

Offline

Board footer

Powered by FluxBB