Mapnik Sotm 2007


Published on

SOTM07 Artem Pavlenko - Putting the map into OSM: rendering geo-data with Mapnik (July 14, 2007)

Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Mapnik Sotm 2007

  1. 1. Putting the map into OSM: rendering geo-data with Mapnik Artem Pavlenko
  2. 2. A brief history of (web)mapping <ul><li>Good old 70 s GIS </li></ul><ul><li>OGC – WMS, WFS, W*S ... </li></ul><ul><li>Google Maps </li></ul><ul><li>[???] </li></ul>
  3. 3. Why did I like Google Maps? <ul><li>No Java, no Flash, no ActiveX </li></ul><ul><li>No W*S </li></ul><ul><li>Lots of data </li></ul><ul><li>Good looking maps </li></ul><ul><li>APIs </li></ul>
  4. 4. What was the problem, then? <ul><ul><li>It is not free! </li></ul></ul><ul><ul><li>Data is subject to license and rendering software is proprietary </li></ul></ul>
  5. 5. Searching for the solution <ul><ul><li>In the post GMap world we expect web mapping to be: </li></ul></ul><ul><ul><li>Fast </li></ul></ul><ul><ul><li>Highly interactive </li></ul></ul><ul><ul><li>And to have good cartography </li></ul></ul>At the time, none of the FOSS tools delivered these...
  6. 6. Mapnik
  7. 7. Mapnik is not ... <ul><li>GIS </li></ul><ul><li>A map server, though you can hack one with Mapnik in no time </li></ul><ul><li>Attempt to implement all OGC specs in Java and bully the rest for not doing so </li></ul><ul><li>MapNick – I'm not Nick ... </li></ul>
  8. 8. Mapnik is ... <ul><li>About making beautiful maps </li></ul><ul><li>What I wanted to use myself </li></ul><ul><li>F/OSS </li></ul><ul><li>Cross platform – Linux, Mac OS X, Win32 </li></ul><ul><li>Written in modern c++ </li></ul><ul><li>Easy to get started (Python bindings) </li></ul><ul><li>Flexible design </li></ul>
  9. 12. How do you make a map?
  10. 13. Making a map is easy <ul><ul><li>from mapnik import * </li></ul></ul><ul><ul><li>m = Map(800,600) </li></ul></ul><ul><ul><li>load_map(m,'/Users/artem/map.xml') </li></ul></ul><ul><ul><li>m.zoom_to_box(Envelope(-180,-90,180,90)) </li></ul></ul><ul><ul><li>render_to_file(m,&quot;world.jpg&quot;,&quot;jpeg&quot;) </li></ul></ul><ul><ul><li>What is *.xml? </li></ul></ul>
  11. 14. Making a map is easy <ul><ul><li><Map bgcolor='steelblue'> </li></ul></ul><ul><ul><li></Map> </li></ul></ul>
  12. 15. Making a map is easy <ul><ul><li><Map bgcolor='steelblue'> </li></ul></ul><ul><ul><li><Layer name='mylayer'> </li></ul></ul><ul><ul><li><Datasource type='shape' file='/tmp/world'/> </li></ul></ul><ul><ul><li></Layer> </li></ul></ul><ul><ul><li></Map> </li></ul></ul>
  13. 16. Making a map is easy (almost) <ul><ul><li><Map bgcolor='steelblue'> </li></ul></ul><ul><ul><li><Style name='My Style'> </li></ul></ul><ul><ul><li><Rule> </li></ul></ul><ul><ul><li><PolygonSymbolizer> </li></ul></ul><ul><ul><li> <CssParameter name='fill'>lightgrey</CssParameter> </li></ul></ul><ul><ul><li></PolygonSymbolizer> </li></ul></ul><ul><ul><li><LineSymbolizer> </li></ul></ul><ul><ul><li> <CssParameter name='stroke'>white</CssParameter> </li></ul></ul><ul><ul><li></LineSymbolizer> </li></ul></ul><ul><ul><li></Rule> </li></ul></ul><ul><ul><li></Style> </li></ul></ul><ul><ul><li><Layer name='countries'> </li></ul></ul><ul><ul><li><Style>MyStyle</Style> </li></ul></ul><ul><ul><li><Datasource type='shape' file='/tmp/shapefile/world' /> </li></ul></ul><ul><ul><li></Layer> </li></ul></ul><ul><ul><li></Map> </li></ul></ul>
  14. 17. Making a map is fun <ul><ul><li>f rom mapnik import * </li></ul></ul><ul><ul><li>m = Map(800,600,&quot;+proj=latlong +datum=WGS84&quot;) </li></ul></ul><ul><ul><li>m.background = Color('steelblue') </li></ul></ul><ul><ul><li>s = Style() </li></ul></ul><ul><ul><li>r=Rule() </li></ul></ul><ul><ul><li>r.symbols.append(PolygonSymbolizer(Color('#f2eff9'))) </li></ul></ul><ul><ul><li>r.symbols.append(LineSymbolizer(Color('rgb(50%,50%,50%)'),0.1)) </li></ul></ul><ul><ul><li>s.rules.append(r) </li></ul></ul><ul><ul><li>m.append_style('My Style') </li></ul></ul><ul><ul><li>lyr = Layer('world') </li></ul></ul><ul><ul><li>lyr.datasource Shapefile(file='/opt/data/countries') </li></ul></ul><ul><ul><li>lyr.styles.append('My Style') </li></ul></ul><ul><ul><li>m.layers.append(lyr) </li></ul></ul><ul><ul><li>m.zoom_to_box(lyr.envelope()) </li></ul></ul><ul><ul><li>render_to_file(m,'world.jpg', 'jpeg') </li></ul></ul>
  15. 18. Made it!
  16. 19. More about styling... <ul><li>Named styles, each layer can have 0...N style(s) </li></ul><ul><li>Order is important – 'painter model' </li></ul><ul><li>0...N Styles -> 0...N Rules ->(Min/Max Scale Denominator, Filter, 0...N Symbolizer(s)) </li></ul><ul><li>Filter is 'filter expression' </li></ul>
  17. 20. Filter expressions - DSEL <ul><li>Syntax for filter expressions is very simple, you enclose variables (evaluated at runtime) in square brackets - [var] </li></ul><ul><li>Arithmetics: + , - , * , / </li></ul><ul><li>Comparison: = , <> , > , < , >= ,<= </li></ul><ul><li>Logical operators: and, or , not </li></ul><ul><li>regular expressions: [attribute].match('your_reg_ex') </li></ul>
  18. 21. Filter expressions - examples <ul><ul><li>[highway] = 'motorway' or 'motorway_link' = [highway] </li></ul></ul><ul><ul><li>[cfcc].match('^A1[0-9]') </li></ul></ul><ul><ul><li>[area] > 1000 and [area] <= (1000*2) </li></ul></ul>
  19. 22. Making an OpenStreetMap <ul><ul><li>Challenges and opportunities </li></ul></ul>
  20. 23. The first challenge <ul><ul><li>Data entered by real people </li></ul></ul><ul><ul><li>uclassified uhclassified unc lassified unclasiffied unclasified unclassfied unclassiefied unclassifed unclassifeid unclassiffied unclassified unclassified unclessified uncliassified undefined ... </li></ul></ul><ul><ul><li>'horse' = 'yes' </li></ul></ul><ul><ul><li>'village_green' </li></ul></ul>
  21. 24. Facing the challenge <ul><li>Data processing : compile raw OSM data into domain specific formats suited for rendering, routing, small devices etc. </li></ul><ul><li>We have some tools already: osm2pgsql, osm2shp, osm2kml, osm2whatever but we'll need more. </li></ul>
  22. 25. osm2pgsql <ul><li>$ osm2pgsql planet.osm.bz2 </li></ul><ul><li>Outputs 'clean' geometries </li></ul><ul><li>Builds polygons </li></ul><ul><li>Assigns z-order </li></ul><ul><li>~30 minutes on my laptop </li></ul><ul><li>planet.osm -> osm2pgsql -> postgresql/postgis </li></ul>
  23. 26. More challenges <ul><li>Visualising 'live' data </li></ul><ul><li>Users want reward for their efforts: “ where is my track on the map? I want it now!” </li></ul>
  24. 27. Possible solutions <ul><li>Mapnik at home? </li></ul><ul><li>Planet.diff? </li></ul><ul><li>Direct rendering from live OSM database? </li></ul>
  25. 28. Tiles. How many? <ul><li>Level 1 - 4 tiles </li></ul><ul><li>Level 2 - 16 tiles </li></ul><ul><li>Level 18 - 68719476736 tiles :( </li></ul><ul><li>Let user decide - 3244998 tiles :) </li></ul><ul><li>More resources will be needed very soon! </li></ul>
  26. 29. Yet another challenge! Or do I mean opportunity... <ul><ul><li>Number of map features will continue to grow... </li></ul></ul><ul><ul><li>(osm.)XML sucks! </li></ul></ul><ul><ul><li>What is the answer? </li></ul></ul>
  27. 30. Map editor? OSM Illustrator?
  28. 31. An opportunity for Mapnik <ul><li>OSM style community scrutiny and effort are invaluable </li></ul><ul><li>Mapnik is FREE and everyone can get involved </li></ul><ul><li>To play with some new features grab the ISO image from: http:// </li></ul>
  29. 32. A future history of (web)mapping? <ul><li>Good old 70 s GIS </li></ul><ul><li>OGC – WMS, WFS, W*S </li></ul><ul><li>Google Maps </li></ul><ul><li>[OpenStreetMap] </li></ul>
  30. 33. Thank you!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.