问题
I'm trying to learn some skills in programming (python) by plotting out/manipulating public data sets. Currently, I'm trying to make an interactive population map of the Arctic. I downloaded Alaskan census data from the Alaskan State Department of Labor which gave me population divided by census tract in FIPS (i.e. 0201301090 is Akutan City in the Aleutians East Borough). Is there a way to convert FIPS to Lat Lon or plot by FIPS in python?
回答1:
The FIPS code for places in your example (the 01090 part) is in a style (FIPS 55.3) that was retired long ago by the Census Bureau, so finding a good data source was kind of tricky. I tried a bunch of fancy GIS libraries and lots of big shp files from the Census Bureau, but although you can get pretty close with Census Blocks and Tracts, none of them had enough data to trace down the place FIPS.
However, I eventually found that the US Board on Geographic Names has a useful database here that still uses this format.
If you download the Alaska file from the "State Files with Federal Codes" section on the bottom of that page, it's pretty easy to parse the necessary information with just python's built-in csv reader.
import csv
datapath = r"C:\folder\where\you\saved\the\file\AK_FedCodes_20170201.txt"
data = []
with open(datapath) as f:
reader = csv.reader(f, delimiter="|")
rows = [row for row in reader]
for row in rows[1:]:
name = row[1]
fips = row[7]+row[10]+row[3]
lat = row[12]
lon = row[13]
data.append({"name": name,
"fips": fips,
"lat": lat,
"lon": lon})
if name == "Akutan":
print name, fips, lat, lon # just because we can
Output:
Akutan 0201301090 54.1355556 -165.7730556
来源:https://stackoverflow.com/questions/42868735/how-do-i-convert-from-census-fips-to-lat-lon