Using GeoDjango for user participation in enriching web GIS systems Bo Zhao University of Florida...

30
Using GeoDjango for user participation in enriching web GIS systems Bo Zhao University of Florida July 15 th , 2009
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    224
  • download

    1

Transcript of Using GeoDjango for user participation in enriching web GIS systems Bo Zhao University of Florida...

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

Using GeoDjango for user participation in enriching web GIS systems

Bo ZhaoUniversity of Florida

July 15th, 2009

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

Requests

ID Function Item1 CGA assigned logins authentication &

Permissions2 User login ability3 User uploads shape file to server shapefile uploading4 User specifies layer symbology

spatial data customizing & management

5 User populates Layer List tab6 User defines layer searchability7 User defines attributes returned8 Files that are generated if adding new layer Spatial Crud & related

operation9 Files effected when layer is removed

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

So we need…

• Web Framework–PHP, ASP, Python, Java

• Geospatial libraries–Commercial Geospatial libaries, Open

Source libaries.

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

Why Python Matters?

• Glue Language• Dynamic script Language

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

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

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

Why Geodjango?

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

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

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

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.

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

Design Pattern

MTVModel Template View

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

Model

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

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.

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

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)

);

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

Scary Quirky Language

• SQL knows no version control

• Can be dangerous

• DRY(Don’t Repeat Yourself.)

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

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()

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

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')

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

Template

DRY(Don’t repeat yourself)

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

index.html

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

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

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

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

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>';

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

View

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

URLs

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

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

/export/tilecache/world//upload/shapefile/

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

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}),

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

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

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

App

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

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

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

Hands-on demo

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

Thanks, any questions?

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

References

• http://www.djangoproject.com/• Justin Bronn, Web Applications for (Neo)Geographers with

Deadlines, Oct. 2008• http://en.wikipedia.org/wiki/Object-relational_mapping