SlideShare a Scribd company logo
1 of 41
GeoDjango e HTML5

Lucio Grenzi

l.grenzi@gmail.com
Who am I?
• Delphi developer for 11 years
• Now freelance and Web developer
• Javascript addicted
    Nonantolando.blogspot.com
   https://plus.google.com/108943068354277861330
   http://it.linkedin.com/pub/lucio-grenzi/27/2bb/2a

                                                      Lucio Grenzi   2
                                    l.grenzi@gmail.com – Freelance
Agenda
•   HTML 5 geolocalization: the new parts
•   About GeoDjango
•   GIS data format troubles
•   GeoDjango api's
•   GeoDjango and Google Maps /
    OpenStreetMaps

                                                   Lucio Grenzi   3
                                 l.grenzi@gmail.com – Freelance
Once upon a time




                                Lucio Grenzi   4
              l.grenzi@gmail.com – Freelance
HTML 5 and Geolocation
• Supported by IE 9,
  Firefox, Safari, Chrome
• All the smartphone has a
  GPS or a Wifi network
  card
• Location based services

                                               Lucio Grenzi   5
                             l.grenzi@gmail.com – Freelance
HTML 5 Geolocation api's (1/3)
Example of requesting a potentially cached position.
  // Request a position. We accept positions whose age is not greater than 10 minutes. If the user
  // agent does not have a fresh enough cached position object, it will automatically
  // acquire a new one.
  navigator.geolocation.getCurrentPosition(successCallback,
                            errorCallback,
                            {maximumAge:600000});

  function successCallback(position) {
    // By using the 'maximumAge' option above, the position object is guaranteed to be at most 10
   // minutes old.
  }

  function errorCallback(error) {
    // Update a div element with error.message.
  }
                                                                                   Lucio Grenzi      6
                                                                 l.grenzi@gmail.com – Freelance
HTML 5 Geolocation api's (2/3)
function getLocationUpdate(){


    if(navigator.geolocation){
        // timeout 60 seconds
        var options = {timeout:60000};
        watchID = navigator.geolocation.watchPosition(showLocation,
                           errorHandler,
                           options);
    }else{
        alert("Sorry, browser does not support geolocation!");
    }
}
                                                                                   Lucio Grenzi   7
                                                                 l.grenzi@gmail.com – Freelance
HTML 5 Geolocation api's (3/3)
interface Position {                       interface Coordinates {
  readonly attribute Coordinates coords;     readonly attribute double latitude;
  readonly attribute DOMTimeStamp            readonly attribute double longitude;
   timestamp;                                readonly attribute double altitude;
 };                                          readonly attribute double accuracy;
                                             readonly attribute double altitudeAccuracy;
                                             readonly attribute double heading;
                                             readonly attribute double speed;
                                            };




                                                                          Lucio Grenzi     8
                                                        l.grenzi@gmail.com – Freelance
GeoDjango
GeoDjango intends to be a
 world-class   geographic
 Web framework.

Its goal is to make it as easy
   as possible to build GIS
   Web applications and
   harness the power of
   spatially enabled data.
                                                     Lucio Grenzi   9
                                   l.grenzi@gmail.com – Freelance
Install GeoDjango
• django.contrib.gis
• Spatial database
• Geospatial libraries




                                               Lucio Grenzi   10
                             l.grenzi@gmail.com – Freelance
Spatial database

Database     Library            Supported Versions Notes
             Requirements
PostgreSQL   GEOS, PROJ.4,      8.1+                 Requires PostGIS
             PostGIS
MySQL        GEOS               5.x                  limited functionality

Oracle       GEOS               10.2, 11             XE not supported

SQLite       GEOS, GDAL,        3.6.+                Requires SpatiaLite
             PROJ.4, SpatiaLite                      2.3+, pysqlite2 2.5+,
                                                     and Django 1.1.
                                                                 Lucio Grenzi   11
                                               l.grenzi@gmail.com – Freelance
Geospatial libraries
Program      Description              Required                    Supported Versions
GEOS         Geometry Engine          Yes                         3.3, 3.2, 3.1, 3.0
             Open Source
PROJ.4       Cartographic             Yes (PostgreSQL and         4.7, 4.6, 4.5, 4.4
             Projections library      SQLite only)
GDAL         Geospatial Data          No (but, required for       1.8, 1.7, 1.6, 1.5, 1.4
             Abstraction Library      SQLite)
GeoIP        IP-based geolocation     No                          1.4
             library
PostGIS      Spatial extensions for   Yes (PostgreSQL             1.5, 1.4, 1.3
             PostgreSQL               only)
SpatiaLite   Spatial extensions for   Yes (SQLite only)           3.0, 2.4, 2.3
             SQLite
                                                                       Lucio Grenzi         12
                                                     l.grenzi@gmail.com – Freelance
GIS problems
• The Earth is not like
  a ball!
• How to store data
  efficiently
  – Different vendor
    implementation


                                               Lucio Grenzi   13
                             l.grenzi@gmail.com – Freelance
