I am using OSM Water Layer raster where oceans (1), large lake/river (2), major river (3), canal (4) and stream (5) are mapped. I have a point defined by its lon/lat pair and I would like to compute the distance from that point to the nearest of each water body (ocean, large river, river, canal and stream).
I have tried multiple options in python, however, noone of them gave me a correct result. Could somebody provide suggestion on how to conduct the analysis?
Not a lot of info to go on, but this script shows how to find the closest the closest water body for a point based on some test data.
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