Upload
john-paulett
View
5.168
Download
2
Embed Size (px)
DESCRIPTION
Presentation at September 2011 Lambda Lounge.
Citation preview
The Plan
HTML5 Geolocation
Django Crash Course
What is GeoDjango?
GeoDjango Basics
Demo Application
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
W3C Geolocation
function showMap(position) {
console.log(position);
}
navigator.geolocation.getCurrentPosition(
showMap
);
W3C Geolocation
{
"coords": {
"accuracy": 22000,
"altitude": null,
"altitudeAccuracy": null,
"heading": null,
"latitude": 38.631756,
"longitude": -90.24323,
"speed": null
},
"timestamp": 1314459776275
}
Crash Course
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
urls.py
urlpatterns = patterns(
url(
r'^user-groups/(?P<city_name>\w+)$',
'myapp.views.user_groups'
),
)
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})
user_groups.html
{% extends "base.html%}
<ul>
{% for group in groups %}
<li>
{{ group.name }}
</li>
{% endfor %}
</ul>
What is GeoDjango?
“world-class geographic Web framework” included in Django core
Combine existing Python & DB tools with standard API
but first …
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 ….
GeoDjango Basics
GeoDjango Model Fields
from django.contrib.gis.db import models
models.PointField
models.LineStringField
models.PolygonField
models.MultiPointField
models.MultiLineStringField
models.MultiPolygonField
models.GeometryCollectionField
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()
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))
)
lambdageo
lambdageo
http://lambdageo.ep.io
http://github.com/johnpaulett/lambdageo
●lambdageo.ep.io
models.py
Admin
Views
Templates
Django Admin
GIS is Cool
Python GIS
Tile Servers, Mapnik, etc.
Data
Openstreet Maps, Census
References
References
Python Geospatial Development – Erik Westra
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