GIS data formats
• Lots of GIS file formats:
  – Raster formats: DRG, GeoTIFF, ..
  – Vector formats: DXF, GeoJSON, KML, GML
  – http://en.wikipedia.org/wiki/GIS_file_formats




                                                       Lucio Grenzi   14
                                     l.grenzi@gmail.com – Freelance
ABC GeoDjango




                             Lucio Grenzi   15
           l.grenzi@gmail.com – Freelance
GeoDjango Model layer
A model is the single, definitive source of data
   about your data.
It contains the essential fields and behaviors of
   the data you’re storing. Generally, each model
   maps to a single database table.



                                                  Lucio Grenzi   16
                                l.grenzi@gmail.com – Freelance
GeoDjango Template layer
Django’s template language is designed to strike
  a balance between power and ease.
The Django template system provides tags which
  function similarly to some programming
  constructs – an if tag for boolean tests, a for
  tag for looping, etc. – but these are not simply
  executed as the corresponding Python code
                                                  Lucio Grenzi   17
                                l.grenzi@gmail.com – Freelance
GeoDjango View layer
A view function, or view for short, is simply a
  Python function that takes a Web request and
  returns a Web response. This response can be
  the HTML contents of a Web page, or a
  redirect, or a 404 error



                                                 Lucio Grenzi   18
                               l.grenzi@gmail.com – Freelance
GeoDjango Model API
Field type                        Field options


class GeometryField               srid
class PointField                  spatial_index
class LineStringField             dim
class PolygonField                geography
class MultiPointField             geography Type
class MultiLineStringField
class MultiPolygonField
GeometryCollectionField
class GeometryCollectionField
                                                                Lucio Grenzi   19
                                              l.grenzi@gmail.com – Freelance
GeoQuerySet API
• Measurement: distance,area, length, perimeter
• Relationship: centroid, envelop, point_on_surface
• Editor: force_rhr, reverse_geom, scale, snap_to_grid,
  transform(srid), translate
• Opertion: difference, intersection, sym_difference, union
• Output: geohash, geojson, gml, kml, svg
• Miscellaneous: mem_size, num_geom, num_points


                                                             Lucio Grenzi   20
                                           l.grenzi@gmail.com – Freelance
GeoQuerySet API
• Measurement: distance,area, length, perimeter

   GeoQuerySet.distance(geom, **kwargs)




                                                           Lucio Grenzi   21
                                         l.grenzi@gmail.com – Freelance
GeoQuerySet API
• Relationship: centroid, envelop, point_on_surface

  GeoQuerySet.envelope(**kwargs)




                                                            Lucio Grenzi   22
                                          l.grenzi@gmail.com – Freelance
GeoQuerySet API
• Editor: force_rhr, reverse_geom, scale, snap_to_grid,
  transform(srid), translate

  GeoQuerySet.transform(srid=4326, **kwargs)




                                                            Lucio Grenzi   23
                                          l.grenzi@gmail.com – Freelance
GeoQuerySet API
• Opertion: difference, intersection, sym_difference, union

 GeoQuerySet.intersection(geom)




                                                             Lucio Grenzi   24
                                           l.grenzi@gmail.com – Freelance
GeoQuerySet API
• Output: geohash, geojson, gml, kml, svg

 GeoQuerySet.svg(**kwargs)




                                                              Lucio Grenzi   25
                                            l.grenzi@gmail.com – Freelance
Google Maps license




http://www.google.com/intl/it_it/help/terms_maps.html
                                                         Lucio Grenzi   26
                                       l.grenzi@gmail.com – Freelance
OpenstreetMap recent licensing changes




  http://blog.openstreetmap.it/2012/04/01/cambio-licenza/
                                                        Lucio Grenzi   27
                                      l.grenzi@gmail.com – Freelance
GeoDjango & Google Maps




                                   Lucio Grenzi   28
                 l.grenzi@gmail.com – Freelance
GeoDjango & Google Maps: recipe
•   Web server
•   Python and GeoDjango
•   PostgreSQL (postgresql-9.1-postgis)
•   libgeos



                                                   Lucio Grenzi   29
                                 l.grenzi@gmail.com – Freelance
Step 1 : create db and a new django project
• createdb -U postgres -T template_postgis -O geouser
  geodatabase
• python manage.py syncdb
• django-admin.py startproject geodjangomaps
• Changes affect settings.py
DATABASES = { 'default': {
     'ENGINE' : 'django.contrib.gis.db.backends.postgis',
     'NAME': 'geodatabase',
     'USER': 'geouser',
     'PASSWORD': 'geopassword',
  }}
                                                                              Lucio Grenzi   30
                                                            l.grenzi@gmail.com – Freelance
Step 2 : Geospatial information
• Edit model.py in order to setup the spatial
  reference system
