Does anyone know a reliable, efficient, and, ideally, free or cheap way to identify the county in which a particular city or town identified by "[locality name], [state abbreviation]" is located?
So far, I've found two ways to geocode U.S. counties, but both of them have problems for my use case.
One way is to use the U.S. Census Bureau's API, which the censusxy
package makes easy to do. The problem here is that the Census API requires a street address, so it will not work with town names alone.
Another way is to use the Google Maps API, which ggmap
facilitates. It does accept town/state combos without a street address, and if you call geocode(..., output = 'all')
, county is one of the bits of information you get back.
Sounds promising, but this approach has two problems for my use case. One is that hitting the Google Maps API costs money, at least after a subsidized trial period, and my nonprofit research program runs on a tight budget.
The second is that the output returned when you run geocode(..., output = 'all')
is a byzantine mess of nested lists whose structure varies across inputs, so it's really difficult to extract the desired bits into a flat data frame structure, which is what I need for my Shiny app (see my Stack Overflow question on this aspect here).
So, I'm still looking for something in that sweet spot of reliable, efficient---our data has tens of thousands of records to geocode on a weekly basis---and affordable. Is there something I'm overlooking?