Académique Documents
Professionnel Documents
Culture Documents
Michael Regg
Institute For Software University of Applied Sciences Rapperswil
Outline
1
GIS 101 PostGIS OpenStreetMap Open Source Routing Machine OpenLayers Showcase: Tourpl
November, 2012
2 / 40
Outline
1
GIS 101 PostGIS OpenStreetMap Open Source Routing Machine OpenLayers Showcase: Tourpl
November, 2012
3 / 40
What is GIS?
GIS stands for Geographic Information System Used to answer what is where on the Earths surface GIS data is typically stored in a Spatial Database A spatial database
denes 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
November, 2012
4 / 40
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 Regg (IFS) Route Planning with FOSS November, 2012 5 / 40
Layer concept
GIS is closely associated with the layer concept 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 Regg (IFS) Route Planning with FOSS November, 2012 6 / 40
GIS le formats
Standards for encoding geographical information into a le Raster vs. vector formats Common vector formats:
Drawing Interchange Format (DXF): CAD data le format developed by Autodesk ESRI Shapele: 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
November, 2012
7 / 40
LineString LINESTRING (30 10, 10 30, 40 40) Polygon Polygon with hole
Michael Regg (IFS)
POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10)) POLYGON ((35 10, 10 20, 15 40, 45 45, 35 10), (20 30, 35 35, 30 20, 20 30))
Route Planning with FOSS November, 2012 10 / 40
Spatial Relationships
An important goal when using a GIS is determining the spatial relationships between geometric objects
Spatial Indices
A spatial index is used to optimize spatial queries Spatial order structure: What is spatially close together should also be close in memory
November, 2012
12 / 40
Outline
1
GIS 101 PostGIS OpenStreetMap Open Source Routing Machine OpenLayers Showcase: Tourpl
November, 2012
13 / 40
What is PostGIS?
Extension of PostgreSQL, spatially enables the PostgreSQL server Implements the SFS model Open Source (GNU General Public License) Data loaders (e. g., ESRI shape les) >330 geometric functions: distance, area, union, intersection, etc.
November, 2012
14 / 40
November, 2012
15 / 40
November, 2012
16 / 40
No spatial reference system used (default is Cartesian grid). Lets use WGS84:
SELECT ST_SetSRID(ST_Point(8.515342,47.389058), 4326);
Syntax of AddGeometryColumn:
AddGeometryColumn(<schema_name>, <table_name>, <column_name>, <srid>, <type>, <dimension>)
Michael Regg (IFS) Route Planning with FOSS November, 2012 18 / 40
PostGIS Functions
SELECT name, price, round( st_distance_sphere(geom, GeometryFromText(POINT(8.816511 47.223064), 4326) )::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 Regg (IFS) Route Planning with FOSS November, 2012 20 / 40
Outline
1
GIS 101 PostGIS OpenStreetMap Open Source Routing Machine OpenLayers Showcase: Tourpl
November, 2012
21 / 40
OpenStreetMap Data
OpenStreetMap (OSM) export format is a XML format 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 Regg (IFS) Route Planning with FOSS November, 2012 22 / 40
osm2pgsql is a utility that 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
November, 2012
23 / 40
-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)
November, 2012
24 / 40
Outline
1
GIS 101 PostGIS OpenStreetMap Open Source Routing Machine OpenLayers Showcase: Tourpl
November, 2012
25 / 40
Introduction
High performance routing machine Does not use an A* variant to compute shortest path, but Contraction Hierarchies (CH) Written in C++, available under the GNU license
November, 2012
26 / 40
Installation
For Ubuntu 12.04:
$ sudo apt-get install build-essential git scons \ pkg-config libprotoc-dev libprotobuf7 \ protobuf-compiler libprotobuf-dev libosmpbf-dev \ libpng-dev libbz2-dev libstxxl-dev libstxxl-doc \ libstxxl1 libxml2-dev libzip-dev \ libboost-thread-dev libboost-system-dev \ libboost-regex-dev libboost-filesystem-dev \ lua5.1 liblua5.1-0-dev libluabind-dev $ git clone https://github.com/DennisOSRM/Project-OSRM.git $ scons -j4
November, 2012
27 / 40
Conguration
server.ini
November, 2012
28 / 40
Conguration
Routing proles
Running OSRM
Extracting the Road Network 1/2
OSM data contains 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 le and writes:
A .osrm le containing the routing data A .osrm.restrictions le containing the restrictions to make certain turns during navigation A .osrm.names le which contains the road names
November, 2012
30 / 40
Running OSRM
Extracting the Road Network 2/2
The extractor is able to handle bzip2 compressed les as well as PBF les External memory accesses are handles by the stxxl library stxxl must be congured in a le .stxxl File format: disk=full_disk_filename,capacity,access_method Example: disk=/tmp/stxxl,25000,syscall
November, 2012
31 / 40
Running OSRM
Creating the hierachy and run OSRM
To create hierarchy (the precomputed data that enables OSRM to nd the shortest path extermly fast), type:
$ ./osrm-prepare switzerland.osrm \ switzerland.osrm.restrictions
Nearest-neighbor data structure and node map are created Afterwards, 4 les should exist:
map.osrm.hsgr (the hierarchy) map.osrm.nodes (the nodemap) map.osrm.ramIndex (stage 1 index) map.osrm.fileIndex (stage 2 index)
OSRM Services
locate: Location of nearest node to a given 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
Outline
1
GIS 101 PostGIS OpenStreetMap Open Source Routing Machine OpenLayers Showcase: Tourpl
November, 2012
34 / 40
Introduction
OpenLayers is a JavaScript library for displaying map data 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
November, 2012
35 / 40
Example
<script src="OpenLayers.js"></script> <script type="text/javascript"> var map; function init() { 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>
November, 2012
36 / 40
Outline
1
GIS 101 PostGIS OpenStreetMap Open Source Routing Machine OpenLayers Showcase: Tourpl
November, 2012
37 / 40
Tourpl
Tourpl Der Tourenplaner A route planning web application 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
November, 2012
38 / 40
IFS
November, 2012
39 / 40
Bibliography I
Regina O. Obe and Leo S. Hsu PostGIS 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
November, 2012
40 / 40