When working with maps and JavaScript, if you need to outline or shade states or counties on a map you need a huge list of coordinates that make up that shape. Sometimes it’s a single polygon but sometimes, like in the case of Alaska, it’s a MultiPolygon.
I’ve worked on more maps in the last couple months than I have in the last few years but haven’t ever been able to find all of the counties of the US in geoJSON/JSON format, only in KML or CSV.
This weekend I wrote a parser that takes the CSV’s that hold the data and creates individual files for each state as well as a master file for the whole US.
Enjoy!
I made a endpoint to help in this using the data:
http://api.reaperfire.com/reaperfire/rest/v1/public/boundary?city=Washington&state=DC&isAnd=true&format=geojson
http://api.reaperfire.com/reaperfire/rest/v1/public/boundary?zipCode=20695&isAnd=true&format=geojson
example GoogleMap integration:
http://api.reaperfire.com
Thanks for sharing Jeryl, this looks great! Since you’re using it as a service would you mind placing credit somewhere in the API or the front end? It took some work to get all of this prepared. Thanks!
Would it be possible to use these files to query the coords of a specific county and only show that county on a map?
Definitely. You could either download the state by state county files above and load just the state with the county you want to display, or you could download the ‘All US County Boundaries,’ assign that to a variable (eg: var counties = {{countiesObject}}) and then query that object for the county by state and then county name.
Thanks for sharing. I’m trying to use these with mapbox (leaflet.js) and have something like https://gist.github.com/gwintrob/fb338ff40d037d023356. Unfortunately, I don’t see anything on the map. Do you have any tips to get started?
Thanks again!
Nothing is jumping out at me immediately, do you have any more context in the code that you could provide so I can help you debug it? Maybe something on Codepen or a collaborative platform like that?
Looking to see if there is a featurecollection, features JSON specific to be used in LeafLet for counties?
Hey Jared, could you please clarify your question? You could absolutely use this in Leaflet.
Nice work. Have you considered posting the geoJSON to Github?
I have thought of it but haven’t found the time to license it and post it. Thanks for the reminder!
This was exactly what I was looking for – separate files of all counties state-by-state. Thanks!
However, I had issues using them as-is with my d3.js application. When I checked them with GeoJSON Lint (http://geojsonlint.com), it returned 2 errors — the first polygon point has to the same as the last one, and the ‘features’ object needs to be a JSON array.
I was able to write a sctipt to modify them and get everything working. I can send you updated files if you’re interested. Thanks again for your hard work!
I have downloaded state counties and using in open layers 3. I don’t see any map loading.
Do you have code you could share?
I started to search for us county api on the web for the last few month but missed this site, so I made a small api for myself.
https://us-county-boundary-api.herokuapp.com/api?state=TX&county=Brazos
This is a RESTFUL API.
Hey brother, you made my day! Thank you so much! The universe and God bless you 😀