【问题标题】:How to do Nearest Neighbour Analysis using GeoPandas/Geo-Python/GIS?如何使用 GeoPandas/Geo-Python/GIS 进行最近邻分析?
【发布时间】:2019-11-19 16:26:48
【问题描述】:

我正在关注本教程最近邻分析: https://automating-gis-processes.github.io/2017/lessons/L3/nearest-neighbour.html

我收到此错误:

('id', 'occurred at index 0')

在我运行这个之后:

def nearest (row, geom_union, df1, df2, geom1_col='geometry', geom2_col='geometry', src_column=None):
    # Find the nearest point and return the corresponding value from specified column.
    # Find the geometry that is closest
    nearest= df2[geom2_col] == nearest_points(row[geom1_col], geom_union)[1]
    #Get the corresponding value from df2 (matching is based on the geometry)
    value = df2[nearest][src_column].get_values()[0]
    return value

df1['nearest_id'] = df1.apply(nearest, geom_union=unary_union, df1=df1, df2=df2, geom1_col='centroid', src_column='id', axis=1)

为此,我使用自己的数据。它与示例中给出的类似。但我在 shp 文件中有地址、几何、纬度和经度。所以我没有使用 .kml 文件。我无法弄清楚这个错误。

【问题讨论】:

    标签: python pandas gis geospatial geopandas


    【解决方案1】:

    你是按照字面的代码来的吗,

    df1['nearest_id'] = df1.apply(最近的,geom_union=unary_union, df1=df1, df2=df2, geom1_col='质心', src_column='id',axis=1)

    那么问题很可能是src_column - 该函数返回列src_column 参数的值,该值由示例代码给出id。如果您对列 id 有疑问,很可能您没有具有此类名称的列,应提供数据集中现有列的名称。

    【讨论】:

    • 我并没有完全按照代码进行操作。我有不同的函数/变量/列名。为了在此处发布,我只是使用示例名称作为参考。但是,是的,你是对的,我的 src_column 拼写错误。这是一个非常简单的问题,我知道我是怎么错过的。感谢您的帮助。
    猜你喜欢
    • 2011-11-11
    • 1970-01-01
    • 2016-09-26
    • 2015-05-12
    • 2020-12-31
    • 1970-01-01
    • 2017-02-01
    • 2017-07-11
    • 2016-03-06
    相关资源
    最近更新 更多