4

I am looking for a way to gather the political areas (ie FIPS codes) from a latitude and longitude coordinate.

For example, if I were to input the coordinates: 47.66955, -122.31259 (Downtown Seattle), I would expect to get the following FIPS codes:

Place (aka "City"):

name: Seattle

FIPS: 53_63000

County:

name: King County

FIPS: 53_033

State:

name: Washington

FIPS: 53

Ideally, this could also include the census block, but at the very least, I need to return the State, County, and Place (aka "city") for a given coordinate.

I also understand that not all coordinates will map to a city/county/state, and that's ok.

Is there a library or machine image that I can deploy to solve this problem? Or perhaps a service (paid or otherwise) that I can use in production?


I have been researching this problem, and I found some interesting solutions. But none of them are working for me, as described below:

ESRI service at tigerweb.geo.census.gov It looks like there was a similar question here, but the service in the answer to the question is down. If I'm going to use a service, I'd like to see an SLA (I wouldn't mind paying for a service), or have a way to deploy it myself.

Data Science Toolkit Also, I found this project which solves my problem: http://www.datasciencetoolkit.org/developerdocs#coordinates2politics but it doesn't appear to be working and is not maintained. First, it's not a service - I have to deploy it myself to rely on it in production. And when I tried deploying it myself using their recommended AMI, the coordinates2politics endpoint was down, as described in this issue: https://github.com/petewarden/dstk/issues/66

data.fcc.gov I also found this service to be helpful: http://data.fcc.gov/api/block/2010/find?format=json&latitude=47.66955&longitude=-122.31259&showall=true

but it doesn't have an SLA ,and it doesn't return any Places

Any other suggestions or tips would be very helpful.

NOTE: SLA stands for Service Level Agreement: https://en.wikipedia.org/wiki/Service-level_agreement (ie "99.5% uptime")

  • 1
    What does SLA stand for? – whyzar Sep 28 '17 at 18:59
  • 1
    Service Level Agreement: en.wikipedia.org/wiki/Service-level_agreement For example, if I'm using a third party API, in their SLA they can specify an uptime of at least 99.5%. I'll clarify this term in the question – modulitos Sep 28 '17 at 19:02
3

I'm aware of the Census Bureau Geocoder that provides a return of the FIPS and Geographic Areas that you are interest.

You could read up more on the tool here as well

enter image description here

There is also a github page Latitude/Longitude to FIPS Codes via the FCC's API That may be helpful.

   # FCC's Census Block Conversions API   
   # http://www.fcc.gov/developers/census-block-conversions-api  
   latlong2fips <- function(latitude, longitude) {  
   url <- "http://data.fcc.gov/api/block/find? 
   format=json&latitude=%f&longitude=%f"  
   url <- sprintf(url, latitude, longitude)  
   json <- RCurl::getURL(url)  
   json <- RJSONIO::fromJSON(json)  
   as.character(json$County['FIPS'])  

}

   # Orange County  
   latlong2fips(latitude=28.35975, longitude=-81.421988)  

A third option may be to look into Pitney Bowes US Address Fabric

Each address location contains a latitude and longitude coordinate pair so that it can be sited on a map and used in location analysis. The US Address Fabric adds the full Federal Information Processing Standard (FIPS) code to allow Census level demographics to be attached automatically. A location “accuracy” code provides a confidence level as to the positional accuracy of each data point.

You could always try using an approach that includes as you suggested in the comments.

  • Download shapefiles for US States/Counties/Places from here
  • Then I can import the shape files into PostGIS using shp2pgsql,
  • Then I can perform a point in polygon query to return all FIPS locations that contain that point using ST_Contains.
  • Perhaps I'm using this wrong, but I tried entering the lat/long in my example above and I got the following error: status: Layer query encountered an error: java.lang.RuntimeException: Failed to return here is the url of my query: geocoding.geo.census.gov/geocoder/geographies/… – modulitos Sep 28 '17 at 19:14
  • I think your entering properly, let's see if it returns something correctly. I've tried the other options, e.g. address and it returned. I'm wondering what it may be as well? Let me see if I can find something. – whyzar Sep 28 '17 at 19:17
  • The FCC Api looks really interesting and useful, but is there a way for it to return Places (aka "cities") as well? Also, I don't know if the service is reliable enough for use in production - I haven't found an SLA. If needed, wouldn't mind deploying it myself either. – modulitos Sep 28 '17 at 19:23
  • Added a third option that may be the SLA type of your interest. – whyzar Sep 28 '17 at 19:30
  • Pitney Bowes doesn't offer much info about their service - it looks like I'd have to contact one of their sales people to learn more. I'm starting to consider rolling my own using shapefiles and PostGIS. Does that seem reasonable? It looks like I can download shapefiles for US States/Counties/Places from here: census.gov/geo/maps-data/data/cbf/cbf_place.html Then I can import the shape files into PostGIS using shp2pgsql, then I can perform a point in polygon query to return all FIPS locations that contain that point using ST_Contains. – modulitos Sep 28 '17 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.