【发布时间】: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