计算到最近水体的距离

问题描述 投票:0回答:1

我正在使用 OSM Water Layer 栅格,其中绘制了海洋 (1)、大湖泊/河流 (2)、主要河流 (3)、运河 (4) 和溪流 (5)。我有一个由经度/纬度对定义的点,我想计算从该点到每个水体(海洋、大河、河流、运河和溪流)最近的距离。

我在Python中尝试了多个选项,但是,没有一个给我正确的结果。有人可以提供有关如何进行分析的建议吗?

python spatial geopandas qgis rasterio
1个回答
0
投票

没有太多信息可以继续,但此脚本展示了如何根据一些测试数据找到某个点最近的最近的水体。

import geopandas as gpd
from shapely import box, Point

waterbodies = gpd.GeoDataFrame(
    data={
        "name": ["river1", "lake1"],
        "geometry": [box(0, 0, 10, 1), box(5, 5, 10, 10)],
    }
)

poi = Point(0, 7)

# Get the nearest water body. If there are multiple ones at the same distance, the first
# returned one is taken.
nearest_water = waterbodies.iloc[[waterbodies.sindex.nearest(poi)[1][0]]].copy()

# Calculate the actual distance of this nearest water body
nearest_water["distance"] = nearest_water.distance(poi)

print(nearest_water)
#    name                                           geometry  distance
# 1  lake1  POLYGON ((10.00000 5.00000, 10.00000 10.00000,...       5.0
© www.soinside.com 2019 - 2024. All rights reserved.