Putting Django on the MapΒΆ

GeoDjango

“Everything is related to everything else, but near things are more related than distant things.” - Tobler’s first law of geography

  • GeoDjango gives a nice interface to 2 C++ libs, GDAL and GEOS
  • GDAL is used for getting data in and out
  • GEOS manipuates spatial data
  • KML/GeoJSON
  • have model fields for Point and Polygon

Example app - 3sqaure

  • install PostGIS http://postgis.net/install , install libs
    • MySQL and SpatiaLite have some support, but much less than Postgres
  • add django.contrib.gis to INSTALLED_APPS
from django.contrib.gis.db import models

class xyz(models.Model):
    # ...
    location = models.PointField()

    objects = models.GeoManager

Create objects with shapes and points. Then can do stuff with querysets like:

Place.objects.filter(locations__within=london.shape).count()
gps_reading = Point(...)
Place.objects.all().distance(gps_reading).order_by('distance')
Place.objects.all().distance(gps_reading).order_by('distance')[0].geojson()

Many operations on shape - spacial relationships stuff.

Play with open datasets:

Previous topic

OpenDevelop

Next topic

Introducing Wagtail

This Page