How do I convert from Census FIPS to Lat Lon?

主宰稳场 提交于 2019-12-06 00:40:13

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!