srai icon indicating copy to clipboard operation
srai copied to clipboard

OSMPbfLoader returns data out of the given area

Open Calychas opened this issue 1 year ago • 2 comments

OSMPbfLoader returns data partially out of the given area (not clipped to the area). Maybe consider a mode parameter to set the correct behaviour or just document the behaviour. Copy the snippet below to see:

from srai.regionalizers import geocode_to_region_gdf
from srai.loaders import OSMPbfLoader
from srai.loaders.osm_loaders.filters import GEOFABRIK_LAYERS

area = geocode_to_region_gdf( "Basel, Switzerland")
area.plot(color="blue")
gdf = OSMPbfLoader().load(area, GEOFABRIK_LAYERS)
gdf.plot(color="black")

image

Workaround:

gdf.clip(area).plot()

image

Calychas avatar Aug 08 '23 19:08 Calychas

Might be worth looking into other loaders' behaviour

Calychas avatar Aug 08 '23 19:08 Calychas

This is actually by design, we just read the features from the OSM and don't alter their geometries at all. Looking at the example from the OSM Pbf Loader, I was clipping those features before plotting by hand.

We might add a parameter to force clipping before returning the data, but this operation alters original geometry of the OSM feature.

RaczeQ avatar Aug 08 '23 22:08 RaczeQ