Making Maps from OpenStreetMap Data

Aus Geoinformation HSR
Version vom 17. April 2014, 16:06 Uhr von HTan (Diskussion | Beiträge) (Step 3. Style data)

Wechseln zu: Navigation, Suche

See also OSM, OpenStreetMap-Daten zu Karten aufbereiten (german)

 >> Work in progress... <<

Overview

This is a how to/knowhow page about making own web maps from OpenStreetMap data.

  • If you are looking for making nice own base (or background) maps with own styling for print or web eventually within own region, and without programming skills - then this is the place to look for. Examples of personalized base maps are blind maps (maps without labels), the watercolor map from Stamen, OpenCycleMap among others.
  • If you are looking for making a thematic map on top of given base maps, use Maperitive or other services (see Geovisualisierung (german)). Examples of thematic maps is Wheelmap with infoboxes.
  • This is still work in progress. Our plan (see Team below) is to put everything in a single script file (tbd.).
  • See also Map Making Overview at OSM Wiki.

Use Case 'Vintage Map'

As a first use case we will show how to make a Vintage Maps from OpenStreetMap data.

tbd.

Your Use Case Here?

 If you have a nice map styling (preferrably in CartoCSS) 
 based on any 'map oriented' OSM database, 
 pls. contact us (see Team below)!

Cookbook

  • Software: tbd.
  • Data: tbd.
  • Hardware: tbd.

See workflow.

Some background: Making maps actually means in this context transforming a dataset to graphics. Before being styled (or rendered) the dataset is being preprocessed which ultimately would be a one-click process - but it's not yet since technology and user demands are changing fast.

At least, we can make life easeier when the intermediate dataset structure is has some known rules: See e.g. database schema below.

Workflow

Pls. note that this is still work in progress and thus experimental, suboptimal and at worst partially broken.

The workflow consists of followin steps:

  • Step 0. Prepare software and config data.
  • Step 1. Download, convert and clip OSM data. You can skip to step 2 and jump to step 3 "Style data" if you are in a hurry.
  • Step 2. Enhance and preprocess SQLite dataset.
  • Step 3. Style data.
  • Step 4. Publish map.

As said before, our goal is to wrap step 1 and 2 into one single Python script.

Step 0. Prepare software and config data

  • Install software: OGR/Python, SpatiaLite, TileMill
  • Get config data, e.g. modified osmconf.ini
  • Prepare clip boundary (e.g. liechtenstein_schloss_bbox.geojson)
    • Search for the desired country boundary from OpenStreetMap and copy the Relation id
    • Open http://overpass-turbo.eu/ and insert the commands below with the desired Relation id
    • Export the data as geoJSON and open as layer in TileMill
 {type=relation}
 {id=...}
 <osm-script output="json">
 <id-query type="{type}" ref="{id}"/>
 <print mode="body"/>
 <recurse type="down"/>
 <print mode="skeleton"/>
 </osm-script>

Step 1. Download, convert and clip OSM data

  • Open command line shell (PBF file in, SQLite/SpatiaLite file out):
 > ogr2ogr -f "SQLite" liechtenstein.sqlite
   /vsicurl/http://download.geofabrik.de/europe/liechtenstein-latest.osm.pbf 
   -dsco SPATIALITE=YES -skipfailures -progress -overwrite 
   --config OSM_CONFIG_FILE osmconf.ini -gt 65536 
   -clipsrc liechtenstein_schloss_bbox.geojson -clipsrclayer OGRGeoJSON 
   -nlt PROMOTE_TO_MULTI

Open points:

  • Convert coordinates to Mercator?

Alternatives (not used further here; this does not mean they are unusable - in contrary! - but that the are just not considered for different reasons):

  • QGIS - reads PDF/OSM data with OGR (like we do here) but with default config and without preprocessing.
  • spatialite_osm_map (OSM import tool from Spatialite) - no config of own tag->attribute mapping, no clipping possible?
  • osm2pgsql - requires PostGIS which is cumbersome being another local server software.
  • osmosis - no tag->attribute mapping?

Step 2a. Enhance SQLite dataset

  • Enhance dataset by shuffling geo objects around (using Spatialite, SQLite file in/out)
  • Convert Polygons to Points and add them to points as POIs.
  • Eventually convert multilinestring to linestring (can TileMill/Mapnik and QGIS handle multilinestrings/multipolygons?).

Step 2b. Do some other preprocessing

  • use preprocessing tools (Python, SQLite file in/out)
  • line smoothing of streets
  • tbd.

Sources:

Ideas:

  • DB related
    • Tippfehler in Tag-Values korrigieren
    • Tags vereinheitlichen
  • Geometry related:
    • Generalisierung von Wald/Gewässer/Straßen

Step 3. Style data

  • Start TileMill
  • Making boundaries (like from buildings) to make a hand-made effect.
    • A ‘sketchy’ look to lines can be achieved by overlaying a number of line attachments with different smoothing values applied. By smoothing higher values, the lines are overlaid using the ‘multiply’ compositing operation. This make areas that overlap more appear darker.
 ::outline1, ::outline2, ::outline3, ::outline4 {
   line-join: round;
   line-color:#773d00;
   line-smooth: 0.05; 
   line-width: 0.5;
 }
 ::outline1{ line-smooth: 0.04; }
 ::outline2{ line-smooth: 0.06; }
 ::outline3{ line-smooth: 0.08; }
 ::outline4{ line-smooth: 0.10; }
 
  • Using a specific font which is unavailable in TileMill
    • Create a directory to load fonts from in addition to the system directories
    • Set up font sets for various weights and styles.
    • Some suitable fonts/typefaces for a vintage pirate style are Aquiline and Mutlu
 Map { font-directory: url(./fonts); } 
 @piratefont: "Aquiline","Mutlu","French Script MT Regular";

Sources:

Step 4. Publish map

Database Schema

Table names and name rules (schema):

  • osm_points
  • osm_lines
  • osm_polygons
  • osm_roads, osm_roads_gen0, ...
  • osm_pois
  • osm_boundaries (osm_boundaries_gen0, osm_boundaries_gen1, ...)

Table names follow the schema "<prefix>_<name>_<postfix>" e.g. for zoom levels:

  • 0-10 => <name>_gen0
  • 11-14 => <name>_gen1
  • >= 12 => <name>

Notes

See also Diskussion:Making Maps from OpenStreetMap Data.

Team