Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
GeoDjango
What is GeoDjango•   included contrib module for Django that turns it into a world-class geographic Web framework.• GeoDja...
Wait.. How seamless is seamless?• Geospatially enabled admin site
Wait.. How seamless is seamless?• GeoDjango adds spatial lookups to the Django ORM• Query = Marker.objects.filter(point__d...
Setting up• Geospatial Libraries  – PostGIS (requires PostgreSQL 9.1+)  – GEOS  – PROJ.4
Creating spatial database• For PostGIS 2 and PostgreSQL 9.1 +  – $ createdb <dbname>  – $ psql <dbname>  – > CREATE EXTENS...
Configuration• settings.py• Change database engine  ENGINE: django.contrib.gis.db.backends.postgis,  Add to INSTALLED_APPS...
Configuration• From django.contrib.gis.db import models• class Marker(models.Model):     name = models.CharField(‘name’)  ...
Admin.py setupfrom django.contrib.gis import adminfrom django.contrib.gis.geos import Pointfrom models import Markerclass ...
Admin Map templateGoogle.html{% extends "gis/admin/openlayers.html" %}{% block extrastyle %}{{ block.super }}<style type="...
Upcoming SlideShare
Loading in …5
×

Geo django

680 views

Published on

  • Be the first to comment

Geo django

  1. 1. GeoDjango
  2. 2. What is GeoDjango• included contrib module for Django that turns it into a world-class geographic Web framework.• GeoDjango makes working Geo Data in Django seamless.
  3. 3. Wait.. How seamless is seamless?• Geospatially enabled admin site
  4. 4. Wait.. How seamless is seamless?• GeoDjango adds spatial lookups to the Django ORM• Query = Marker.objects.filter(point__distance_lte=(pnt, D(km=5)))• Gives you all those markers less than or equal the given distance
  5. 5. Setting up• Geospatial Libraries – PostGIS (requires PostgreSQL 9.1+) – GEOS – PROJ.4
  6. 6. Creating spatial database• For PostGIS 2 and PostgreSQL 9.1 + – $ createdb <dbname> – $ psql <dbname> – > CREATE EXTENSION postgis• Alternatively, you could create postgis template and createdb with it – $ createdb -T postgis_template <dbname>
  7. 7. Configuration• settings.py• Change database engine ENGINE: django.contrib.gis.db.backends.postgis, Add to INSTALLED_APPS ‘django.contrib.gis’,
  8. 8. Configuration• From django.contrib.gis.db import models• class Marker(models.Model): name = models.CharField(‘name’) location = models.PointField(srid=4326) objects = models.GeoManager()
  9. 9. Admin.py setupfrom django.contrib.gis import adminfrom django.contrib.gis.geos import Pointfrom models import Markerclass GoogleAdmin(admin.OSMGeoAdmin): sgPoint = Point(103.8, 1.3667, srid=4326) sgPoint.transform(900913) default_lon, default_lat = sgPoint.coords default_zoom = 11 map_template = gis/admin/google.html extra_js =[https://maps.google.com/maps?file=api&v=3&sensor=false&callback=initialize]admin.site.register(MapPoint, GoogleAdmin)
  10. 10. Admin Map templateGoogle.html{% extends "gis/admin/openlayers.html" %}{% block extrastyle %}{{ block.super }}<style type="text/css">v:* {behavior:url(#default#VML);}</style>{% endblock %}{% block openlayers %}{% include "gis/admin/google.js" %}{% endblock %}Google.js{% extends "gis/admin/openlayers.js" %}{% block base_layer %}new OpenLayers.Layer.Google("Google Base Layer", { type: G_NORMAL_MAP, sphericalMercator : true});{% endblock %}

×