• Google Maps api use srid = 4126
name = models.CharField(max_length=32)
geometry = models.PointField(srid=4326)
objects = models.GeoManager()



                                                            Lucio Grenzi   31
                                          l.grenzi@gmail.com – Freelance
Step 3 : HTML page
<!DOCTYPE html>
<head>
  <script src="http://maps.google.com/maps?file=api&v=2&key=abcdefg" type="text/javascript"></
   script>
  </head>
<body onload="load()" onunload="GUnload()">
<span style=" font-family:Verdana; background-color:#95877f; cursor:default;"
   onclick="get_location();">Find me!</span>
<div id="map" style="width: 400px; height: 400px"></div></body>




                                                                                  Lucio Grenzi   32
                                                                l.grenzi@gmail.com – Freelance
Get Current position
<script language="javascript">
    var lat=50;
    var lon=-110;
    function load() {
      if (GBrowserIsCompatible()) {
       var map = new GMap2(document.getElementById("map"));
       map.setCenter(new GLatLng(lat, lon), 13);} }
    function map(position) {
       lat = position.coords.latitude;
       lon = position.coords.longitude;
       load(); }
    function get_location() { navigator.geolocation.getCurrentPosition(map);}
  </script>
                                                                                      Lucio Grenzi   33
                                                                    l.grenzi@gmail.com – Freelance
