enu-sav / minimap-creator

3 stars 0 forks source link

Minimap Creator

Minimap Creator is a HTTP server for creating minimaps.

Preparation

  1. clone the project
  2. Run PsotGIS:
    docker run --name minimap-postgis -p 5455:5432 -e POSTGRES_PASSWORD=snakeoil -e POSTGRES_HOST_AUTH_METHOD=trust --shm-size=1g -d postgis/postgis
  3. download map data sql and import it to PostGIS:
    
    pigz -cd dump.sql.gz | psql -h localhost -p 5455 -U postgres
  4. save hillshading data as data/hillshading-world.tif
  5. install dependencies
    npm i
  6. build the project
    npm run build
  7. start the server
    PORT=8080 npm start

Map generation

Query parameters, all are optional:

Generated map must be enclosed with the following attribution: OpenStreetMap contributors (ODbL 1.0)

Examples

Highlight administrative area and show a marker:

curl 'http://localhost:8080?features=borders,landcover,roads&placeId=522422&country=sk&width=1200&scale=1&margin=20&minor-borders=hu:4,uk:4,at:4,pl:4,sk:4,cz:4&micro-borders=sk:8&place-types=city,town&highlight-admin-area=Ko%C5%A1ick%C3%BD%20kraj&hillshading-opacity=0.5&lat=48.700142&lon=20.891184' | display

Slovakia, Košický región

Watershed Hornád:

RIVER=hornad

curl "http://localhost:8080?features=borders,landcover,scale&width=1200&scale=2&place-size-factor=0.8&margin=20&place-types=city,town&hillshading-opacity=0.5&watershed-name=$RIVER&bbox="`ogrinfo -sql "select st_transform(st_envelope(st_union(geometry)), 4326) from watershed_$RIVER" data/watershed_$RIVER.sqlite watershed_$RIVER | grep Extent | sed -e 's/[^0-9\.]\{1,\}/,/g' | sed -e 's/^.\|.$//g'` | display

Hornád watershed

Notes

Preparing map data

  1. Obtain latest planet.osm.pbf from planet.openstreetmap.org.
  2. Import the data:
    imposm import -connection postgis://minimap:minimap@localhost/minimap -mapping mapping.yaml -read planet.osm.pbf -write -overwritecache
    imposm import -connection postgis://minimap:minimap@localhost/minimap -mapping mapping.yaml -deployproduction
  3. Process the data in PostGIS:
    psql -h localhost minimap minimap < process.sql
  4. download simplified land polygons and convert it to PosgGIS SQL.
  5. Import simplified_land_polygons.sql to PosgGIS:
    psql -h localhost minimap minimap < simplified_land_polygons.sql
  6. Dump the data:
    pg_dump -h localhost -U minimap -t simplified_land_polygons -t osm_admin_rels -t border_lines -t admin_borders -t osm_places -t roads -t landcover minimap | pigz > dump.sql.gz
  7. Run dockerized PostGIS:
    docker run --name minimap-postgis -p 5455:5432 -e POSTGRES_PASSWORD=snakeoil -e POSTGRES_HOST_AUTH_METHOD=trust --shm-size=1g -d postgis/postgis
  8. Load data to dockerized PostGIS:
    pigz -cd dump.sql | psql -h localhost -p 5455 -U postgres

    Watershed

Download geopackage(s) from https://land.copernicus.eu/imagery-in-situ/eu-hydro/eu-hydro-river-network-database?tab=download (for example EU-Hydro-Danube-GeoPackage)

Extract waterways of a watershed for a particular river - find its first and last segment object_id and also for its parent.

scripts/gen_waterways.sh danube hornad RL35142907 RL35137645 RL35137675 RL35136997

Make watershed polygon (QGIS):

  1. Clip
  2. FlowAccumulationFullWorkflow
  3. ExtractStreams (100000)
  4. add point to sink
  5. Watershed
  6. Polygonize (gdal)
  7. SmoothVectors (10)
  8. Simplify (10)
  9. export to data/watershed_{name}.sqlite
SELECT load_extension('mod_spatialite');
delete from admin_areas where ogc_fid = 785489; -- find ID of border making Krym Russian
insert into admin_areas select null, 1 as osm_id, name as name, name_sk, admin_level, country_code, st_union(geometry) as geometry from admin_areas where country_code = 'UA' and admin_level = 2 group by country_code;
delete from admin_areas where country_code = 'UA' and admin_level = 2 and osm_id <> 1;

More resources / ideas