pycon2011

43
Igor Pochechuev 22-23 October, 2011 Kyiv, Ukraine GIS, Python and company

Upload: django-stars

Post on 27-Jan-2015

107 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Pycon2011

Igor Pochechuev22-23 October, 2011Kyiv, Ukraine

GIS, Python and company

Page 2: Pycon2011
Page 3: Pycon2011

Content

● What is geometry?geometry formats

● How to store geo data?spatial databases

● Where we can get geo data?● Render it!● Demo

Page 4: Pycon2011

General provisionswhat we got

Page 5: Pycon2011

Geometryformats

● WKT, WKB● KML, GML (xml based)● GeoJSON (json based)● Shapefile (ESRI open specification)● etc.

Page 6: Pycon2011

Geometrycommon types

● Point(x, y)

● Line(<point>, <point1>, <point2>, …)

● Polygon(<line>, <line1>, <line2>, …)

Page 7: Pycon2011

MultiGeometryadditional types of geometry

● MultiPoint(<point>, <point1>, <point2>, ...)

● MultiLine(<line>, <line1>, <line2>, ...)

● MultiPolygon(<polygon>, <polygon1>, <polygon2>, ...)

Page 8: Pycon2011

Database layerstoring spatial data

Page 9: Pycon2011

Storing dataspatial databases

● SpatiaLite (SQLite)● MySQL● Oracle● PostGIS (PostgreSQL)

Page 10: Pycon2011

Storing dataright choice

PostGIS

Page 11: Pycon2011

How to get geo data?vector data

Page 12: Pycon2011

Getting datavector data

OpenStreetMap

Page 13: Pycon2011

OpenStreetMapstats

● < 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

Page 14: Pycon2011

OpenStreetMapdownloading ...

● Download planet.osmhttp://wiki.openstreetmap.org/wiki/Planet.osm

● OSM APIhttp://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

Page 15: Pycon2011

Loading data to database

Page 16: Pycon2011

>wget http://wiki.openstreetmap.org/wiki/Planet.osm

Page 17: Pycon2011

OSM2PgSQLloading 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

Page 18: Pycon2011

Rendering ...

Page 19: Pycon2011

Renderingtool choosing

MapServer Mapnik

Page 20: Pycon2011

Mapnikdescription

● Written in C++● Python interface● OpenStreetMap, Flickr, CloudMade use mapnik● PostGIS, Shapefiles, GeoTIFF, OSM XML, ...● PNG, JPG, SVG, PDF, ...

Page 21: Pycon2011

Mapnikmap example

Page 22: Pycon2011

Layersintro

Page 23: Pycon2011

Mapnikcode example

import mapnik

m = 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)

Page 24: Pycon2011

Mapnikcode example

import mapnik

m = 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)

Page 25: Pycon2011

Mapnikcode example

import mapnik

m = 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)

Page 26: Pycon2011

Mapnikcode example

import mapnik

m = 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)

Page 27: Pycon2011

Mapnikcode example 2

lyr = 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')

Page 28: Pycon2011

Mapnikcode example 2

lyr = 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')

Page 29: Pycon2011

Mapnikcode example 2

lyr = 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')

Page 30: Pycon2011

Map in browser

Page 31: Pycon2011

Mapniktile description

Page 32: Pycon2011

Mapnikmap services

● Tile Map Service● Web Map Service

Page 33: Pycon2011

MapnikTMS

http: //website.com/<zoom>/<x>/<y>.png

../tiles/12/2451/1360.png

Page 34: Pycon2011

Mapnikusing 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

Page 35: Pycon2011

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>

Page 36: Pycon2011

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>

Page 37: Pycon2011

Tile generating

./generate_tiles.py

Page 38: Pycon2011

Got tiles, what's next?

Page 39: Pycon2011

Frontend mapschoosing tool

● OpenLayers● GeoExt● Leaflet

Page 40: Pycon2011

OpenLayers

● Most powerfull● Most used● Large community● OSM supported● OSM, Google, Yahoo maps in one string● TMS, WMS, WFS● GML, GeoJSON, GeoRSS

Page 41: Pycon2011

OpenLayers

Page 42: Pycon2011

Show time!

Page 43: Pycon2011

Thanks!Questions?