Django101 geodjango
Upcoming SlideShare
Loading in...5
×
 

Django101 geodjango

on

  • 1,585 views

A presentation at NTU OSS's Software Freedom Day.

A presentation at NTU OSS's Software Freedom Day.

Django 101 + GeoDjango. Why It Rocks!

Statistics

Views

Total Views
1,585
Views on SlideShare
1,583
Embed Views
2

Actions

Likes
2
Downloads
64
Comments
0

1 Embed 2

http://www.linkedin.com 2

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • * Today, I will be talking about the context in which jQuery Mobile, OpenLayers and GeoDjango are applied to help scientists, NGOs and governments make practical land use and conservation decisions.\n* I will illustrate the technology stack that we have used and talk briefly about the installation process for various GeoDjango dependencies on Mac OS X and Gentoo. \n* We usually use Gentoo on our servers. Yes I know, it’s nuts but that’s what Stefan, my colleague and CTO in Odeon, is proficient with, with over 11 years of experience.\n* My weapon of choice for my interface design and python work is my Macbook.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n\n
  • \n
  • \n
  • * So, this is where it begins. Species extinction in the old days have been simply correlated to Area loss using the Arrhenius equation.\n\n
  • * Here’s a graphical representation of the Arrhenius formula.\n* But of course, this is an outdated model and is wildly inaccurate.\n
  • * Modern conservation biologists and environmental scientists needed a more accurate prediction model\n* And they realise that land-use change on a mainland often creates landscapes that kind of look like islands of forests in an ocean of other land uses\n\n
  • * So this is what modern environmental scientists adopted as a working model.\n* The species-area model is often used by conservation biologists to predict biodiversity loss based upon forest loss\n* S(new) refers to species after an area of interest (also referred to as the “Total Landscape Area”) has been modified by human activity.\n* S(original) refers to the original number of species residing in the area.\n* Ditto for A\n* Z is an arbitrary number which varies according to various other conditions\n
  • However, there are 2 problems with this approach...\n#1: it assumes that the landscape matrix, the land uses in-between forest fragments, are completely inhospitable to any species, which obviously is not always true\n#2: it assumes that species are not affected by edge effects: deleterious effects on a forest fragment mediated by biophysical interactions near the interface between forest and matrix\nAlthough ecologists know that these assumptions are unrealistic, the species-area model continues to be used in assessments of biodiversity loss and in conservation planning. That was what motivated Koh et. al to develop a better tool \n\n
  • * Koh et al’s improved model addresses those shortcomings by accounting for how species respond to changes in composition & quality of the matrix, and it also accounts for effects of forest edges\n* These improvements allow for predictions of extinction risks that are specific to the landscape and the taxon of interest\n* Result? An improved accuracy in predicting how land use changes affect species diversity\n* This new model of predicting species response to land use changes has been accepted in Conservation Biology and Journal of Applied Ecology.\n\n
  • * This gives us a beautiful 3 dimensional graph as above.\n* So how does all these formulas relate to what we do with a GIS (Geographical Information System) application using GeoDjango?\n
  • * Area, of course. Calculating and defining the area is core to producing a reasonably accurate prediction estimate for policy making by governments, NGOs and the united nation.\n* 3rd largest island in the world. (after greenland and new guinea). Ref: http://en.wikipedia.org/wiki/List_of_islands_by_area\n*The island is divided among three countries: Brunei, Indonesia and Malaysia. Approximately 73% of the island is Indonesian territory. The Malaysian states of Sabah and Sarawak in the north occupy about 26% of the island. The sovereign state of Brunei, located on the north coast, comprises about 1% of Borneo's land area. It has the oldest rainforest in the world ahead of the Amazon rainforest inBrazil.\n
  • * 3rd largest island in the world. (after greenland and new guinea). Ref: http://en.wikipedia.org/wiki/List_of_islands_by_area\n* Specifically Kalimantan\n\n
  • * Loss of species, carbon emissions as a balance against employment and financial losses\n\n
  • * Here’s an example screen shot of polygons plotted by land owners in collaboration with environmental scientists.\n* We will go into the code details and what each of these polygons in a while.\n* But first, for those not familiar with terminologies and the basic concepts of Geographical Information Systems (GIS) software, I will provide a simple overview of the technology stack and associated libraries which you will need to install before getting started.\n
  • * The user interface\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • * “from django.db import models” is, of course, the usual way we import the django models class before writing our custom models.\n* For our model to contain GIS capabilities, like storing a geographical feature as an attribute, we will simply subclass from django.contrib.gis.db instead.\n\n
  • * add the geometry field you need. in this example, “geom” is our geometry field and it is a contains a MultiPolygon object using the datum WGS84 (i.e. 4326)\n* \n\n
  • * an interesting note about the geography attribute in a GeoDjango Field\n* polygons computed are assumed to be based on its 2D area.\n* by stating geography=True, areas computed will based on the ellipsoidal surface area, which gives a more accurate result at the expense of slightly poorer performance\n* in other words, you need to take a design decision on this trade-off.\n
  • * “from django.db import models” is, of course, the usual way we import the django models class before writing our custom models.\n* For our model to contain GIS capabilities, like storing a geographical feature as an attribute, we will simply subclass from django.contrib.gis.db instead.\n\n
  • \n\n
  • * represented by coordinates, specific to the projection or datum\n\n
  • * represented by coordinates, specific to the projection or datum\n\n
  • * represented by coordinates, specific to the projection or datum\n\n
  • * represented by coordinates, specific to the projection or datum\n\n
  • * represented by coordinates, specific to the projection or datum\n\n
  • * obviously :-) more than 1 or more Polygons stored in this field!\n\n
  • * A collection of different geometries can be stored in the field\n\n
  • * Using GeoDjango APIs with a model containing a MultiPolygonField!\n\n
  • \n\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • * Using GeoDjango APIs with a model containing a MultiPolygonField!\n\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • * Here, you can visualize what I just explained.\n
  • \n
  • \n
  • \n
  • \n\n
  • \n\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n\n
  • \n\n
  • \n
  • \n\n
  • \n\n
  • \n\n
  • \n\n
  • \n\n
  • \n\n
  • \n\n
  • \n
  • \n\n
  • * Here’s one of the excel file holding all the formulas our scientist collaborators have painstakingly built.\n
  • \n
  • * Translation of excel formulas and vbscript (ack!) to Python\n
  • \n\n
  • \n\n
  • \n\n
  • \n\n
  • \n\n
  • \n
  • \n
  • \n\n
  • \n
  • \n
  • \n
  • * GIS is a really fascinating topic in the world of Python and Django.\n* I am new to the topic and have much to learn!\n* I will be happy to link up with any geodjango developers out there to share our skills and knowledge.\n\n

