28
GeoDjango & HTML5 Geolocation John Paulett September 1, 2011 [email protected] @johnpaulett

GeoDjango & HTML5 Geolocation

Embed Size (px)

DESCRIPTION

Presentation at September 2011 Lambda Lounge.

Citation preview

Page 1: GeoDjango & HTML5 Geolocation

GeoDjango & HTML5 Geolocation

John PaulettSeptember 1, 2011

[email protected]@johnpaulett

Page 2: GeoDjango & HTML5 Geolocation
Page 3: GeoDjango & HTML5 Geolocation

The Plan

HTML5 Geolocation

Django Crash Course

What is GeoDjango?

GeoDjango Basics

Demo Application

Page 4: GeoDjango & HTML5 Geolocation

Geolocation

Page 5: GeoDjango & HTML5 Geolocation

W3C Geolocation

GPS, nearby Wi-Fi networks, cell towers, IP address

IE 9, FF 3.6, Safari 5.0, Chrome, Opera 10.6, iOS, Android

navigator.geolocation.getCurrentPosition

navigator.geolocation.watchPosition

Page 6: GeoDjango & HTML5 Geolocation

W3C Geolocation

function showMap(position) {

console.log(position);

}

navigator.geolocation.getCurrentPosition(

showMap

);

Page 7: GeoDjango & HTML5 Geolocation

W3C Geolocation

{

"coords": {

"accuracy": 22000,

"altitude": null,

"altitudeAccuracy": null,

"heading": null,

"latitude": 38.631756,

"longitude": -90.24323,

"speed": null

},

"timestamp": 1314459776275

}

Page 8: GeoDjango & HTML5 Geolocation

Crash Course

Page 9: GeoDjango & HTML5 Geolocation

models.py

from django.db import models

class City(models.Model):

name = models.TextField()

class UserGroup(models.Model):

name = models.TextField()

city = models.ForeignKey(City)

started = models.DateField()

def join(self, user):

# add user to group

Page 10: GeoDjango & HTML5 Geolocation

urls.py

urlpatterns = patterns(

url(

r'^user-groups/(?P<city_name>\w+)$',

'myapp.views.user_groups'

),

)

Page 11: GeoDjango & HTML5 Geolocation

views.py

def user_groups(request, city_name):

city = City.objects.get(name=city_name)

groups = UserGroup.objects.filter(city=city)

return render(request, 'user_groups.html',

{'groups': groups})

Page 12: GeoDjango & HTML5 Geolocation

user_groups.html

{% extends "base.html%}

<ul>

{% for group in groups %}

<li>

{{ group.name }}

</li>

{% endfor %}

</ul>

Page 13: GeoDjango & HTML5 Geolocation
Page 14: GeoDjango & HTML5 Geolocation

What is GeoDjango?

“world-class geographic Web framework” included in Django core

Combine existing Python & DB tools with standard API

but first …

Page 15: GeoDjango & HTML5 Geolocation

Some GIS Problems

The Earth is not a sphere!

How to store & query efficiently

Vendor implementations

Wide range of data formats

Tiger/LINE, Shapefiles, E00, OGR, GeoJSON, WKT, EWKT, EWKB, GML, KML, OSM, GLOBE, TIFF, ArcGrid ….

Page 16: GeoDjango & HTML5 Geolocation

GeoDjango Basics

Page 17: GeoDjango & HTML5 Geolocation

GeoDjango Model Fields

from django.contrib.gis.db import models

models.PointField

models.LineStringField

models.PolygonField

models.MultiPointField

models.MultiLineStringField

models.MultiPolygonField

models.GeometryCollectionField

Page 18: GeoDjango & HTML5 Geolocation

Given a Set of Geo Objects

Measure & Find:

distance, area, perimeter, centroid, envelope

Edit:

transform (SRID), scale

Operations:

intersection, difference, union

Output:

geojson, gml, kml, svg

SalesRegion.objects.all().kml()

Page 19: GeoDjango & HTML5 Geolocation

Geo Querying

contains, covers, crosses, disjoint, equals, intersects, touches, left/right, distance_lt, distance_gt …

SalesRegion.objects.filter(

poly__distance_lt=(pnt, D(mi=500))

)

Page 20: GeoDjango & HTML5 Geolocation

lambdageo

Page 21: GeoDjango & HTML5 Geolocation

lambdageo

http://lambdageo.ep.io

http://github.com/johnpaulett/lambdageo

Page 22: GeoDjango & HTML5 Geolocation

●lambdageo.ep.io

models.py

Admin

Views

Templates

Page 23: GeoDjango & HTML5 Geolocation

Django Admin

Page 24: GeoDjango & HTML5 Geolocation

GIS is Cool

Python GIS

Tile Servers, Mapnik, etc.

Data

Openstreet Maps, Census

Page 25: GeoDjango & HTML5 Geolocation

lambdageo.ep.io

github.com/johnpaulett/lambdageo

[email protected] / @johnpaulett

Page 26: GeoDjango & HTML5 Geolocation

References

Page 27: GeoDjango & HTML5 Geolocation

References

Python Geospatial Development – Erik Westra

Page 28: GeoDjango & HTML5 Geolocation

References

http://geodjango.org/

http://dev.w3.org/geo/api/spec-source.html

http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/geolocation/ http://caniuse.com/#search=geolocation