SlideShare a Scribd company logo
GeoDjango
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.
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__distance_lte=(pnt, D(km=5)))


• Gives you all those markers less than or equal the given
  distance
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 EXTENSION postgis


• Alternatively, you could create postgis
  template and createdb with it
  – $ createdb -T postgis_template <dbname>
Configuration
• settings.py
• Change database engine
  'ENGINE': 'django.contrib.gis.db.backends.postgis',

  Add to INSTALLED_APPS
    ‘django.contrib.gis’,
Configuration
• From django.contrib.gis.db import models
• class Marker(models.Model):
     name = models.CharField(‘name’)

     location = models.PointField(srid=4326)
     objects = models.GeoManager()
Admin.py setup
from django.contrib.gis import admin
from django.contrib.gis.geos import Point
from models import Marker

class 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)
Admin Map template
Google.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 %}

More Related Content

PDF
New York GeoConn 2015 Presentation
PPTX
MongoDB GeoSpatial Feature
PDF
Geospatial Enhancements in MongoDB 2.4
PPTX
Sydney Python Presentation (Feb 2010) - Tracking Large Metallic Objects / Goo...
PDF
日経平均上下予想Botを作った話
PPT
Geo-Django Python
PDF
Gmaps Railscamp2008
KEY
Ioannis Doxaras on GIS and Gmaps at 1st GTUG meetup Greece
New York GeoConn 2015 Presentation
MongoDB GeoSpatial Feature
Geospatial Enhancements in MongoDB 2.4
Sydney Python Presentation (Feb 2010) - Tracking Large Metallic Objects / Goo...
日経平均上下予想Botを作った話
Geo-Django Python
Gmaps Railscamp2008
Ioannis Doxaras on GIS and Gmaps at 1st GTUG meetup Greece

Similar to Geo django (20)

PDF
GeoDjango & HTML5 Geolocation
PDF
2016 foss4 g track: developing and implementing spatial etl processes with...
PPTX
Getting Started with Geospatial Data in MongoDB
PPT
Server side geo_tools_in_drupal_pnw_2012
PDF
Why Grails?
PDF
Why Grails
PDF
Powerful geographic web framework GeoDjango
PDF
GIS_Day_2016
KEY
國民雲端架構 Django + GAE
PDF
Comparing Geospatial Implementation in MongoDB, Postgres, and Elastic
PDF
Getting Started with DrupalGap
PDF
Social Data and Log Analysis Using MongoDB
PDF
Let Grunt do the work, focus on the fun!
PDF
Gae Meets Django
PDF
PostgreSQL 9.4
KEY
Inside PyMongo - MongoNYC
PDF
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
PDF
Getting Started with PostGIS
 
PPT
LinuxFest NW - Using Postgis To Add Some Spatial Flavor To Your App
PPT
Droid onwheels v2
GeoDjango & HTML5 Geolocation
2016 foss4 g track: developing and implementing spatial etl processes with...
Getting Started with Geospatial Data in MongoDB
Server side geo_tools_in_drupal_pnw_2012
Why Grails?
Why Grails
Powerful geographic web framework GeoDjango
GIS_Day_2016
國民雲端架構 Django + GAE
Comparing Geospatial Implementation in MongoDB, Postgres, and Elastic
Getting Started with DrupalGap
Social Data and Log Analysis Using MongoDB
Let Grunt do the work, focus on the fun!
Gae Meets Django
PostgreSQL 9.4
Inside PyMongo - MongoNYC
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Getting Started with PostGIS
 
LinuxFest NW - Using Postgis To Add Some Spatial Flavor To Your App
Droid onwheels v2
Ad

Geo django

  • 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. Wait.. How seamless is seamless? • Geospatially enabled admin site
  • 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. Setting up • Geospatial Libraries – PostGIS (requires PostgreSQL 9.1+) – GEOS – PROJ.4
  • 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. Configuration • settings.py • Change database engine 'ENGINE': 'django.contrib.gis.db.backends.postgis', Add to INSTALLED_APPS ‘django.contrib.gis’,
  • 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. Admin.py setup from django.contrib.gis import admin from django.contrib.gis.geos import Point from models import Marker class 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. Admin Map template Google.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 %}