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, 2018 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, 2018 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, 2018 at 17:59

2 Answers 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:


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.

  • Worked for me... took about a minute to process 100 coordinates. Thank you
    – f.thorpe
    Jul 7, 2020 at 20:16
  • This seems to rely on FIPS definitions under current FIPS categories? But FIPS codes have been occasionally merged, renamed, recoded, split. How can I use 1990 version of FIPS for this purpose? May 8, 2022 at 23:41

The fcc API is unavailable as today. A good option is geo census. For example: geocoding.geo.census.gov/geocoder/geographies/coordinates?x=-82.630303&y=34.537094&benchmark=4&vintage=423

Python code:

URL = f"https://geocoding.geo.census.gov/geocoder/geographies/coordinates?x={lng}&y={lat}&benchmark=4&vintage=423&format=json"
response = requests.get(URL).json()
county_data = response["result"]["geographies"]["Counties"][0]
fip_code = str(county_data["STATE"]) + str(county_data["COUNTY"])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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