SlideShare ist ein Scribd-Unternehmen logo
1 von 10
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 %}

Weitere ähnliche Inhalte

Ähnlich wie Geo django

GeoDjango & HTML5 Geolocation
GeoDjango & HTML5 GeolocationGeoDjango & HTML5 Geolocation
GeoDjango & HTML5 GeolocationJohn Paulett
 
2016 foss4 g track: developing and implementing spatial etl processes with...
2016 foss4 g track:  developing and implementing  spatial etl processes  with...2016 foss4 g track:  developing and implementing  spatial etl processes  with...
2016 foss4 g track: developing and implementing spatial etl processes with...GIS in the Rockies
 
Getting Started with Geospatial Data in MongoDB
Getting Started with Geospatial Data in MongoDBGetting Started with Geospatial Data in MongoDB
Getting Started with Geospatial Data in MongoDBMongoDB
 
Server side geo_tools_in_drupal_pnw_2012
Server side geo_tools_in_drupal_pnw_2012Server side geo_tools_in_drupal_pnw_2012
Server side geo_tools_in_drupal_pnw_2012Mack Hardy
 
Powerful geographic web framework GeoDjango
Powerful geographic web framework GeoDjangoPowerful geographic web framework GeoDjango
Powerful geographic web framework GeoDjangoOMEGA (@equal_001)
 
國民雲端架構 Django + GAE
國民雲端架構 Django + GAE國民雲端架構 Django + GAE
國民雲端架構 Django + GAEWinston Chen
 
Comparing Geospatial Implementation in MongoDB, Postgres, and Elastic
Comparing Geospatial Implementation in MongoDB, Postgres, and ElasticComparing Geospatial Implementation in MongoDB, Postgres, and Elastic
Comparing Geospatial Implementation in MongoDB, Postgres, and ElasticAntonios Giannopoulos
 
Getting Started with DrupalGap
Getting Started with DrupalGapGetting Started with DrupalGap
Getting Started with DrupalGapAlex S
 
Social Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDBSocial Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDBTakahiro Inoue
 
Let Grunt do the work, focus on the fun!
Let Grunt do the work, focus on the fun!Let Grunt do the work, focus on the fun!
Let Grunt do the work, focus on the fun!Dirk Ginader
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Djangofool2nd
 
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYCMike Dirolf
 
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...Citus Data
 
Getting Started with PostGIS
Getting Started with PostGISGetting Started with PostGIS
Getting Started with PostGISEDB
 
LinuxFest NW - Using Postgis To Add Some Spatial Flavor To Your App
LinuxFest NW - Using Postgis To Add Some Spatial Flavor To Your AppLinuxFest NW - Using Postgis To Add Some Spatial Flavor To Your App
LinuxFest NW - Using Postgis To Add Some Spatial Flavor To Your AppSteven Pousty
 

Ähnlich wie Geo django (20)

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

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 %}