簡體   English   中英

如何使用 GeoPandas/Geo-Python/GIS 進行最近鄰分析?

[英]How to do Nearest Neighbour Analysis using GeoPandas/Geo-Python/GIS?

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

我收到此錯誤:

('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 文件。 我無法弄清楚這個錯誤。

你有沒有按照字面的代碼,

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

那么問題很可能是src_column - function 返回列src_column參數的值,該參數由示例代碼給出值id 如果您遇到列id的問題,很可能您沒有具有此類名稱的列,應提供數據集中現有列的名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM