Skip to content

Instantly share code, notes, and snippets.

@amandasaurus
Created Oct 24, 2021
Embed
What would you like to do?
convert OSM ways into long skinny skeletons with ST_Approxipat
#! /bin/bash
# Purpose of this is to try to convert long skinny rivers like
# https://www.openstreetmap.org/way/119339404#map=17/16.32108/-61.77254 into
# regular OSM ways
#
# This code is licenced Affero GPL v3+
#
# Alas, this does not appear to work very well, with the new OSM ways being
# very disconnected and disjoined. This should be viewed as an experiment, and
# not a way to generate OSM geometric data
set -o errexit -o pipefail
wget -N http://download.geofabrik.de/central-america-latest.osm.pbf
if [ central-america-latest.osm.pbf -nt guadeloupe.osm.pbf ] ; then
osmium extract --overwrite central-america-latest.osm.pbf -o guadeloupe.osm.pbf --bbox -62.061768,15.686510,-60.600586,16.694079
fi
osmium tags-filter guadeloupe.osm.pbf --overwrite -o guadeloupe-water.osm.pbf a/waterway=riverbank
osm2pgsql --latlon --hstore-all --drop -p waterway_riverbank_area guadeloupe-water.osm.pbf
psql -c "CREATE EXTENSION postgis_sfcgal;"
pgsql2shp -f spines.shp "select tags->'waterway', ST_ApproximateMedialAxis(way) from waterway_riverbank_area_polygon"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment