2

I have a OSM file (http://download.geofabrik.de/europe/malta-latest.osm.pbf). I am only interested in data that are around ramps (motorway_link,trunk_link,primary_link,secondary_link,tertiary_link) as in the picture. Therefore I want to preprocess the data to keep the OSM file as small as possible. I use the osmium tool.

I want to do it as followed, but I do not know how to implement step 2:

  1. Filter pbf file by desired tags -> malta-ramps.osm.pbf
osmium tags-filter -v --overwrite -o malta-ramps.osm.pbf malta-latest.osm.pbf w/highway=motorway_link,trunk_link,primary_link,secondary_link,tertiary_link
  1. Create polygons around the filteres data -> malta-polygons.poly
How to create the buffered polygons around the ramps e.g. with python?
  1. Cut out the polygons from the original OSM file -> malta-finished.osm.pbf
osmium extract --overwrite -p malta-polygons.poly -o malta-finished.osm.pbf malta-latest.osm.pbf

enter image description here

1
  • 1
    here an approach: convert lines to GeoJSON ogr2ogr -f GeoJSON lines.geojson malta-ramps.osm.pbf lines - compute a buffer ogr2ogr -f GeoJSON buffer.geojson lines.gpkg -dialect sqlite -sql "select st_buffer(geom, 0.0001) from lines" NOTE the buffer distance is in degrees, which is quite hacky. To use metric distance you need to transform to a metric CRS like UTM. Then you might union the buffered polygons to prevent overlap. Finally convert the polygons to a format osmium understand as describe here osmcode.org/osmium-tool/… Nov 15, 2022 at 21:54

1 Answer 1

1

I solved it like this:

  1. Convert from pbf to geojson -> malta-ramps.geojson
    osmium export malta-ramps.osm.pbf -o malta-ramps.geojson -O

  2. Extract unioned polygons (for all geometries) -> malta-polygons.geojson
    ogr2ogr -f GeoJSON malta-polygons.geojson malta-ramps.geojson -dialect sqlite -sql "select st_union(st_buffer(geometry, 0.002)) from malta-ramps"

1
  • 1
    Keep in mind, that buffering with latitude/longitude is super hacky and might only work for your area of interest. It would be much cleaner to reproject your data to metric system (e.g.UTM) first. Something like: ogr2ogr -t_srs EPSG:32632 malta-ramps-utm.geojson malta-ramps.geojson , Union with st_buffer(geometry, 100) with 100 meters, convert it back to lat/lon ogr2ogr -t_srs EPSG:4326 final_result.geojson malta-ramps-buffer.geojson moreover, the shape of the result should be much more circular and less ellipse shaped Dec 3, 2022 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.