1 / 30

Using GeoDjango for user participation in enriching web GIS systems

Using GeoDjango for user participation in enriching web GIS systems. Bo Zhao University of Florida July 15 th , 2009. Requests. So we need…. Web Framework PHP, ASP, Python , Java Geospatial libraries Commercial Geospatial libaries , Open Source libaries . Why Python Matters?.

kare
Download Presentation

Using GeoDjango for user participation in enriching web GIS systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using GeoDjango for user participation in enriching web GIS systems Bo Zhao University of Florida July 15th, 2009

  2. Requests

  3. So we need… • Web Framework • PHP, ASP, Python, Java • Geospatial libraries • Commercial Geospatial libaries, Open Source libaries.

  4. Why Python Matters? • Glue Language • Dynamic script Language

  5. Open Source Geospatial Libs • Pros • Open source is very competitive for geospatial server software • Reduced total cost of ownership • Possibility that you own your own software • Better preparation for computing trends. • Cons • Limited technical support. • Adding Patches or updating might render to crash. • Possibility that you own your own software

  6. Why Geodjango?

  7. “Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design.”

  8. Features of Django Framework • Object-relational mapper: Define your data models entirely in Python. You get a rich, dynamic database-access API, unnecessary to write SQL for query. • Template system: Use template language to separate design, content and Python code. • Automatic admin interface: Django does that automatically, and it's production-ready. • Elegant URL design: Design pretty URLs with no framework-specific limitations. Be as flexible as you like. • Cache system: cache frameworks for super performance. • Internationalization: Django has full support for multi-language applications.

  9. Design Pattern MTV Model Template View

  10. Model

  11. Object-relational mapping • Object-relational mapping (ORM) • a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages. • ORM creates, in effect, a "virtual object database" that can be used from within the programming language.

  12. CREATE TABLE “hug_layer_world" ( "id" serial NOT NULL PRIMARY KEY, "name" varchar(300) NOT NULL, "geom" geometry NOT NULL, CONSTRAINT hug_layer_world_pkey PRIMARY KEY (hug_fid), CONSTRAINT enforce_dims_geom CHECK (ndims(geom) = 2), CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = 'MULTIPOLYGON'::text OR geom IS NULL), CONSTRAINT enforce_srid_geom CHECK (srid(geom) = 4326) );

  13. Scary Quirky Language • SQL knows no version control • Can be dangerous • DRY(Don’t Repeat Yourself.)

  14. from django.contrib.gis.db import models class LAYERS(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=20) geom = models.MultiLineStringField(srid=4326) objects = models.GeoManager()

  15. SELECT "hug_layer_world"."id", "hug_layer_world".“name", "hug_layer_world".“geom" FROM ""hug_layer_world" WHERE "hug_layer_world"."name" = "China"; WORLD.objects.filter(title='China')

  16. Template DRY(Don’t repeat yourself)

  17. index.html <html> <head> <title> {% block title %}{% endblock %} </title> </head> <body> {% block content %}{% endblock %} </body> </html>

  18. tilecache.cfg [{{layer.name}}] url = {{layer.mf_url}} layers = {{layer.name}} spherical_mercator = {{layer.tc_spherical_mercator}} extension = {{layer.tc_extension}} metatile = {{layer.tc_metatile}} srs = EPSG:{{layer.tc_srs}} type = {{layer.tc_type}} searchable = {{layer.tc_searchable}} … …

  19. dataLayer.js amTemplates.{{layer.name}} = '<ul class="featureDetailList">' + {% for item in layer.alias %} {% ifnotequal item.name 'geom' %} '<li><label>{{item.alias}}</label><span> {{layer.left}}{{item.name}}{{layer.right}}</span></li>' + {% endifnotequal %} {% endfor %}'</ul>';

  20. View

  21. URLs

  22. /export.php?id=2&type=tilecache /upload.aspx?filetype=shapefile /export/tilecache/world/ /upload/shapefile/

  23. url.py • (r'^admin/upload/', 'upload_zipped_shapefiles.upload_zipfile'), • (r'^admin/export/$', 'export_config_files.index'), • (r'^databrowse/(.*)', databrowse.site.root), • (r'^map/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MAPS_DIR, 'show_indexes': True}),

  24. View functions def index(request): all_layers = LAYER.objects.all() all_maps = MAP.objects.all() return render_to_response('export.html', {'layers': all_layers, 'maps': all_maps, 'user': request.user})

  25. App

  26. world/ __init__.py admin.py models.py views.py templates/ layer_javascript.html layer_tilechache.html layer_mapfile.html

  27. Hands-on demo

  28. Thanks, any questions?

  29. References • http://www.djangoproject.com/ • Justin Bronn, Web Applications for (Neo)Geographers with Deadlines, Oct. 2008 • http://en.wikipedia.org/wiki/Object-relational_mapping

More Related