Download presentation
Presentation is loading. Please wait.
1
Using GeoDjango for user participation in enriching web GIS systems Bo Zhao University of Florida July 15 th, 2009
2
Requests IDFunctionItem 1CGA assigned logins authentication & Permissions 2User login ability 3User uploads shape file to server shapefile uploading 4User specifies layer symbology spatial data customizing & management 5User populates Layer List tab 6User defines layer searchability 7User defines attributes returned 8Files that are generated if adding new layer Spatial Crud & related operation 9Files effected when layer is removed
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?
8
“Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design.”
9
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.
10
Design Pattern MTV Model Template View
11
Model
12
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.
13
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) );
14
Scary Quirky Language SQL knows no version control Can be dangerous DRY(Don’t Repeat Yourself.)
15
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()
16
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')
17
Template DRY(Don’t repeat yourself)
18
index.html {% block title %}{% endblock %} {% block content %}{% endblock %}
19
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}} …
20
dataLayer.js amTemplates.{{layer.name}} = ' ' + {% for item in layer.alias %} {% ifnotequal item.name 'geom' %} ' {{item.alias}} {{layer.left}}{{item.name}}{{layer.right}} ' + {% endifnotequal %} {% endfor %}' ';
21
View
22
URLs
23
/export.php?id=2&type=tilecache /upload.aspx?filetype=shapefile /export/tilecache/world/ /upload/shapefile/
24
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.*)$', 'django.views.static.serve', {'document_root': settings.MAPS_DIR, 'show_indexes': True}),
25
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})
26
App
27
world/ __init__.py admin.py models.py views.py templates/ layer_javascript.html layer_tilechache.html layer_mapfile.html
28
Hands-on demo
29
Thanks, any questions?
30
References http://www.djangoproject.com/ Justin Bronn, Web Applications for (Neo)Geographers with Deadlines, Oct. 2008 http://en.wikipedia.org/wiki/Object-relational_mapping
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.