Django101 geodjango Django101 geodjango Presentation Transcript

  • DJANGO 101 + GEODJANGO why it rocks
  • CALVIN CHENG www.calvinx.comwww.od-eon.com/blogs/calvin
  • Stefan Talpalaru Liviu Bogdan Chiributa That’s Me! :-)Odeon Consulting Group Odeon Consulting Group Odeon Consulting Group + ........
  • 1 Django Basics 2 GeoDjango 3 Why It Rocks
  • 1Django Basics
  • HTTP request (POST, GET) HTTP response urls.py (1)(url definitions) views.py (5) *.html (“controller”) (HTML template) (4) (2) (3) models.py DB agnostic ORM Actual Database
  • Pythonurls.pyviews.pytemplates (*.html)models.pysettings.py
  • Shared Hosting: WebfactionVPS: LinodeVPS: SlicehostCloud: Amazon EC2
  • 2GeoDjango
  • REDDCalculator.com (Beta) SEC (Closed Beta) LUC (Coming Soon!) ! ENVIRONMENTAL iTOOLS Spatially Explicit Scenario Analysis: Norway-Indonesia’s Forest Moratorium Species Extinction Calculator (SEC) Land Use Calculator (LUC)
  • SPECIES WHA--??Species Extinction Calculator (SEC)
  • 4% 4"&#()#*% 123# !"#$$%&()*"+,-./0" !"#$%
  • 3,000 2,250 Number of species 1,500 750 0 100 200 300 400 500 600 700 800 Area conserved (km sq) SPECIES-AREAMore habitats conserved (Area) = More fauna diversity (Species)
  • +)!) ) &,-! ) * "#$%$&( ( ) . &,- . ) "#$%$&( )
  • !"#$%&()3+(451"67(&/&012( !"#$%&()*+(,-.&(&/&012(
  • 0$1,23+4")56)."+4,2+"+*,7$2/+)$4"8$*.51 !"#$%&""(")*+,--,."+*"/#"+ N # $ % "i $ ! i i =1! - M ( ) #% "!$ j ) ) ) * &+, &+, j =1! - ) ) "#$%$&( "#$%$&(
  • MATRIX-CALIBRATED SPECIES-AREAAccounts for taxon-specific responses to different components of the landscape
  • EXAMPLE OF AN AREA?Conservation Forests, National Reserves etc Borneo 743,330 square kilometres
  • USERS AND USE-CASEConservation scientists and Land owners define areas which areconserved by plotting polygons on a map source (e.g. Google Maps).Areas which are slated for development are also marked.By quantifying area conservation goals (areas conserved before and afterdevelopment) and its impact on the loss of species, SEC is a tool whichhelps people make better trade-off decisions.
  • USERS AND USE-CASEREDDCalculator.com computes the socio-economic trade-offs andresults as a consequence of the Norway-Indonesia REDD+ Moratorium.
  • Layers & Features (‘Vector Objects’) jQuery &OpenLayers User Interface Map SourceKML GML WKT GeoJSON GeoRSS Others Data (serialized) GeoDjango Python Logic C/C++ Libraries w/ Python Bindings & Datastore
  • (2.7)
  • (trunk)
  • sudo -u postgres psql -d yourdatabase_name -f { ... }/postgis.sqlsudo -u postgres psql -d yourdatabase_name -f { ... }/postgis_comments.sqlsudo -u postgres psql -d yourdatabase_name -f { ... }/spatial_ref_sys.sql
  • sudo -u postgres psql -d yourdatabase_name -f /opt/local/var/macports/software/postgis/1.5.2_1+postgresql90/opt/local/share/postgresql90/contrib/postgis-1.5/postgis.sqlsudo -u postgres psql -d yourdatabase_name -f /opt/local/var/macports/software/postgis/1.5.2_1+postgresql90/opt/local/share/postgresql90/contrib/postgis-1.5/postgis_comments.sqlsudo -u postgres psql -d yourdatabase_name -f /opt/local/var/macports/software/postgis/1.5.2_1+postgresql90/opt/local/share/postgresql90/contrib/postgis-1.5/spatial_ref_sys.sql
  • Portage existsBut here’s a magical way - https://github.com/stefantalpalaru/dotfiles/tree/master/Gentoo/custom%20overlay/portage/dev-db/postgis -custom postgis ebuild modified by Stefanadd ebuild to local ‘overlay’ (a gentoo terminology)emerge postgisedit configuration file in /etc/conf.d/postgis and add in the postgresqldatabase that you need ‘postgis-enabled’emerge --config postgis
  • # settings.pyINSTALLED_APPS = ( # Core Django Apps django.contrib.contenttypes, django.contrib.auth, django.contrib.sessions, django.contrib.sites, django.contrib.admin, django.contrib.admindocs, django.contrib.flatpages, django.contrib.humanize, django.contrib.comments, django.contrib.markup, django.contrib.webdesign, django.contrib.sitemaps, django.contrib.gis, # Custom Apps for REDDCalculator.com updatemodel, location, areadata, # Generic and reusable apps for most projects south, django_cherrypy_odeon, misc, cron, notify, log, homepage, userprofile,)
  • # settings.pyDATABASES = { default: { ENGINE: django.contrib.gis.db.backends.postgis, ‘NAME’: ‘yourdatabase_name’, USER: yourdatabase_user’, PASSWORD: yourdatabase_password, HOST: your_ip_or_domain, }}
  • DjangoGeoModel & APIs
  • from django.contrib.gis.db import models
  • from django.contrib.gis.db import modelsclass Province(models.Model): name = models.CharField(max_length=256) name_long = models.CharField(max_length=256, null=True) island = models.ForeignKey(Location, null=True) geom = models.MultiPolygonField(srid=4326, null=True) objects = models.GeoManager()
  • from django.contrib.gis.db import modelsclass Province(models.Model): name = models.CharField(max_length=256) name_long = models.CharField(max_length=256,null=True) island = models.ForeignKey(Location, null=True) geom = models.MultiPolygonField(srid=4326, null=True, geography=True) objects = models.GeoManager()
  • What are the geometry fields available to us in django?
  • GEOS: OGC simple feature implementation PointField MultiPointField LineStringField MultiLineStringField PolygonField MultiPolygonField GeometryCollectionField
  • PointField (x, y)
  • MultiPointField((x1, y1), (x2, y2), (x3, y3))
  • LineStringField((x1, y1), (x2, y2), (x3, y3), (x4, y4))
  • MultiLineStringField(((x1, y1), (x2, y2), (x3, y3), (x4, y4)),((x5, y5), (x6, y6)))
  • PolygonField((x1, y1), (x2, y2), (x3, y3), (x4, y4), (x1, y1))
  • MultiPolygonField((x1, y1), (x2, y2), (x3, y3), (x4, y4), (x1, y1)), ((x5, y5), (x6, y6), (x7, y7), (x5, y5)))
  • GeometryCollectionField((x1, y1), (x2, y2), (x3, y3), (x4, y4), (x1, y1)), ((x5, y5), (x6, y6), (x7, y7)), ((x8, y8)))
  • Practical Example #1: Species Extinction Calculator
  • Practical Example #2: REDDCalculator.com
  • from django.contrib.gis.gdal import datasource, spatialreferencefrom django.contrib.gis.geos import multipolygon, geosgeometryshapefile = os.path.abspath(os.path.join(os.path.dirname(__file__),../../../../proj_public/media/files/giveshapefile.shp))ds = DataSource(shapefile)layer = ds[0] # Checked in Python shell that this has only 1 layer
  • from django.contrib.gis.db import modelsclass AreaData(models.Model): district = models.ForeignKey(District) # District is FKed to Province land_use = models.IntegerField(choices=VEGETATION_TYPES) allocation = models.IntegerField(choices= CHOICES[LAND_ALLOCATION]) intact = models.IntegerField() concession = models.CharField(max_length=255, blank=True) peat = models.CharField(max_length=255, blank=True) area = models.FloatField(help_text=hectares) fid = models.IntegerField() # ... and any other. geom = models.MultiPolygonField(srid=4326, null=True) objects = models.GeoManager()
  • area = AreaData.objects.get(fid = feature.fid)geometry_name = feature.geom.geom_type.namegeometry_object = feature.geom.transform(SpatialReference(4326),clone=True).geos# update our area object with the geom data from our shape fileif geometry_name == Polygon: # If our geometry object is a Polygon, we cast as MultiPolygon first geometry_object = MultiPolygon(geometry_object)area.geom = geometry_objectarea.save()
  • Geospatial Libraries
  • GEOS GDAL PROJ.4 Mapnik GeoIP
  • Utilities
  • LayerMapping./manage.py ogrinspect ./manage.py ogrinfo
  • ./manage.py ogrinspect and LayerMapping
  • $ ./manage.py ogrinspect ../proj_public/media/files/redd_data/kalimantan_universe.shp Location --srid=4326 --mapping# This is an auto-generated Django model module created by ogrinspect.from django.contrib.gis.db import modelsclass Location(models.Model): island = models.CharField(max_length=50) geom = models.MultiPolygonField(srid=4326) objects = models.GeoManager()# Auto-generated `LayerMapping` dictionary for Location modellocation_mapping = { island : island, geom : MULTIPOLYGON,}
  • # models.pyfrom django.contrib.gis.db import modelsclass Location(models.Model): island = models.CharField(max_length=50) geom = models.MultiPolygonField(srid=4326) objects = models.GeoManager()# Auto-generated `LayerMapping` dictionary for Kalimantan modellocation_mapping = { island : island, geom : MULTIPOLYGON,}
  • import osfrom django.contrib.gis.utils import LayerMappingfrom django.contrib.gis.gdal import DataSourcefrom location.models import Location, location_mappingshapefile = os.path.abspath(os.path.join(os.path.dirname(__file__),../../../../proj_public/media/files/kalimantan_universe.shp))ds = DataSource(shapefile)layer = ds[0] # Checked in Python shell that this has only 1 layerkalimantan = LayerMapping(Location, shapefile, location_mapping, transform = True, encoding=iso-8859-1)kalimantan.save(strict = True, verbose = True)
  • Get your Polygon showing up for Free! GeoAdmin FTW
  • from django.contrib.gis import admin as geoadminfrom location.models import Locationadmin.site.register(Location, geoadmin.GeoModelAdmin)
  • OpenLayers
  • “ OpenLayers is a pure JavaScript library for displaying map data in most modern web browsers, with no server-side dependencies. ”
  • jQuery(mobile)
  • “ jQuery Mobile is a Touch-Optimized Web Framework for Smartphones and Tablets. ”
  • + +
  • $(document).ready(function(){ $(#map_delete).hide() // Define a custom styles which will be used by our polygon layer var style = $.extend(true, {}, OpenLayers.Feature.Vector.style[default]) // get a copy of default style style.pointRadius = 15 var styleMap = new OpenLayers.StyleMap({"default": style}) // Define a custom style which will be used by our background layer var backgroundStyle = $.extend(true, {}, OpenLayers.Feature.Vector.style[default]) // get copy backgroundStyle.fillOpacity = "0.1" backgroundStyle.fillColor = "#000000" backgroundStyle.strokeColor = "#999999" var backgroundStyleMap = new OpenLayers.StyleMap({"default": backgroundStyle}) // Define our background layer backgroundLayer = new OpenLayers.Layer.Vector("Background Layer", {styleMap:backgroundStyleMap} )
  • // Define our vector layerpolygonLayer = new OpenLayers.Layer.Vector("Polygon Layer", {styleMap: styleMap})polygonLayer.events.on({ featureselected: show_delete_button, featureunselected: hide_delete_button})// Define our toolbar, panels and associated controls// pinch and zoom is defined in touch navigationvar touchNavigation = new OpenLayers.Control.TouchNavigation({ dragPanOptions: { interval: 100, enableKinetic: true }})// define our zoom panelvar zoomPanel = new OpenLayers.Control.ZoomPanel()// define our layer switchervar layerSwitcher = new OpenLayers.Control.LayerSwitcher()
  • // controlsdrawControl = new OpenLayers.Control.DrawFeature(polygonLayer, OpenLayers.Handler.Polygon, { displayClass: olControlDrawFeaturePolygon});selectControl = new OpenLayers.Control.SelectFeature(polygonLayer, { clickout: true });editControl = new OpenLayers.Control.ModifyFeature(polygonLayer, { selectControl: selectControl, vertexRenderIntent: temporary, displayClass: olControlModifyFeature});// define our custom control tool barvar toolbar = new OpenLayers.Control.Panel({displayClass: olControlEditingToolbar});toolbar.addControls([ //this control is just there to be able to deactivate the drawing tools and pan the map drawControl, editControl, new OpenLayers.Control({ displayClass: olControlNavigation })]);
  • // Define Map Layersvar gphy = new OpenLayers.Layer.Google("Google Physical", {type: google.maps.MapTypeId.TERRAIN});var gmap = new OpenLayers.Layer.Google("Google Streets", {numZoomLevels: 20});var ghyb = new OpenLayers.Layer.Google("Google Hybrid", {type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20});var gsat = new OpenLayers.Layer.Google("Google Satellite", {type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 20});// Feed the controls and layers defined above to our map objectmap = new OpenLayers.Map({ div: map, controls: [zoomPanel, touchNavigation, layerSwitcher, toolbar], layers: [ghyb, gphy, gmap, gsat, backgroundLayer, polygonLayer]})
  • // Google.v3 uses EPSG:900913 as projection, so we have to transform our coordinates mapProjection = map.getProjectionObject() map.setCenter(new OpenLayers.LonLat(map_center_lon, map_center_lat).transform(defaultProjection,mapProjection), map_zoom) // if theres a Total Landscape Area polygon, we will draw it on the backgroundLayer. if (background_coords_json){ var pointList = [] for (var i=0; i<background_coords_json.length; i++) { var point = new OpenLayers.Geometry.Point(background_coords_json[i][0], background_coords_json[i][1]) pointList.push(point.transform(defaultProjection, mapProjection)); } var linearRing = new OpenLayers.Geometry.LinearRing(pointList) totalAreaPolygon = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Polygon([linearRing])) backgroundLayer.addFeatures([totalAreaPolygon]) }
  • // draw the existing features into the polygonLayer var loaded_features = [] for (var i=0; i<list_of_coords_json.length; i++) { var pointList = [] for (var j=0; j<list_of_coords_json[i].length; j++) { var point = new OpenLayers.Geometry.Point(list_of_coords_json[i][j][0], list_of_coords_json[i][j][1]) pointList.push(point.transform(defaultProjection, mapProjection)); } var linearRing = new OpenLayers.Geometry.LinearRing(pointList) var polygonFeature = new OpenLayers.Feature.Vector(newOpenLayers.Geometry.Polygon([linearRing]), {fid: list_of_coords_ids_json[i]}) loaded_features.push(polygonFeature) } polygonLayer.addFeatures(loaded_features) polygonLayer.events.on({ "featuremodified": polygonSave, "featureadded": polygonSave, "vertexmodified": adjustVertex, "sketchstarted": adjustVertex, "sketchmodified": adjustVertex }) // confirmation dialog $(#project_map_delete_polygon_yes).click(delete_polygon)})/* END of $(document).ready() */
  • Possibilities
  • 1. Offline Maps for Field Usage 2. Remote Controlled UAV for data collection3. Crunch collected data and generate visualizations
  • Offline Maps for Field Usage
  • Layers & Features (Saved Locally, Syncing) NativeiOS/Android Native? Map Source (Local Map Tiles)KML GML WKT GeoJSON GeoRSS Others Data Transfer GeoDjango Python Logic C/C++ Libraries w/ Python Bindings & Datastore
  • The Problem with iOS MapKit FrameworkMKMapView class implements Google Maps API nativelyUnfortunately, Google Maps terms of use prevents us from cachingor storing map tiles locally
  • Alternative? https://github.com/route-me/route-meSupports many map sources - OpenStreetMap, MicrosoftVirtualEarth, CloudMade, OpenAerialMap, OpenCycleMap,SpatialCloudOpenStreetMap permits map tile caching and local storageSupports 2 offline, database-backed formats DBMap and MBTiles
  • A Comparison MKMapKit Route-Me Embed in iOS App YES YES Interaction YES YES Geolocalization YES YESDifferent Map Sources NO YES Offline Maps NO YES
  • The Problem with Android Google Maps FrameworkRenders Google Maps of courseSupport for alternative map sources is important
  • Alternative? https://github.com/camptocamp/android-gis.git Supports many map sources - OpenStreetMap, Microsoft VirtualEarth, CloudMade, OpenAerialMap, OpenCycleMap, SpatialCloud OpenStreetMap permits map tile caching and local storage Supports 2 offline, database-backed formats DBMap and MBTiles
  • Benefits Fast (obviously, since Map Tiles are stored locally) 100% Offline Stored as blob data for SQLite Client Access
  • Remote Controlled UAVs?
  • Collect Real Data => Effects on Landscape Change on Species e.g. obtain actual change in Forest Boundaries(instead of just predicting on map on current prediction tool)
  • Prediction is great.But we want real world data from primary forests!
  • http://www.youtube.com/watch?v=xjLXL72Medw&feature=autoshare
  • Crunch Collected Data => 2 possible approaches- Decoupled R and Python- Integrated Approach RPy Option
  • Decouple R and PythonPython retrieves data from django/postgresqlPython converts data shapefiles, images etcLaunches R given a *.r file with Scientist’s parametersR does the analysisPython does post-processing, projecting data etc
  • Integrated R & Python with RPy R and Python closely coupled RPy and RPy2 provides an interface to R Programming Language Python retrieves and organizes parameters from django/postgresql RPy module imported and R commands are executed within thePython script file
  • Getting a GPS fix via Satellite?
  • Mathematical Modelling, Scenario Analysis for Environmental Policies
  • REDDCalculator.com (Live) SEC (Closed Beta) LUC (Coming Soon!) ! ENVIRONMENTAL iTOOLS Spatially Explicit Scenario Analysis: Norway-Indonesia’s Forest Moratorium Species Extinction Calculator (SEC) Land Use Calculator (LUC)
  • Species Extinction Calculator and REDDCalculator:Mathematical Models and Formulas by Koh et. al are completelytranslated into PythonLand Use Calculator:Ditto. Coming Soon!
  • Key Takeaways
  • Mapnik is useful for rasterizing vector objects when we encounter largedatasets (in our case, 200 MB+ of protected areas in Kalimantan).(jQuery Mobile) Web App can benefit from optimization through djangocaching. To be done right after EuroPython! And besides jQuery MobileBeta 1 has just been released on Monday (20 June 2011)! :-)Usability and App Responsiveness can possibly be improved, Out-Field/Offline Benefits attainable, if we move interface elements and Map Tilesinto a native app (Android or iOS).
  • geography=True/False in a GeoDjango field2 ways to import data from a given GIS Shape File(1) LayerMapping(2) Direct Assignment to obj.geom attribute as mentioned.
  • “ Advancing Environmental Sciences: helping people, scientists, NGOs and governments make practical Land Area Usage and Conservation Decisions using jQuery (Mobile), OpenLayers and GeoDjango! ”
  • Gotchas?
  • Make sure Projections/Datum in your shape file source correspondswith your geometry field’s SRID and Map SourceUsing LayerMapping?transform = TrueDirectly creating or saving into an object’s attribute?geometry_object = feature.geom.transform(SpatialReference(4326),clone=True).geosarea.geom = geometry_objectarea.save()
  • 3Why It Rocks
  • MVC structureGreat community and reusable django apps (“modules”)Organize code in apps (“modules”)Coupled but replaceable user interface for device specific implementationsRich, powerful functionality from open source software and librariesFocus on people, skills, collaboration and creativity
  • Credits
  • + North-South FundProf. Koh Lian Pin Prof. Matthew Hansen Prof. Holly GibbsETH Zurich, Dept of Env Sciences South Dakota State University Stanford Dept of EnvironmentalNUS, Dept of Biological Sciences GIS Center of Excellence Earth System Sciences
  • Previous GeoDjango Presentations + my little contribution www.geodjango.org/presentations www.od-eon.com/presentations
  • Questions and Discussion welcome! calvin.cheng@od-eon.com