to answer what is where on the Earth’s surface GIS data is typically stored in a Spatial Database A spatial database defines special data types for geometric objects (e. g., polygons) allows to save geometric data in regular (relational) databases provides special functions and indexes for querying and manupulating spatial data Michael Rüegg (IFS) Route Planning with FOSS November, 2012 4 / 40
get from a round world to a flat map? ⇒ Map projections: portray Earth’s curved to a flat surface Spatial Reference System (SRS) European Petrolueum Survey Group Geodesy (EPSG) Geodesy is the study of the shape of the Earth WGS84: The World Geodetic System is a standard for use in cartography, geodesy and navigation CHLV03: The coordinate system for Switzerland Michael Rüegg (IFS) Route Planning with FOSS November, 2012 5 / 40
A GIS allows to work in various levels and their proper representations ⇒ Goal: Combination of data to get new information Figure: http://www.digital-geography.com/concept-of-layers-in-a-gis Michael Rüegg (IFS) Route Planning with FOSS November, 2012 6 / 40
file Raster vs. vector formats Common vector formats: Drawing Interchange Format (DXF): CAD data file format developed by Autodesk ESRI Shapefile: popular geospatial vector data format from Environmental Systems Research Institute (ESRI) Keyhole Markup Language (KML): XML dialect for expressing geographic visualization within two-dimensional maps and three-dimensional Earth browsers Spatialite: free GIS that enables spatial queries and objects for SQLite Michael Rüegg (IFS) Route Planning with FOSS November, 2012 7 / 40
in a GIS How can we store and represent geographic features in a database? ⇒ Simple Feature for SQL (SFS) Model Storage model for geographical data using well-known text (WKT) Basic geometric data types: points, linestrings, polygons Figure: Source Wikipedia Michael Rüegg (IFS) Route Planning with FOSS November, 2012 8 / 40
determining the spatial relationships between geometric objects Figure: Source Wikipedia Michael Rüegg (IFS) Route Planning with FOSS November, 2012 11 / 40
queries Spatial order structure: What is spatially close together should also be close in memory Figure: R-Tree example Michael Rüegg (IFS) Route Planning with FOSS November, 2012 12 / 40
server Implements the SFS model Open Source (GNU General Public License) Data loaders (e. g., ESRI shape files) >330 geometric functions: distance, area, union, intersection, etc. Latest release is 2.0.1 (June 2012) Michael Rüegg (IFS) Route Planning with FOSS November, 2012 14 / 40
object (x,y): SELECT ST_Point(1, 3) AS ExamplePoint; No spatial reference system used (default is Cartesian grid). Let’s use WGS84: SELECT ST_SetSRID(ST_Point(8.515342,47.389058), 4326); The same can be done by using WKT: SELECT ST_GeomFromText(’POINT(8.515342,47.389058)’, 4326); The same for LineStrings and Polygons: SELECT ST_GeomFromText(’LINESTRING(1 1,2 2,3 3)’) AS MyLine; SELECT ST_GeomFromText(’POLYGON((0 1,1 -1,-1 -1,0 1))’) As MyTriangle; Michael Rüegg (IFS) Route Planning with FOSS November, 2012 17 / 40
)::numeric, 0) AS "distance" FROM beers ORDER BY distance; "Biergarten"; 3.5; 235 "Dorflade"; 2.4; 300 "Nelson Pub"; 4.5; 381 "Manor"; 1.15;422 "Coop Sunnehof";1.05;706 Note that we must convert the point to EPSG 4326! ST_Distance_Sphere: Returns minimum distance in meters between two lon/lat geometries float ST_Distance_Sphere(geometry lonlatA,geometry lonlatB) Michael Rüegg (IFS) Route Planning with FOSS November, 2012 20 / 40
Topological data structure with four data types: Nodes are points with a geographic position, stored as WGS84 coordinates (e. g. POIs) Ways are ordered node lists representing a polyline (e. g. streets, rivers, parks) Tags are used to store metadata about the map objects Relations are used for representing the relationship of existing nodes and ways (e. g. turn restrictions on roads) OpenStreetMap data: www.geofabrik.de OSM data for Switzerland in PBF Format (Protocolbuffer Binary Format): download.geofabrik.de/osm/ europe/switzerland.osm.pbf Michael Rüegg (IFS) Route Planning with FOSS November, 2012 22 / 40
converts OSM data to PostgreSQL databases osm2pgsql is a lossy conversion utility Two main modes of running: normal and slim mode Normal mode uses memory for intermedia storage Slim mode uses 3 on-disk tracking tables: planet_osm_nodes, planet_osm_ways, planet_osm_rels Michael Rüegg (IFS) Route Planning with FOSS November, 2012 23 / 40
\ --database <DB_NAME> --prefix osm --style \ /usr/local/share/osm2pgsql/xyz.style \ --username <DB_USER> --port <DB_PORT> \ --hstore-all --input-reader pbf \ --extra-attributes switzerland.osm.pbf -hstore: Generate a hstore (key/value) column By using hstore we can use any tag in SQL queries: gis_db=> SELECT COUNT(*) FROM planet_osm_point WHERE ((tags->’man_made’) = ’tower’); osm2pgsql overwrites the tables and create them fresh by default (use -append instead if necessary) Michael Rüegg (IFS) Route Planning with FOSS November, 2012 24 / 40
variant to compute shortest path, but Contraction Hierarchies (CH) Written in C++, available under the GNU license Michael Rüegg (IFS) Route Planning with FOSS November, 2012 26 / 40
information irrelevant to routing OSM data needs to be normalized before being processed This is done by the OSRM tool named extractor Parses the content of the OSM file and writes: A .osrm file containing the routing data A .osrm.restrictions file containing the restrictions to make certain turns during navigation A .osrm.names file which contains the road names Let’s execute it: $ ./osrm-extract switzerland.pbf Michael Rüegg (IFS) Route Planning with FOSS November, 2012 30 / 40
able to handle bzip2 compressed files as well as PBF files External memory accesses are handles by the stxxl library stxxl must be configured in a file .stxxl File format: disk=full_disk_filename,capacity,access_method Example: disk=/tmp/stxxl,25000,syscall Michael Rüegg (IFS) Route Planning with FOSS November, 2012 31 / 40
hierarchy (the precomputed data that enables OSRM to find the shortest path extermly fast), type: $ ./osrm-prepare switzerland.osrm \ switzerland.osrm.restrictions Nearest-neighbor data structure and node map are created Afterwards, 4 files should exist: map.osrm.hsgr (the hierarchy) map.osrm.nodes (the nodemap) map.osrm.ramIndex (stage 1 index) map.osrm.fileIndex (stage 2 index) To run the engine, just type: ./osrm-routed Michael Rüegg (IFS) Route Planning with FOSS November, 2012 32 / 40
coordinate nearest: Location of nearest point on any street segment for a given coordinate viaroute: Computation of shortest path between two coordinates given an ordered list of via points Query format: http://server:5000/_service_?param1=value&...¶mX=value Example (from here to Zürich Mainstation): $ curl "server:5000/viaroute?loc=47.389058,\ > 8.515342&loc=47.378188,8.539204" | python -mjson.tool { "version": 0.3,"status":0,"status_message": "Found route between points","route_geometry": ["4","Duttweilerstrasse",239,4,17,"239m","NE",38], ["2","Foerrlibuckstrasse",363,7,27,"363m","E",84], "route_summary":{"total_distance":3220,"total_time":237,... Michael Rüegg (IFS) Route Planning with FOSS November, 2012 33 / 40
in web browsers (no server-side dependencies) Most popular open source software web-mapping client Ability to overlay proprietary non-OGC-compliant mapping layers with OGC WMS, WFS and WFS-T layers Various controls to build custom toolbars, menus and widgets for editing the map Michael Rüegg (IFS) Route Planning with FOSS November, 2012 35 / 40
map = new OpenLayers.Map(’map’, { controls: [ new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.LayerSwitcher({’ascending’:false}), new OpenLayers.Control.Permalink(), new OpenLayers.Control.ScaleLine(), new OpenLayers.Control.Permalink(’permalink’), new OpenLayers.Control.MousePosition(), new OpenLayers.Control.OverviewMap(), new OpenLayers.Control.KeyboardDefaults()], numZoomLevels: 6 }); map.addLayer(new OpenLayers.Layer.Google("Google Hybrid", { type : google.maps.MapTypeId.HYBRID, numZoomLevels : 20 })); var position = new OpenLayers.LonLat(lon, lat).transform(fromProjection, toProjection); var markers = new OpenLayers.Layer.Markers("Markers"); map.addLayer(markers); markers.addMarker(new OpenLayers.Marker(position)); } </script> Michael Rüegg (IFS) Route Planning with FOSS November, 2012 36 / 40
developed at University of Applied Sciences Rapperswil Travelling Salesman Problem (TSP) Uses PostGIS, OSM data, osm2pgsql, OSRM and OpenLayers Available at www.tourpl.ch ⇒ Demonstration Michael Rüegg (IFS) Route Planning with FOSS November, 2012 38 / 40
in Action. Manning, 2011 Stefan Keller Unterrichtsmaterialien “Geodatenbanksysteme”. University of Applied Sciences Rapperswil, 2012 Dennis Luxen OSRM Wiki. https: //github.com/DennisOSRM/Project-OSRM/wiki Michael Rüegg (IFS) Route Planning with FOSS November, 2012 40 / 40