[GIS] Finding State, County, Place, and Census Block FIPS codes from a coordinate (latitude and longitude)

coordinate systemfipspointpoint-in-polygonspatial-query

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")

Best Answer

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.