• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
GeoDjango in a nutshell
 

GeoDjango in a nutshell

on

  • 7,248 views

 

Statistics

Views

Total Views
7,248
Views on SlideShare
6,954
Embed Views
294

Actions

Likes
8
Downloads
116
Comments
1

10 Embeds 294

http://reedlab.blogspot.com 220
http://ds.dev.djangostars.com 32
http://it-jam.ciklum.net 11
http://it-jam.com.ua 11
http://127.0.0.1 7
https://twitter.com 6
http://twitter.com 3
http://www.it-jam.com.ua 2
http://www.it-jam.ciklum.net 1
http://a0.twimg.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    GeoDjango in a nutshell GeoDjango in a nutshell Presentation Transcript

    • GeoDjango in a nutshell Vasyl Dizhak http://djangostars.com/Friday, August 26, 2011
    • • Into • Standards • Django/GeoDjango • Demo app • Open sourceFriday, August 26, 2011
    • Friday, August 26, 2011
    • “80% of projects and services include spatial data” ClichéFriday, August 26, 2011
    • “nere things are more related than distant things” W.R.Tobler (1970)Friday, August 26, 2011
    • Geographic information systems(GIS) • Standards, spatial data, coordinate systems • Maps are flat, world is notFriday, August 26, 2011
    • Coordinate systems Geodetic (coordinates are in angels latitude/ longitude) Projected (represents world surface in a flat way, using linear units and play with various distortions)Friday, August 26, 2011
    • Standards • OGC: Open Geospatial Consortium. Inc. • Promulgates standards for geospatial and location based services • SFS: Simple Feature Access for SQL • OGC standard for spatial databases • The most popular • WKT: Well Known Text • Geometries • Coordinate systemsFriday, August 26, 2011
    • • WKB: Well Known Binary • Binary representation of geometries • HEX: Binary • EWKT • EWKB, HEXEWKB • GML: Geometry Markup Language (XML based) • KML: Keyhole Markup Language • Google Earth/Maps Format • WMS: Web Mapping Service(serves up images) • WFS: Web Feature Service (serves up vector data)Friday, August 26, 2011
    • Near things • GeoJSON: Geometry JSON (not in OGC standard) • SRS: Spatial Reference System • CRS: Coordinate Reference System (same as SRS) • EPSG: European Petroleum Survey Group • SRID: Spatial Reference Indenifier (corresponds to EPSG number)Friday, August 26, 2011
    • Geometry objects • Point • LineString • LinearRing • Polygon • MultiPoint • MultiString • MultiPolygon • GeometryCollectionFriday, August 26, 2011
    • Django • Python based framework • Powerful ORM • MTV concepts • Support unix and windows platformsFriday, August 26, 2011
    • GeoDjango • Based on the top of django, so include all benefits :) • Include python interfaces for GEOS, GDAL, GeoIP thanks to ctypes support in pythonFriday, August 26, 2011
    • Friday, August 26, 2011
    • http://houstoncrimemaps.com/Friday, August 26, 2011
    • History • Initially created by Justin Bronn • Started in 2006 • 2008 - 1.0 release • 2009 - 1.1 release • 2010 - 1.2 release • 2011 - 1.3 releaseFriday, August 26, 2011
    • Real using http://www.everyblock.com/Friday, August 26, 2011
    • • http://www.nytimes.com/ • http://projects.latimes.com/mapping-la/ neiborhoods/ • http://marinemap.org/ • http://earth.burningman.com/ • http://about.nsw.gov.au/ • and others ...Friday, August 26, 2011
    • GEOS • Geometry Engine Open Source In [3] from django.contrib.gis.geos import * In [4]: point = GEOSGeometry(Point(0 10)) In [5]: point.coords Out[5]: (0.0, 10.0)Friday, August 26, 2011
    • In [7]: coords = ((0, 0), (0, 10), (10, 13), (0, 0)) In [8]: polygon = Polygon(coords) In [9]: mpolygon = MultiPolygon(polygon)Friday, August 26, 2011
    • In [33]: polygon.wktOut[33]: POLYGON ((0.0000000000000000 0.0000000000000000,0.0000000000000000 10.0000000000000000, 10.0000000000000000 13.0000000000000000, 0.0000000000000000 0.0000000000000000))In [34]: polygon.contains(Point(11, 12))Out[34]: FalseIn [35]: polygon.jsonOut[35]: { "type": "Polygon", "coordinates":[ [ [ 0.000000, 0.000000 ], [ 0.000000, 10.000000 ],[ 10.000000, 13.000000 ], [ 0.000000, 0.000000 ] ] ] }In [36]: polygon.kmlOut[36]: <Polygon><outerBoundaryIs><LinearRing><coordinates>0.0,0.0,0 0.0,10.0,0 10.0,13.0,0 0.0,0.0,0</coordinates></LinearRing></outerBoundaryIs></Polygon>Friday, August 26, 2011
    • GDAL Geospatial Data Abstraction Library In [2]: from django.contrib.gis.gdal import * ... In [28]: k = DataSource(data/ukraine_administrative.shp) In [29]: layer = k[0] In [30]: layer Out[30]: <django.contrib.gis.gdal.layer.Layer object at 0x10325f990> In [31]: len(layer) Out[31]: 9976 In [32]: layer.fields Out[32]: [NAME, ADMIN_LEVE]Friday, August 26, 2011
    • You can transform coordinates from one projection to another In [37]: s = SpatialReference(4326) In [39]: k = GEOSGeometry(Point(10 10), s) In [40]: k.transform(900913)Friday, August 26, 2011
    • GeoIP IP-based Geolocation binding to MaxMind In [1]: from django.contrib.gis.utils import GeoIP In [2]: g = GeoIP() In [6]: g.country(it-jam.ciklum.net) Out[6]: {country_name: Ukraine, country_code: UA} In [7]: g.city(it-jam.ciklum.net) Out[7]: {city: None, region: None, area_code: 0, longitude: 32.0, country_code3: UKR, latitude: 49.0, postal_code: None, dma_code: 0, country_code: UA, country_name: Ukraine} In [8]: g.geos(it-jam.ciklum.net) Out[8]: <Point object at 0x103482fd0> In [9]: g.geos(it-jam.ciklum.net).coords Out[9]: (32.0, 49.0)Friday, August 26, 2011
    • Geometry Fields • GeometryField • PointField • LineStringField • PolygonField • MultiPointField • MultiLineStringField • MultiPolygonField • GeometryCollectionFieldFriday, August 26, 2011
    • Models example from django.contrib.gis.db import models class Checkin(models.Model): type = models.CharField(max_length=1, choices=CHECKIN_TYPE) title = models.CharField(max_length=255, blank=True, null=True) geodata = models.PointField() updated = models.DateTimeField(auto_now=True) objects = models.GeoManager()Friday, August 26, 2011
    • PostgreSQL SQLFriday, August 26, 2011
    • Geometry Field Options • srid (Spatial Reference System Identity, corresponding to spatial_ref_sys db table, default is 4326) • spatial_index (Spatial indexes are created by default) • dim (Set dimension if backend supports this, default is 2, postgis only) • geographyFriday, August 26, 2011
    • Spatial LookupsFriday, August 26, 2011
    • Lookup types PostGIS is a rock star :) As parameters lookups can be any data that can be converted into GEOS geometry like GeoJSON, WKT etc. https://docs.djangoproject.com/en/dev/ref/contrib/gis/db-api/#spatial-lookup-compatibilityFriday, August 26, 2011
    • Example In[8]: pnt = Point(40.187953, 49.9658546) In[9]: Administrative.objects.get (geodata__contains=pnt) Out[10]: <Administrative: 9976>Friday, August 26, 2011
    • Measurement objects Conversation between measurement unitsFriday, August 26, 2011
    • Distance, D In [1]: from django.contrib.gis.measure import D In [2]: dist = D(km=500) In [3]: dist.mi Out[3]: 310.68559611866698 In [4]: dist.rod Out[4]: 99419.390757973422Friday, August 26, 2011
    • Area, A In [1]: from django.contrib.gis.measure import A In [2]: a = A(sq_m = 10) In [3]: a.sq_km Out[3]: 1.0000000000000001e-05 In [4]: a.sq_rod Out[4]: 0.39536861034746451Friday, August 26, 2011
    • Distance queries* In [10]: Checkin.objects.filter(geodata__distance_gte=(pnt, 7000)) Out[10]: [<Checkin: Ресторан «Домашня Кухня»>, <Checkin: Великий Вiз>, <Checkin: Ресторан «Домашня Кухня»>, <Checkin: Станція швидкісного трамвая "Польова">, <Checkin: НТУУ "КПИ", корпус 7>]Friday, August 26, 2011
    • GeoQuerySet Methods MySQL does notsupport any of these more ...Friday, August 26, 2011
    • Aggregate Methods • collect • extend • extend3d • make_line • unionaggFriday, August 26, 2011
    • Output methods Done more on db level • kml() • gml() • svg() • geojson() • geohash()Friday, August 26, 2011
    • Measurement methods • area()(attachs the area to each geometry field in the queryset as Area object ) • distance(geom) • length() • perimeter()Friday, August 26, 2011
    • Geometry operations • difference(geom) • intersection(geom) • union(geom) • sym_difference(geom)Friday, August 26, 2011
    • Geometry methods • centroid() • envelope() • point_on_surface() • scale(x, y, z=0) • translate(x, y, z=0) • transform(srid)Friday, August 26, 2011
    • In [10]: k = Administrative.objects.kml().svg().perimeter().point_on_surface().get(id=10)In [11]: k.point_on_surface.coordsOut[11]: (22.153155999999999, 48.512821000000002)In [12]: k.kmlOut[12]:u<LineString><coordinates>22.166018,48.5771299Friday, August 26, 2011
    • Show timeFriday, August 26, 2011
    • Related projects • FeatureServer http://featureserver.org • TileCache http://tilecache.org • TileStache http://tilestache.org/ • Mapproxy http://mapproxy.org/Friday, August 26, 2011
    • Cartography • Mapnik http://mapnik.org • MapServer http://mapserver.orgFriday, August 26, 2011
    • Frontend interaction • OpenLayers http://openlayer.org • Google maps js api • Polymaps http://polymaps.org/ • Wax http://mapbox.github.com/wax/ manual/ • TileMill http://tilemill.com/pages/index.htmlFriday, August 26, 2011
    • Many thanks Vasyl Dizhak http://twitter.com/rootart http://twitter.com/djangostars http://geojam.djangostars.com http://github.com/rootart/geojam Questions?Friday, August 26, 2011