0

I am trying to transform CSV files of lat long into FIPS codes. Does any one have a Python code that is able to do this? I have that worked then stopped working giving me an 'http 400 bad request' output.

  • Hi John, one approach would be to geocode the lat long coordinates and perform a spatial join with FIPS shapefiles to get their corresponding FIPS code. – NULL.Dude Aug 31 '18 at 17:27
  • hi, thanks for your comment. How would I go about this? I only have a csv files with the lat long. – john jones Aug 31 '18 at 17:38
  • 1
    Hi John, welcome to GIS.SE! Could you expand a little bit on what you tried, and resulted in the "http 400 bad request"? Also, if you're using any specific modules in python, it might be good to list some of those out. – evv_gis Aug 31 '18 at 17:59
2

There is an API through the FCC that will return information about a census block from lat/lon coordinates. https://geo.fcc.gov/api/census/#!/block/get_block_find

The format of the request URL is as such:

https://geo.fcc.gov/api/census/block/find?latitude=40&longitude=-75&format=json

import requests
import urllib

#Sample latitude and longitudes
lat = 40
lon = -75

#Encode parameters 
params = urllib.urlencode({'latitude': lat, 'longitude':lon, 'format':'json'})
#Contruct request URL
url = 'https://geo.fcc.gov/api/census/block/find?' + params

#Get response from API
response = requests.get(url)

#Parse json in response
data = response.json()

#Print FIPS code
print data['County']['FIPS']

This example returns the county FIPS code. The request will return FIPS data about the county, state, and census block, so it depends on which level you are interested in.

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.