Open Street Map - Lite - Open Layers - From Map To Web Presentation
Open Street Map - Lite - Open Layers - From Map To Web Presentation
Me ...
Hartmut Holzgraefe <[email protected]> MySQL Support Engineer 2004-2010 Currently working for FoeBuD e.V., a German NGO ( http://foebud.org/ ) OSM-User since 2007, active since late 2009
Talk Outline
What is OpenStreetMap What are PostGIS and OpenLayers OpenStreetMap Data Format OSM Database Database Web Ad Hoc Query Results Example Application
OpenStreetMap
Open Geodata Open license (currently: CC-by-SA License) Data sources contain:
GPS Tracks Arial Images (YaHoo!, Bing, AeroWest, ...) Other Imports (OpenGeoDB, USA: Tiger, )
http://osm.org/go/TZMlDJLP
compared to ...
http://www.openwhatevermap.org/?zoom=12&lat=37.35624&lon=-121.92799&layers=B
OpenStreetMap Workflow
Of interest to us today:
PostGIS
GIS Extension for PostgreSQL Supports standard GIS data types like POINT, LINE, POLYGON ... 2D GIS Index Support Rich set of functions supporting geometry creation, combination and processing See also http://postgis.refractions.net/
OpenLayers
Open Source JavaScript/Ajax API for Web Maps Similar to the Google Maps API in some ways But supporting way more formats:
Bitmap/Image: OpenStreetMap(*), Google, Bing, ... Vektor: WKT, KML, GPX, OSM, GeoJSON, ... WMS
ID, user, timestamp, version, changeset plus any number of additional key/value pairs
Refer to the OSM wiki for key/value tag definitions and suggestions for various real world object types
A Node defines a single point on the map 2D latitute / longitude Nodes can stand for themselves (POI) or can be part of a way
Relations combine other objects Relations can contain Nodes and Ways ... and other Relations, too Typical use cases
Multipolygons Very long Ways Local groups of Objects Routs spanning multiple streets
For small areas OSM API For medium size areas OSM XAPI For large areas Downloads
Planet.osm direktly from openstreetmap.org Daily, hourly, minutely diffs openstreetmap.org $country.osm, $state.osm, $district.osm e.g. from GeoFabrik.de
Import tools: osm2pgsql and ImpOSM Both can import complete OSM files and daily/hourly/minutely diffs (osm2pgsql) Support OSM XML and the newer PBF Format Raw data is converted into a more usable form
By combining objects from relations By creating separate tables for lines and polygons
Database support
Currently PostgreSQL / PostGIS only Both tools are modular though so having backends for different GIS capable databases possible and being worked on, but moving slowly Other open source optipons would be:
osm2pgsql
osm2pgsql [options] planet.osm.{gz,bz2,pbf} --database=name --prefix=name --latlong --slim --cache=size
Osm2pgsql Schema
Main tables
Schema Details
Table "public.planet_osm_polygon" Column | Type | Modifiers --------------------+----------+----------osm_id | integer | ... name | text | z_order | integer | way_area | real | way | geometry | Indexes: "planet_osm_polygon_index" gist (way) "planet_osm_polygon_pkey" btree (osm_id)
Simple Queries
Administrative town border of Stuttgart, Germany: SELECT ASTEXT(way) FROM planet_osm_polygon WHERE name='Stuttgart'; POLYGON((1006189.62 6231109.22, 1006225.9 6231281.72, ...
OpenLayers Basics
<script src="OpenLayers.js"/> <script src="OpenStreetMap.js"/> <script type="text/javascript"> var map, vectorLayer; function init() { map = new OpenLayers.Map('map'); osmLayer = new OpenLayers.Layer.OSM.Mapnik(); vectorLayer = new OpenLayers.Layer.Vector(); map.addLayers([osmLayer, vectorLayer]); map.zoomToMaxExtent(); } </script> <body onload="init();"> <div id="map"/> </body>
WKT-Results as VectorLayer
OpenLayers directly supports the WKT format as returned by ASTEXT() for displaying vector features like points, lines and polygons:
var wkt_format = new OpenLayers.Format.WKT(); var vectorFeature = wkt_format.read(WKT_text); vectorLayer.addFeatures(vectorFeature); map.zoomToExtent(vectorLayer.getDataExtent());
Markers as TextLayer
TextLayer reads a TAB separated list and creats one map marker per input line Supported input fields:
Latitude and Longitude (mandatory) Popup title and content (optional) Icon image and relative position (optional)
PostGIS Terminal
Originally created by Marc Jansen and Till Adams for their (German) book on OpenLayers Simple query entry in a web form Results shown directly in the browser Slightly extended by me to support markers in addition to WKT vectors, and to support more than one WKT result row See also http://openlayers-buch.de/
Screenshot
Result Screenshot
Screenshot
Screenshot
BUFFER(CENTROID(city.way), sqrt(pop.population)*10))) FROM planet_osm_polygon city JOIN population pop ON city.name = pop.name AND ( city.admin_level = '8' OR ( AND
the higher level 6 */
Screenshot
Example Application
Cat inspectors