Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using OSM data The technical details.... Using OSM data Extracting data from planet.osm Setting up a PostGIS database Importing data into a PostGIS database.

Similar presentations


Presentation on theme: "Using OSM data The technical details.... Using OSM data Extracting data from planet.osm Setting up a PostGIS database Importing data into a PostGIS database."— Presentation transcript:

1 Using OSM data The technical details...

2 Using OSM data Extracting data from planet.osm Setting up a PostGIS database Importing data into a PostGIS database Rendering map data with Mapnik Using OpenLayers to create an OSM-based website

3 Extracting data from planet.osm Download a planet.osm extract from a server e.g. geofabrik.de  Planet extracts available from download.geofabrik.de/osm Use Osmosis to extract the data  Available from wiki.openstreetmap.org/index.php/Osmosis

4 Using Osmosis There is a good chance that we are only interested in certain OSM data For example, if we wish to create a map for walkers, we might only want to use countryside data Osmosis allows you to extract the data you want only

5 Osmosis Osmosis allows you to: Extract data by bounding box Extract all nodes or ways containing a particular key, or key/value pair Write OSM data to a MySQL or PostGIS database Read OSM data from a database and write to an OSM data file

6 Osmosis Example of Osmosis commands: osmosis --rx file=uk.osm -–bounding-box top=52 bottom=50 left=-2 right=-0 –-wx file=southern_england.osm This extracts a bounding box from uk.osm and saves it as southern_england.osm. osmosis –-rx file=uk.osm -–tf reject-ways –-tf accept-nodes place=* --wx file=ukplaces.osm This filters out all ways, and accepts those nodes with a ‘place’ tag, and writes to ukplaces.osm.

7 General principles of Osmosis Has a set of commands specified as command-line options e.g. --rx (read XML); --tf (tag filter) Commands typically filter the input stream So the following command : osmosis –-rx file=uk.osm -–tf reject-ways -–tf accept-nodes place=* --tf accept-nodes amenity=* --wx file=output.osm will only give nodes with both a place tag and an amenity tag If we want nodes with either a place tag or an amenity tag we must use named pipes and stream merging, see the Osmosis page for details

8 Setting up an OSM database You may wish to set up your own copy of the OSM database e.g. for rendering maps, or developing a web service of some kind Typically, a PostgreSQL / PostGIS database is used for this OSM data is imported into two tables planet_osm_point and planet_osm_line

9 Setting up PostgreSQL/PostGIS PostgreSQL and PostGIS normally available as packages for Linux distributions Installation fairly straightforward on current Ubuntu or Debian distributions Detailed installation instructions available at wiki.openstreetmap.org/index.php/Mapnik/PostGIS

10 Importing OSM data Having set up the PostGIS database we need to import OSM data into it A custom tool, osm2pgsql, is used for this This can be downloaded from OSM's subversion repository osm2pgsql allows us to control which map features are imported (by tag) See the osm2pgsql wiki page: http://wiki.openstreetmap.org/index.php/Osm2pgsql

11 Mapnik To create our own maps we can use the Mapnik library (www.mapnik.org)www.mapnik.org C++ library with Python wrapper which allows easy creation of high-quality maps Source available from mapnik.org Binary packages available for Debian, Ubuntu, OS X, Windows Main dependency: Boost C++ libraries For installation details see: trac.mapnik.org/wiki/MapnikInstallation

12 Using Mapnik Mapnik is a library, not an application So to create maps with Mapnik, we have to write our own application (C++, Python) or use a pre-built Mapnik-based application Examples of pre-built applications:  mod_tile – Apache module to render tiles from PostGIS using Mapnik  generate_tiles.py – Python script to generate tiles at different zoom levels from a PostGIS database

13 Configuring Mapnik Mapnik styles are configurable with an XML file Basic units are styles, rules and layers Each broad class of feature (e.g. road, path, natural vegetation, landuse) is defined within a tag Within that, we define a series of s to match various tagging patterns We then set the colour, font, etc of each Finally we define s, each of which can contain several s

14 Example of Mapnik XML Style/Rule [natural] = 'wood' or [landuse] = 'wood' #aed1a0 [natural] = 'heath' #ffffc0

15 Example of Mapnik XML Layer paths (select way,highway from planet_osm_line where highway in ('path','footway','bridleway','cycleway') order by z_order) as roads postgis localhost 5432 gis Note how we link in a (paths) and specify the SQL to retrieve all objects in that layer

16 A word on the OSM tiling system OSM based sites normally use the “Google” tiling system Principle is: - At the highest zoom level, the entire world is shown on a 256x256 tile - Each subsequent zoom level zooms in by a factor of 2 - So, for example, zoom level 1 requires 4 tiles for the whole world (NW, NE, SW, SE quadrants), zoom level 2 requires 16, etc. See wiki.openstreetmap.org/wiki/ Slippy_map_tilenames

17 How to produce tiles generate_tiles.py script available from OSM Subversion repository (http://svn.openstreetmap.org/applications/rendering/mapnik/) This will pre-generate OSM map tiles from a postgis database Can configure bounding box and zoom levels Alternatively use mod_tile Apache module for live generation and caching of tiles from an OSM PostGIS database

18 Producing your own “slippy map” Having created your tiles, you need to use them in a web application Use the open-source OpenLayers JavaScript API (www.openlayers.org) An open source alternative to Google Maps, etc. See www.free- map.org.uk/course/osm/openlayers.xhtml to get started


Download ppt "Using OSM data The technical details.... Using OSM data Extracting data from planet.osm Setting up a PostGIS database Importing data into a PostGIS database."

Similar presentations


Ads by Google