我有一个地理数据框,其中包含约25个点几何表示的位置。我正在尝试编写一个脚本,遍历每个点,识别最近的位置,并返回最近位置的名称和距离。
如果我有不同的地理数据框,可以轻松使用shapely.ops库中的nearest_points(geom1, geom2)完成此操作。然而,我所有的位置都存储在一个地理数据框中。我正试图进行循环,这就是我遇到问题的地方。
以下是我的示例文件:
如果我有不同的地理数据框,可以轻松使用shapely.ops库中的nearest_points(geom1, geom2)完成此操作。然而,我所有的位置都存储在一个地理数据框中。我正试图进行循环,这就是我遇到问题的地方。
以下是我的示例文件:
geofile = gpd.GeoDataFrame([[0, 'location A', Point(55, 55)],
[1, 'location B', Point(66, 66)],
[2, 'Location C', Point(99, 99)],
[3, 'Location D', Point(11, 11)]],
columns=['ID','Location','geometry'])
这是我创建但无法正常运行的循环。
for index, row in geofile.iterrows():
nearest_geoms=nearest_points(row, geofile)
print('location:' + nearest_geoms[0])
print('nearest:' + nearest_geoms[1])
print('-------')
我遇到了这个错误:
AttributeError: 'Series' object has no attribute '_geom'
然而,我认为我的问题超出了错误的原因,因为我必须排除我正在循环遍历的行,因为那将自动返回最接近的位置,因为它就是那个位置。
对于一个位置,我的最终结果如下:
([0,'location A','location B', '5 miles', Point(55,55)], columns=['ID','Location','Nearest', 'Distance',geometry'])
MultiPoint(list(df["geometry"]))
(从shapely.geometry
导入) - undefined