Record Location
class RecordLocation(webapp.RequestHandler):
 def post(self):
   session=SessionManager(self)
     if session.is_set():
    marker=Markers(lat=self.request.get('lat'),lon=self.request.get('lon'),user_id=self.request.get('u
    ser'))
     marker.put()
     self.response.out.write('<html><body>')
     self.response.out.write(" Location Updated<br/>")
     self.response.out.write('</body></html>')




                                                                                     Lucio Grenzi   34
                                                                   l.grenzi@gmail.com – Freelance
Generate Marker
class GenerateMarkers(webapp.RequestHandler):
   def get(self):
     session=SessionManager(self)
     if session.is_set():
         markers=db.GqlQuery("SELECT * FROM Markers")
         doc='<?xml version="1.0"?>'
         doc+='<markers>'
         for marker in markers:
            doc+='<marker '
            doc+='lat="'+marker.lat+'" '
            doc+='lon="'+marker.lon+'" '
            doc+='type="restaurant" '
            doc+='/>'
            doc+='</markers>'
         self.response.out.write(doc)


                                                                          Lucio Grenzi   35
                                                        l.grenzi@gmail.com – Freelance
Openlayer
<html>
 <head>
  <script src="http://openlayers.org/api/OpenLayers.js"></script>
  <script> var points = []; </script>
    <ul>
    {% for point in interesting_points %}
      <li>{{ point.name }} -- {{point.interestingness}}</li>
      <script>points.push({{point.geometry.geojson|safe}});</script>
     {% endfor %}
   </ul> </scrpit>
 </head>
<body onload="init()">
  Intersting Points.<br />
  <div id="map"></div>
 </body></html>


                                                                                   Lucio Grenzi   36
                                                                 l.grenzi@gmail.com – Freelance
Openlayer js script
<script type="text/javascript">
  var map, base_layer, kml;
  function init(){
     map = new OpenLayers.Map('map');
     base_layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
       "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );

         var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry");
          var point = new OpenLayers.Geometry.Point(-100.01, 55.78);
          var pointFeature = new OpenLayers.Feature.Vector(point,null,null);
          map.addLayer(vectorLayer);
          map.setCenter(new OpenLayers.LonLat(point.x, point.y), 5);
          vectorLayer.addFeatures([pointFeature]);
     }

</script>

                                                                                Lucio Grenzi   37
                                                              l.grenzi@gmail.com – Freelance
Openlayer django script
vectors = OpenLayers.Layer.Vector("Simple Geometry");

for (var i = 0; i < points.length; i++) {
      point = format.read(points[i])[0];
      point.attributes = {'type':'point'};
      vectors.addFeatures(point);
    }




                                                                          Lucio Grenzi   38
                                                        l.grenzi@gmail.com – Freelance
References
• http://www.geodjango.com
• http://invisibleroads.com/tutorials/geodjango-googlemaps-build.html
• http://code.google.com/p/geodjango-basic-apps/wiki/FOSS4GWorkshop




                                                                Lucio Grenzi   39
                                              l.grenzi@gmail.com – Freelance
Questions?




                               Lucio Grenzi   40
             l.grenzi@gmail.com – Freelance
Thank you




Creative Commons via tcmaker.org



                                                     Lucio Grenzi   41
                                   l.grenzi@gmail.com – Freelance

More Related Content

Viewers also liked

Django - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesDjango - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesMarkus Zapke-Gründemann
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework  for perfectionists with deadlinesDjango - The Web framework  for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesMarkus Zapke-Gründemann
 
Django mongodb -djangoday_
Django mongodb -djangoday_Django mongodb -djangoday_
Django mongodb -djangoday_WEBdeBS
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
Authentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCAuthentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCMindfire Solutions
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - ChiusuraWEBdeBS
 
The Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.pyThe Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.pyTzu-ping Chung
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia ContiniWEBdeBS
 
NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - AperturaWEBdeBS
 
Rabbitmq & Postgresql
Rabbitmq & PostgresqlRabbitmq & Postgresql
Rabbitmq & PostgresqlLucio Grenzi
 
라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘Jiho Lee
 

Viewers also liked (20)

Django - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesDjango - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
 
Digesting jQuery
Digesting jQueryDigesting jQuery
Digesting jQuery
 
Vim for Mere Mortals
Vim for Mere MortalsVim for Mere Mortals
Vim for Mere Mortals
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework  for perfectionists with deadlinesDjango - The Web framework  for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
 
PythonBrasil[8] closing
PythonBrasil[8] closingPythonBrasil[8] closing
PythonBrasil[8] closing
 
Django mongodb -djangoday_
Django mongodb -djangoday_Django mongodb -djangoday_
Django mongodb -djangoday_
 
PyClab.__init__(self)
PyClab.__init__(self)PyClab.__init__(self)
PyClab.__init__(self)
 
Website optimization
Website optimizationWebsite optimization
Website optimization
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
Authentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCAuthentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVC
 
EuroDjangoCon 2009 - Ein Rückblick
EuroDjangoCon 2009 - Ein RückblickEuroDjangoCon 2009 - Ein Rückblick
EuroDjangoCon 2009 - Ein Rückblick
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - Chiusura
 
2 × 3 = 6
2 × 3 = 62 × 3 = 6
2 × 3 = 6
 
The Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.pyThe Django Book Chapter 9 - Django Workshop - Taipei.py
The Django Book Chapter 9 - Django Workshop - Taipei.py
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
 
NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - Apertura
 
Bottle - Python Web Microframework
Bottle - Python Web MicroframeworkBottle - Python Web Microframework
Bottle - Python Web Microframework
 
Rabbitmq & Postgresql
Rabbitmq & PostgresqlRabbitmq & Postgresql
Rabbitmq & Postgresql
 
라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘
 
Html5 History-API
Html5 History-APIHtml5 History-API
Html5 History-API
 

Similar to Geodjango

Mapping, GIS and geolocating data in Java
Mapping, GIS and geolocating data in JavaMapping, GIS and geolocating data in Java
Mapping, GIS and geolocating data in JavaJoachim Van der Auwera
 
Mapping, GIS and geolocating data in Java @ JAX London
Mapping, GIS and geolocating data in Java @ JAX LondonMapping, GIS and geolocating data in Java @ JAX London
Mapping, GIS and geolocating data in Java @ JAX LondonJoachim Van der Auwera
 
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...JAX London
 
Developing Geospatial software with Python, Part 1
Developing Geospatial software with Python, Part 1Developing Geospatial software with Python, Part 1
Developing Geospatial software with Python, Part 1Paolo Corti
 
Foss4 g 2017-kansai-ryoo-kim
Foss4 g 2017-kansai-ryoo-kimFoss4 g 2017-kansai-ryoo-kim
Foss4 g 2017-kansai-ryoo-kimOSgeo Japan
 
Saving Money with Open Source GIS
Saving Money with Open Source GISSaving Money with Open Source GIS
Saving Money with Open Source GISbryanluman
 
Using Geoscript Groovy
Using Geoscript GroovyUsing Geoscript Groovy
Using Geoscript GroovyJared Erickson
 
Comparing Vocabularies for Representing Geographical Features and Their Geometry
Comparing Vocabularies for Representing Geographical Features and Their GeometryComparing Vocabularies for Representing Geographical Features and Their Geometry
Comparing Vocabularies for Representing Geographical Features and Their GeometryGhislain Atemezing
 
Geo2tag LBS platform training at FRUCT12
Geo2tag LBS platform training at FRUCT12Geo2tag LBS platform training at FRUCT12
Geo2tag LBS platform training at FRUCT12OSLL
 
New way for GIS Development(Gaia3D)
New way for  GIS Development(Gaia3D)New way for  GIS Development(Gaia3D)
New way for GIS Development(Gaia3D)slhead1
 
Android Developer Toolbox 2017
Android Developer Toolbox 2017Android Developer Toolbox 2017
Android Developer Toolbox 2017Shem Magnezi
 
Android dev toolbox - Shem Magnezi, WeWork
Android dev toolbox - Shem Magnezi, WeWorkAndroid dev toolbox - Shem Magnezi, WeWork
Android dev toolbox - Shem Magnezi, WeWorkDroidConTLV
 
Using python to analyze spatial data
Using python to analyze spatial dataUsing python to analyze spatial data
Using python to analyze spatial dataKudos S.A.S
 
Up and Running with Leaflet.js
Up and Running with Leaflet.jsUp and Running with Leaflet.js
Up and Running with Leaflet.jsPatrick McKinney
 
Pycon 2012 Taiwan
Pycon 2012 TaiwanPycon 2012 Taiwan
Pycon 2012 TaiwanDongpo Deng
 
那些年 Python 攻佔了 GIS / The Year Python Takes Over GIS
那些年 Python 攻佔了 GIS / The Year Python Takes Over GIS那些年 Python 攻佔了 GIS / The Year Python Takes Over GIS
那些年 Python 攻佔了 GIS / The Year Python Takes Over GISpycontw
 
Open Source GIS
Open Source GISOpen Source GIS
Open Source GISJoe Larson
 
Location based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tagLocation based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tagMicrosoft Mobile Developer
 

Similar to Geodjango (20)

Mapping, GIS and geolocating data in Java
Mapping, GIS and geolocating data in JavaMapping, GIS and geolocating data in Java
Mapping, GIS and geolocating data in Java
 
Mapping, GIS and geolocating data in Java @ JAX London
Mapping, GIS and geolocating data in Java @ JAX LondonMapping, GIS and geolocating data in Java @ JAX London
Mapping, GIS and geolocating data in Java @ JAX London
 
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...
 
Developing Geospatial software with Python, Part 1
Developing Geospatial software with Python, Part 1Developing Geospatial software with Python, Part 1
Developing Geospatial software with Python, Part 1
 
Foss4 g 2017-kansai-ryoo-kim
Foss4 g 2017-kansai-ryoo-kimFoss4 g 2017-kansai-ryoo-kim
Foss4 g 2017-kansai-ryoo-kim
 
Saving Money with Open Source GIS
Saving Money with Open Source GISSaving Money with Open Source GIS
Saving Money with Open Source GIS
 
Using Geoscript Groovy
Using Geoscript GroovyUsing Geoscript Groovy
Using Geoscript Groovy
 
Comparing Vocabularies for Representing Geographical Features and Their Geometry
Comparing Vocabularies for Representing Geographical Features and Their GeometryComparing Vocabularies for Representing Geographical Features and Their Geometry
Comparing Vocabularies for Representing Geographical Features and Their Geometry
 
Geo2tag LBS platform training at FRUCT12
Geo2tag LBS platform training at FRUCT12Geo2tag LBS platform training at FRUCT12
Geo2tag LBS platform training at FRUCT12
 
New way for GIS Development(Gaia3D)
New way for  GIS Development(Gaia3D)New way for  GIS Development(Gaia3D)
New way for GIS Development(Gaia3D)
 
Gdal introduction
Gdal introductionGdal introduction
Gdal introduction
 
Android Developer Toolbox 2017
Android Developer Toolbox 2017Android Developer Toolbox 2017
Android Developer Toolbox 2017
 
Android dev toolbox - Shem Magnezi, WeWork
Android dev toolbox - Shem Magnezi, WeWorkAndroid dev toolbox - Shem Magnezi, WeWork
Android dev toolbox - Shem Magnezi, WeWork
 
Using python to analyze spatial data
Using python to analyze spatial dataUsing python to analyze spatial data
Using python to analyze spatial data
 
Up and Running with Leaflet.js
Up and Running with Leaflet.jsUp and Running with Leaflet.js
Up and Running with Leaflet.js
 
Pycon 2012 Taiwan
Pycon 2012 TaiwanPycon 2012 Taiwan
Pycon 2012 Taiwan
 
那些年 Python 攻佔了 GIS / The Year Python Takes Over GIS
那些年 Python 攻佔了 GIS / The Year Python Takes Over GIS那些年 Python 攻佔了 GIS / The Year Python Takes Over GIS
那些年 Python 攻佔了 GIS / The Year Python Takes Over GIS
 
Open Source GIS
Open Source GISOpen Source GIS
Open Source GIS
 
Postgis for Enterprise
Postgis for EnterprisePostgis for Enterprise
Postgis for Enterprise
 
Location based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tagLocation based services for Nokia X and Nokia Asha using Geo2tag
Location based services for Nokia X and Nokia Asha using Geo2tag
 

More from WEBdeBS

Legal Pirlo
Legal PirloLegal Pirlo
Legal PirloWEBdeBS
 
Nodejsconf 2012
Nodejsconf 2012Nodejsconf 2012
Nodejsconf 2012WEBdeBS
 
Mockup, wireframe e visual: una breve introduzione
Mockup, wireframe e visual: una breve introduzioneMockup, wireframe e visual: una breve introduzione
Mockup, wireframe e visual: una breve introduzioneWEBdeBS
 
Djangoday lt 20120420
Djangoday lt 20120420Djangoday lt 20120420
Djangoday lt 20120420WEBdeBS
 
Unbit djangoday 20120419
Unbit djangoday 20120419Unbit djangoday 20120419
Unbit djangoday 20120419WEBdeBS
 
Virtualenv
VirtualenvVirtualenv
VirtualenvWEBdeBS
 
Iga workflow
Iga workflowIga workflow
Iga workflowWEBdeBS
 
PepperTweet - Project presentation Startup Weekend Brescia
PepperTweet - Project presentation Startup Weekend BresciaPepperTweet - Project presentation Startup Weekend Brescia
PepperTweet - Project presentation Startup Weekend BresciaWEBdeBS
 
Peppertweet - Presentazione Startup Weekend Brescia
Peppertweet - Presentazione Startup Weekend BresciaPeppertweet - Presentazione Startup Weekend Brescia
Peppertweet - Presentazione Startup Weekend BresciaWEBdeBS
 

More from WEBdeBS (10)

Legal Pirlo
Legal PirloLegal Pirlo
Legal Pirlo
 
Nodejsconf 2012
Nodejsconf 2012Nodejsconf 2012
Nodejsconf 2012
 
Mockup, wireframe e visual: una breve introduzione
Mockup, wireframe e visual: una breve introduzioneMockup, wireframe e visual: una breve introduzione
Mockup, wireframe e visual: una breve introduzione
 
Djangoday lt 20120420
Djangoday lt 20120420Djangoday lt 20120420
Djangoday lt 20120420
 
Unbit djangoday 20120419
Unbit djangoday 20120419Unbit djangoday 20120419
Unbit djangoday 20120419
 
Virtualenv
VirtualenvVirtualenv
Virtualenv
 
Fagungis
FagungisFagungis
Fagungis
 
Iga workflow
Iga workflowIga workflow
Iga workflow
 
PepperTweet - Project presentation Startup Weekend Brescia
PepperTweet - Project presentation Startup Weekend BresciaPepperTweet - Project presentation Startup Weekend Brescia
PepperTweet - Project presentation Startup Weekend Brescia
 
Peppertweet - Presentazione Startup Weekend Brescia
Peppertweet - Presentazione Startup Weekend BresciaPeppertweet - Presentazione Startup Weekend Brescia
Peppertweet - Presentazione Startup Weekend Brescia
 

Recently uploaded

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 

Recently uploaded (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 

Geodjango

  • 1. GeoDjango e HTML5 Lucio Grenzi l.grenzi@gmail.com
  • 2. Who am I? • Delphi developer for 11 years • Now freelance and Web developer • Javascript addicted Nonantolando.blogspot.com https://plus.google.com/108943068354277861330 http://it.linkedin.com/pub/lucio-grenzi/27/2bb/2a Lucio Grenzi 2 l.grenzi@gmail.com – Freelance
  • 3. Agenda • HTML 5 geolocalization: the new parts • About GeoDjango • GIS data format troubles • GeoDjango api's • GeoDjango and Google Maps / OpenStreetMaps Lucio Grenzi 3 l.grenzi@gmail.com – Freelance
  • 4. Once upon a time Lucio Grenzi 4 l.grenzi@gmail.com – Freelance
  • 5. HTML 5 and Geolocation • Supported by IE 9, Firefox, Safari, Chrome • All the smartphone has a GPS or a Wifi network card • Location based services Lucio Grenzi 5 l.grenzi@gmail.com – Freelance
  • 6. HTML 5 Geolocation api's (1/3) Example of requesting a potentially cached position. // Request a position. We accept positions whose age is not greater than 10 minutes. If the user // agent does not have a fresh enough cached position object, it will automatically // acquire a new one. navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {maximumAge:600000}); function successCallback(position) { // By using the 'maximumAge' option above, the position object is guaranteed to be at most 10 // minutes old. } function errorCallback(error) { // Update a div element with error.message. } Lucio Grenzi 6 l.grenzi@gmail.com – Freelance
  • 7. HTML 5 Geolocation api's (2/3) function getLocationUpdate(){ if(navigator.geolocation){ // timeout 60 seconds var options = {timeout:60000}; watchID = navigator.geolocation.watchPosition(showLocation, errorHandler, options); }else{ alert("Sorry, browser does not support geolocation!"); } } Lucio Grenzi 7 l.grenzi@gmail.com – Freelance
  • 8. HTML 5 Geolocation api's (3/3) interface Position { interface Coordinates { readonly attribute Coordinates coords; readonly attribute double latitude; readonly attribute DOMTimeStamp readonly attribute double longitude; timestamp; readonly attribute double altitude; }; readonly attribute double accuracy; readonly attribute double altitudeAccuracy; readonly attribute double heading; readonly attribute double speed; }; Lucio Grenzi 8 l.grenzi@gmail.com – Freelance
  • 9. GeoDjango GeoDjango intends to be a world-class geographic Web framework. Its goal is to make it as easy as possible to build GIS Web applications and harness the power of spatially enabled data. Lucio Grenzi 9 l.grenzi@gmail.com – Freelance
  • 10. Install GeoDjango • django.contrib.gis • Spatial database • Geospatial libraries Lucio Grenzi 10 l.grenzi@gmail.com – Freelance
  • 11. Spatial database Database Library Supported Versions Notes Requirements PostgreSQL GEOS, PROJ.4, 8.1+ Requires PostGIS PostGIS MySQL GEOS 5.x limited functionality Oracle GEOS 10.2, 11 XE not supported SQLite GEOS, GDAL, 3.6.+ Requires SpatiaLite PROJ.4, SpatiaLite 2.3+, pysqlite2 2.5+, and Django 1.1. Lucio Grenzi 11 l.grenzi@gmail.com – Freelance
  • 12. Geospatial libraries Program Description Required Supported Versions GEOS Geometry Engine Yes 3.3, 3.2, 3.1, 3.0 Open Source PROJ.4 Cartographic Yes (PostgreSQL and 4.7, 4.6, 4.5, 4.4 Projections library SQLite only) GDAL Geospatial Data No (but, required for 1.8, 1.7, 1.6, 1.5, 1.4 Abstraction Library SQLite) GeoIP IP-based geolocation No 1.4 library PostGIS Spatial extensions for Yes (PostgreSQL 1.5, 1.4, 1.3 PostgreSQL only) SpatiaLite Spatial extensions for Yes (SQLite only) 3.0, 2.4, 2.3 SQLite Lucio Grenzi 12 l.grenzi@gmail.com – Freelance
  • 13. GIS problems • The Earth is not like a ball! • How to store data efficiently – Different vendor implementation Lucio Grenzi 13 l.grenzi@gmail.com – Freelance
  • 14. GIS data formats • Lots of GIS file formats: – Raster formats: DRG, GeoTIFF, .. – Vector formats: DXF, GeoJSON, KML, GML – http://en.wikipedia.org/wiki/GIS_file_formats Lucio Grenzi 14 l.grenzi@gmail.com – Freelance
  • 15. ABC GeoDjango Lucio Grenzi 15 l.grenzi@gmail.com – Freelance
  • 16. GeoDjango Model layer A model is the single, definitive source of data about your data. It contains the essential fields and behaviors of the data you’re storing. Generally, each model maps to a single database table. Lucio Grenzi 16 l.grenzi@gmail.com – Freelance
  • 17. GeoDjango Template layer Django’s template language is designed to strike a balance between power and ease. The Django template system provides tags which function similarly to some programming constructs – an if tag for boolean tests, a for tag for looping, etc. – but these are not simply executed as the corresponding Python code Lucio Grenzi 17 l.grenzi@gmail.com – Freelance
  • 18. GeoDjango View layer A view function, or view for short, is simply a Python function that takes a Web request and returns a Web response. This response can be the HTML contents of a Web page, or a redirect, or a 404 error Lucio Grenzi 18 l.grenzi@gmail.com – Freelance
  • 19. GeoDjango Model API Field type Field options class GeometryField srid class PointField spatial_index class LineStringField dim class PolygonField geography class MultiPointField geography Type class MultiLineStringField class MultiPolygonField GeometryCollectionField class GeometryCollectionField Lucio Grenzi 19 l.grenzi@gmail.com – Freelance
  • 20. GeoQuerySet API • Measurement: distance,area, length, perimeter • Relationship: centroid, envelop, point_on_surface • Editor: force_rhr, reverse_geom, scale, snap_to_grid, transform(srid), translate • Opertion: difference, intersection, sym_difference, union • Output: geohash, geojson, gml, kml, svg • Miscellaneous: mem_size, num_geom, num_points Lucio Grenzi 20 l.grenzi@gmail.com – Freelance
  • 21. GeoQuerySet API • Measurement: distance,area, length, perimeter GeoQuerySet.distance(geom, **kwargs) Lucio Grenzi 21 l.grenzi@gmail.com – Freelance
  • 22. GeoQuerySet API • Relationship: centroid, envelop, point_on_surface GeoQuerySet.envelope(**kwargs) Lucio Grenzi 22 l.grenzi@gmail.com – Freelance
  • 23. GeoQuerySet API • Editor: force_rhr, reverse_geom, scale, snap_to_grid, transform(srid), translate GeoQuerySet.transform(srid=4326, **kwargs) Lucio Grenzi 23 l.grenzi@gmail.com – Freelance
  • 24. GeoQuerySet API • Opertion: difference, intersection, sym_difference, union GeoQuerySet.intersection(geom) Lucio Grenzi 24 l.grenzi@gmail.com – Freelance
  • 25. GeoQuerySet API • Output: geohash, geojson, gml, kml, svg GeoQuerySet.svg(**kwargs) Lucio Grenzi 25 l.grenzi@gmail.com – Freelance
  • 26. Google Maps license http://www.google.com/intl/it_it/help/terms_maps.html Lucio Grenzi 26 l.grenzi@gmail.com – Freelance
  • 27. OpenstreetMap recent licensing changes http://blog.openstreetmap.it/2012/04/01/cambio-licenza/ Lucio Grenzi 27 l.grenzi@gmail.com – Freelance
  • 28. GeoDjango & Google Maps Lucio Grenzi 28 l.grenzi@gmail.com – Freelance
  • 29. GeoDjango & Google Maps: recipe • Web server • Python and GeoDjango • PostgreSQL (postgresql-9.1-postgis) • libgeos Lucio Grenzi 29 l.grenzi@gmail.com – Freelance
  • 30. Step 1 : create db and a new django project • createdb -U postgres -T template_postgis -O geouser geodatabase • python manage.py syncdb • django-admin.py startproject geodjangomaps • Changes affect settings.py DATABASES = { 'default': { 'ENGINE' : 'django.contrib.gis.db.backends.postgis', 'NAME': 'geodatabase', 'USER': 'geouser', 'PASSWORD': 'geopassword', }} Lucio Grenzi 30 l.grenzi@gmail.com – Freelance
  • 31. Step 2 : Geospatial information • Edit model.py in order to setup the spatial reference system • Google Maps api use srid = 4126 name = models.CharField(max_length=32) geometry = models.PointField(srid=4326) objects = models.GeoManager() Lucio Grenzi 31 l.grenzi@gmail.com – Freelance
  • 32. Step 3 : HTML page <!DOCTYPE html> <head> <script src="http://maps.google.com/maps?file=api&v=2&key=abcdefg" type="text/javascript"></ script> </head> <body onload="load()" onunload="GUnload()"> <span style=" font-family:Verdana; background-color:#95877f; cursor:default;" onclick="get_location();">Find me!</span> <div id="map" style="width: 400px; height: 400px"></div></body> Lucio Grenzi 32 l.grenzi@gmail.com – Freelance
  • 33. Get Current position <script language="javascript"> var lat=50; var lon=-110; function load() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map")); map.setCenter(new GLatLng(lat, lon), 13);} } function map(position) { lat = position.coords.latitude; lon = position.coords.longitude; load(); } function get_location() { navigator.geolocation.getCurrentPosition(map);} </script> Lucio Grenzi 33 l.grenzi@gmail.com – Freelance
  • 34. Record Location class RecordLocation(webapp.RequestHandler): def post(self): session=SessionManager(self) if session.is_set(): marker=Markers(lat=self.request.get('lat'),lon=self.request.get('lon'),user_id=self.request.get('u ser')) marker.put() self.response.out.write('<html><body>') self.response.out.write(" Location Updated<br/>") self.response.out.write('</body></html>') Lucio Grenzi 34 l.grenzi@gmail.com – Freelance
  • 35. Generate Marker class GenerateMarkers(webapp.RequestHandler): def get(self): session=SessionManager(self) if session.is_set(): markers=db.GqlQuery("SELECT * FROM Markers") doc='<?xml version="1.0"?>' doc+='<markers>' for marker in markers: doc+='<marker ' doc+='lat="'+marker.lat+'" ' doc+='lon="'+marker.lon+'" ' doc+='type="restaurant" ' doc+='/>' doc+='</markers>' self.response.out.write(doc) Lucio Grenzi 35 l.grenzi@gmail.com – Freelance
  • 36. Openlayer <html> <head> <script src="http://openlayers.org/api/OpenLayers.js"></script> <script> var points = []; </script> <ul> {% for point in interesting_points %} <li>{{ point.name }} -- {{point.interestingness}}</li> <script>points.push({{point.geometry.geojson|safe}});</script> {% endfor %} </ul> </scrpit> </head> <body onload="init()"> Intersting Points.<br /> <div id="map"></div> </body></html> Lucio Grenzi 36 l.grenzi@gmail.com – Freelance
  • 37. Openlayer js script <script type="text/javascript"> var map, base_layer, kml; function init(){ map = new OpenLayers.Map('map'); base_layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ); var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry"); var point = new OpenLayers.Geometry.Point(-100.01, 55.78); var pointFeature = new OpenLayers.Feature.Vector(point,null,null); map.addLayer(vectorLayer); map.setCenter(new OpenLayers.LonLat(point.x, point.y), 5); vectorLayer.addFeatures([pointFeature]); } </script> Lucio Grenzi 37 l.grenzi@gmail.com – Freelance
  • 38. Openlayer django script vectors = OpenLayers.Layer.Vector("Simple Geometry"); for (var i = 0; i < points.length; i++) { point = format.read(points[i])[0]; point.attributes = {'type':'point'}; vectors.addFeatures(point); } Lucio Grenzi 38 l.grenzi@gmail.com – Freelance
  • 39. References • http://www.geodjango.com • http://invisibleroads.com/tutorials/geodjango-googlemaps-build.html • http://code.google.com/p/geodjango-basic-apps/wiki/FOSS4GWorkshop Lucio Grenzi 39 l.grenzi@gmail.com – Freelance
  • 40. Questions? Lucio Grenzi 40 l.grenzi@gmail.com – Freelance
  • 41. Thank you Creative Commons via tcmaker.org Lucio Grenzi 41 l.grenzi@gmail.com – Freelance