Skip to content

Instantly share code, notes, and snippets.

@nqbao
Forked from ramhiser/latlong2fips.r
Created June 29, 2016 09:43
Show Gist options
  • Save nqbao/b5c5a5f99b5c0e135b40b9c3667b774d to your computer and use it in GitHub Desktop.
Save nqbao/b5c5a5f99b5c0e135b40b9c3667b774d to your computer and use it in GitHub Desktop.
Latitude/Longitude to FIPS Codes via the FCC's API
# 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment