Pycon2011

2,004 views

Published on

Published in: Technology, Art & Photos
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,004
On SlideShare
0
From Embeds
0
Number of Embeds
39
Actions
Shares
0
Downloads
30
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Pycon2011

  1. 1. GIS, Python and company Igor Pochechuev 22-23 October, 2011 Kyiv, Ukraine
  2. 2. Content● What is geometry? geometry formats● How to store geo data? spatial databases● Where we can get geo data?● Render it!● Demo
  3. 3. General provisions what we got
  4. 4. Geometry formats● WKT, WKB● KML, GML (xml based)● GeoJSON (json based)● Shapefile (ESRI open specification)● etc.
  5. 5. Geometry common types● Point (x, y)● Line (<point>, <point1>, <point2>, …)● Polygon (<line>, <line1>, <line2>, …)
  6. 6. MultiGeometry additional types of geometry● MultiPoint (<point>, <point1>, <point2>, ...)● MultiLine (<line>, <line1>, <line2>, ...)● MultiPolygon (<polygon>, <polygon1>, <polygon2>, ...)
  7. 7. Database layer storing spatial data
  8. 8. Storing data spatial databases● SpatiaLite (SQLite)● MySQL● Oracle● PostGIS (PostgreSQL)
  9. 9. Storing data right choicePostGIS
  10. 10. How to get geo data? vector data
  11. 11. Getting data vector dataOpenStreetMap
  12. 12. OpenStreetMap stats● < 400 000 registered users● ~ 1 100 000 000 nodes (points)● 100 000 000 ways● ~ 800 — 3 000 nodes added each day● ~ 100 000 — 300 000 ways added each day● More statistics: http://wiki.openstreetmap.org/wiki/Stats
  13. 13. OpenStreetMap downloading ...● Download planet.osm http://wiki.openstreetmap.org/wiki/Planet.osm● OSM API http://api.openstreetmap.org/api/0.6/map?bbox=11.54,48.14,11.543,48.145● JOSM (download through desktop app) http://wiki.openstreetmap.org/wiki/JOSM● Third part services (GIS LAB) http://gis-lab.info/projects/osm-export.html
  14. 14. Loading data to database
  15. 15. >wget http://wiki.openstreetmap.org/wiki/Planet.osm
  16. 16. OSM2PgSQL loading data● osm2pgsql -d <db_name> -H <db_host> -U <db_user> -P <db_port> -c # create tables if needed -s # store tmp data in database -S osm.import.style # mapping style -k # add tags without column to an additional hstore -z extra_data # hstore column containing all tags that start with extra_data RU-KRS.osm # path to OSM data file
  17. 17. Rendering ...
  18. 18. Rendering tool choosingMapServer Mapnik
  19. 19. Mapnik description● Written in C++● Python interface● OpenStreetMap, Flickr, CloudMade use mapnik● PostGIS, Shapefiles, GeoTIFF, OSM XML, ...● PNG, JPG, SVG, PDF, ...
  20. 20. Mapnikmap example
  21. 21. Layers intro
  22. 22. Mapnik code exampleimport mapnikm = mapnik.Map(600,300,"+proj=latlong +datum=WGS84")m.background = mapnik.Color(steelblue)r = mapnik.Rule()r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color(#f2eff9)))r.symbols.append(mapnik.LineSymbolizer(mapnik.Color(rgb(50%,50%,50%)),0.1))s = mapnik.Style()s.rules.append(r)m.append_style(World Style,s)
  23. 23. Mapnik code exampleimport mapnikm = mapnik.Map(600, 300, "+proj=latlong +datum=WGS84")m.background = mapnik.Color(steelblue)r = mapnik.Rule()r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color(#f2eff9)))r.symbols.append(mapnik.LineSymbolizer(mapnik.Color(rgb(50%,50%,50%)),0.1))s = mapnik.Style()s.rules.append(r)m.append_style(World Style,s)
  24. 24. Mapnik code exampleimport mapnikm = mapnik.Map(600, 300, "+proj=latlong +datum=WGS84")m.background = mapnik.Color(steelblue)r = mapnik.Rule()r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color(#f2eff9)))r.symbols.append(mapnik.LineSymbolizer(mapnik.Color(rgb(50%,50%,50%)), 0.1))s = mapnik.Style()s.rules.append(r)m.append_style(World Style,s)
  25. 25. Mapnik code exampleimport mapnikm = mapnik.Map(600, 300, "+proj=latlong +datum=WGS84")m.background = mapnik.Color(steelblue)r = mapnik.Rule()r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color(#f2eff9)))r.symbols.append(mapnik.LineSymbolizer(mapnik.Color(rgb(50%,50%,50%)), 0.1))s = mapnik.Style()s.rules.append(r)m.append_style(World Style,s)
  26. 26. Mapnik code example 2lyr = mapnik.Layer(world, "+proj=latlong +datum=WGS84")lyr.datasource = mapnik.Shapefile(file=world_borders.shp)lyr.styles.append(World Style)m.layers.append(lyr)m.zoom_to_box(lyr.envelope())mapnik.render_to_file(m,world.png, png)
  27. 27. Mapnik code example 2lyr = mapnik.Layer(world, "+proj=latlong +datum=WGS84")lyr.datasource = mapnik.Shapefile(file=world_borders.shp)lyr.styles.append(World Style)m.layers.append(lyr)m.zoom_to_box(lyr.envelope())mapnik.render_to_file(m,world.png, png)
  28. 28. Mapnik code example 2lyr = mapnik.Layer(world, "+proj=latlong +datum=WGS84")lyr.datasource = mapnik.Shapefile(file=world_borders.shp)lyr.styles.append(World Style)m.layers.append(lyr)m.zoom_to_box(lyr.envelope())mapnik.render_to_file(m,world.png, png)
  29. 29. Map in browser
  30. 30. Mapniktile description
  31. 31. Mapnik map services● Tile Map Service● Web Map Service
  32. 32. Mapnik TMShttp: //website.com/<zoom>/<x>/<y>.png../tiles/12/2451/1360.png
  33. 33. Mapnik using osm scripts● svn export http://svn.openstreetmap.org/applications/rendering/...● ./generate_xml.py --password value --host value --port value --user value --dbname value● MAPNIK_MAP_FILE=osm.xml MAPNIK_TILE_DIR=tiles/ ./generate_tiles.py
  34. 34. Mapnik XML<Map bgcolor="#b5d0d0"><Style name="map_style"> <Rule> <MaxScaleDenominator>[scale]</MaxScaleDenominator> <MinScaleDenominator>[scale]</MinScaleDenominator> <Filter>[field]=value</Filter> <PointSymbolizer/> <LineSymbolizer/> <PolygonSymbolizer/> … </Rule></Style>
  35. 35. Mapnik XML<Layer name="misc_boundaries"><StyleName>map_style</StyleName><Datasource> <Parameter name="table"> (select way,way_area,name,boundary from polygon where boundary=national_park) as boundary </Parameter> <Parameter name=dbname>[dbname]</Parameter> <Parameter name=host>[host]</Parameter> <Parameter name=user>[user]</Parameter> …</Datasource></Layer>
  36. 36. Tile generating./generate_tiles.py
  37. 37. Got tiles, whats next?
  38. 38. Frontend maps choosing tool● OpenLayers● GeoExt● Leaflet
  39. 39. OpenLayers● Most powerfull● Most used● Large community● OSM supported● OSM, Google, Yahoo maps in one string● TMS, WMS, WFS● GML, GeoJSON, GeoRSS
  40. 40. OpenLayers
  41. 41. Show time!
  42. 42. Thanks!Questions?

×