【问题标题】:How to find census tract from latitude and longitude in python如何在python中从经纬度查找人口普查区
【发布时间】:2021-03-07 00:44:46
【问题描述】:

我有两个要合并的数据集,以根据经度和纬度查找人口普查区

我使用的第一个数据集是纽约市 Airbnb 开放数据,其经纬度列如下所示。

latitude    longitude   
40.64749    -73.97237
40.75362    -73.98377
40.80902    -73.94190
40.68514    -73.95976
40.79851    -73.94399

我使用的第二个数据集包含纽约坐标的人口普查块代码。

Latitude    Longitude   BlockCode   
40.48   -74.280000  340230076002012 
40.48   -74.276834  340230076005000 
40.48   -74.273668  340230076003018 
40.48   -74.270503  340230076003004 
40.48   -74.267337  340230074021000

我首先尝试计算纬度和经度的 single_pt_haversine(假设距离点具有坐标 (0,0))。然后,我在single_pt_havesine上内联了两个数据集,数据集之间没有匹配。然后我将 single_pt_havesine 四舍五入到小数点后 3 位,列中有一些匹配项,但只返回了大约 300 行(在第一个数据集中的 48895 行中)。

有没有更好的方法?或者也许是一个包来从 Python 中的坐标确定人口普查区?

【问题讨论】:

    标签: python census


    【解决方案1】:

    我认为 Python 包 censusgeocode 应该足以满足您的情况。所以你可以试试:

    import censusgeocode as cg 
    result = cg.coordinates(x=lng, y=lat)
    

    更多文档在这里:https://pypi.org/project/censusgeocode/

    【讨论】:

    • 将答案转换为评论:- 我认为应该是 cg.coordinates 而不是 cg.coordinate
    猜你喜欢
    • 2010-09-07
    • 2010-09-07
    • 1970-01-01
    • 2013-10-30
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    相关资源
    最近更新 更多