4. “80% of projects and
services include spatial
data” Cliché
Friday, August 26, 2011
5. “nere things are more
related than distant
things”
W.R.Tobler (1970)
Friday, August 26, 2011
6. Geographic information
systems(GIS)
• Standards, spatial
data, coordinate
systems
• Maps are flat, world is
not
Friday, August 26, 2011
7. 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
8. 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 systems
Friday, August 26, 2011
9. • 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
10. 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
12. Django
• Python based framework
• Powerful ORM
• MTV concepts
• Support unix and windows platforms
Friday, August 26, 2011
13. GeoDjango
• Based on the top of django, so include all
benefits :)
• Include python interfaces for GEOS,
GDAL, GeoIP thanks to ctypes support in
python
Friday, August 26, 2011
16. History
• Initially created by Justin Bronn
• Started in 2006
• 2008 - 1.0 release
• 2009 - 1.1 release
• 2010 - 1.2 release
• 2011 - 1.3 release
Friday, August 26, 2011
17. Real using
http://www.everyblock.com/
Friday, August 26, 2011
18. • 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
19. 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
20. 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
22. 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
23. 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
24. 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
28. 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)
• geography
Friday, August 26, 2011
30. 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-compatibility
Friday, August 26, 2011
31. 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
32. Measurement objects
Conversation between measurement units
Friday, August 26, 2011
33. 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.390757973422
Friday, August 26, 2011
34. 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.39536861034746451
Friday, August 26, 2011
35. 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
36. GeoQuerySet Methods
MySQL does not
support any of these
more ...
Friday, August 26, 2011
38. Output methods
Done more on db level
• kml()
• gml()
• svg()
• geojson()
• geohash()
Friday, August 26, 2011
39. Measurement methods
• area()(attachs the area to each geometry
field in the queryset as Area object )
• distance(geom)
• length()
• perimeter()
Friday, August 26, 2011
41. Geometry methods
• centroid()
• envelope()
• point_on_surface()
• scale(x, y, z=0)
• translate(x, y, z=0)
• transform(srid)
Friday, August 26, 2011
42. In [10]: k = Administrative.objects.kml().svg().perimeter
().point_on_surface().get(id=10)
In [11]: k.point_on_surface.coords
Out[11]: (22.153155999999999, 48.512821000000002)
In [12]: k.kml
Out[12]:
u'<LineString><coordinates>22.166018,48.5771299
Friday, August 26, 2011