Permalink
Browse files

Update for PyCon-APAC, 2012.

This brings the code into line with Mapnik 2.0 and Django 1.4 and adds a
bit more explanation in the README about some things.
  • Loading branch information...
1 parent 2d217b6 commit cc424ef0f61564ba0a580ac2d1222d2628122b96 Malcolm Tredinnick committed Jun 9, 2012
Showing with 65 additions and 22 deletions.
  1. +38 −5 README.rst
  2. +15 −6 interface/urls.py
  3. +2 −2 map_server/island.xml
  4. +1 −1 map_server/map_factory.py
  5. +1 −1 map_server/wms.py
  6. +3 −2 map_urls.py
  7. +5 −5 settings.py
View
@@ -5,8 +5,10 @@ Maps of Imaginary Lands
Introduction
=============
-Supporting code and slides for a talk introducing customised usage of
-Django's GIS components, Mapnik and OpenLayers. Originally presented at DjangoCon-US, September 2010 (Portland, Oregon, USA) in a short form and then at Kiwi Pycon (Bay of Islands, New Zealand) in November, 2010.
+Supporting code and slides for a talk introducing customised usage of Django's
+GIS components, Mapnik and OpenLayers. Originally presented at DjangoCon-US,
+September 2010 (Portland, Oregon, USA) in a short form and then at Kiwi Pycon
+(Bay of Islands, New Zealand) in November, 2010 and PyCon-APAC in June, 2012.
Short Description
------------------
@@ -39,12 +41,31 @@ Some basic familiarity with Django's GIS features would be useful for this
talk, although it might also serve as a motivating introduction to trying
things out.
+Aside: Creating map graphics
+-----------------------------
+
+Over the years, a number of people have asked how I created the island map
+image for this presentation.
+
+The main graphic was done using the Gimp_, following tutorials at `The
+Cartographer's Guild`_ website. I have spent hours playing with their
+map-making tutorials and trying out different things.
+
+The shapefiles describing the island boundaries and paths and points of
+interest were creating in QGis_, a professional level tool that is highly accessible to amateurs and with a very supportive online community of tutorials and tips.
+
+.. _Gimp: http://http://www.gimp.org/
+.. _The Cartographer's Guild: http://www.cartographersguild.com/
+.. _QGis: http://www.qgis.org/
+
Setting up
===========
This code is intended as a small self-contained, executable example, written
with reasonably professional coding standards in mind.
+All the code here has been verified to run against Django 1.4 (as of June, 2012).
+
That being said, a few prerequisites need to be installed in order to run the
example. I am assuming you have worked through the ``django.contrib.gis``
tutorial_ and thus have all the necessary prerequisites installed. If you can
@@ -55,11 +76,18 @@ Secondly, you'll need to have Mapnik_ installed (and Mapnik's Python bindings).
Major Linux distributions will ship these as packages that won't require
anything more than a ``yum install ...`` or ``aptitude install...``. I've been
led to believe it isn't amazingly difficult to get the necessary pieces
-installed on a Mac OS X and Windows as well [*]_. If you can run the following
+installed on a Mac OS X and Windows as well [1]_. If you can run the following
at a Python prompt and no exception is raised, you have the necessary
components installed::
- >>> from mapnik import ogcserver
+ >>> from mapnik2 import ogcserver
+
+This assumes you are running mapnik-python version 2.0. If you are using an
+earlier version (0.7) of mapnik and mapnik-python, you will need to import
+``mapnik``, rather than ``mapnik2`` [2]_. There are obviously other differences
+between the earlier and later versions of mapnik, however, for the most part,
+things are forwards compatible and the code here will work without change once
+the import is correct.
.. _tutorial: http://docs.djangoproject.com/en/1.2/ref/contrib/gis/tutorial/
.. _Mapnik: http://mapnik.org/
@@ -140,6 +168,11 @@ Best of luck!
Malcolm Tredinnick
(Sydney, Australia)
-.. [*] I have no direct experience with either platform. However, a credible
+.. [1] I have no direct experience with either platform. However, a credible
source wrote to say that installing Mapnik and Python bindings on
Windows XP, SP2 was *"a breeze."*
+
+.. [2] In Mapnik 2.1, the Python module will again be called ``mapnik``. Then
+ ``mapnik2`` name was to allow 0.7 and 2.0 to be run in parallel for a
+ while.
+
View
@@ -1,12 +1,21 @@
-from django.conf.urls.defaults import * # pylint: disable-msg=W0401,W0614
-from django.views.generic.simple import direct_to_template
+from django.conf.urls.defaults import patterns, url
+from django.views import generic
from interface import views
+
+class TemplateView(generic.TemplateView):
+ template_name = "interface/simple.html"
+
+ def get_context_data(self, **kwargs):
+ context = super(TemplateView, self).get_context_data(**kwargs)
+ context["title"] = "Imaginary Island Map"
+ return context
+
+
urlpatterns = patterns('',
- ("^$", direct_to_template, {"template": "interface/simple.html",
- "extra_context": {"title": "Imaginary Island Map"}}),
- ("^tracks/$", views.tracks),
- ("^places/$", views.places),
+ url("^$", TemplateView.as_view()),
+ url("^tracks/$", views.tracks),
+ url("^places/$", views.places),
)
View
@@ -1,4 +1,4 @@
-<Map>
+<Map minimum-version="0.7.2">
<Datasource name="base-map">
<Parameter name="type">raster</Parameter>
<!-- File names (by default) are relative to this XML file's location,
@@ -13,7 +13,7 @@
<Style name="basic">
<Rule>
- <RasterSymbolizer />
+ <RasterSymbolizer/>
</Rule>
</Style>
@@ -7,7 +7,7 @@
import os
-from mapnik.ogcserver import WMS
+from mapnik2.ogcserver import WMS
MAPFILE_XML = os.path.join(os.path.dirname(__file__), "island.xml")
View
@@ -7,7 +7,7 @@
import os
import sys
-from mapnik.ogcserver.wsgi import WSGIApp
+from mapnik2.ogcserver.wsgi import WSGIApp
PORT = 8001
View
@@ -1,9 +1,8 @@
import os
from django.conf import settings
-from django.conf.urls.defaults import * # pylint: disable-msg=W0401,W0614
+from django.conf.urls.defaults import include, patterns
from django.contrib import admin
-from django.views.static import serve
admin.autodiscover()
@@ -13,6 +12,8 @@
)
if settings.DEV_MODE:
+ from django.views.static import serve
+
static_path = os.path.join(settings.PROJ_ROOT, "media")
urlpatterns += patterns("",
("^static_data/(.*)$", serve, {"document_root": static_path}),
View
@@ -12,10 +12,6 @@
'default': {
'ENGINE': "django.contrib.gis.db.backends.postgis",
'NAME': "imaginary_lands",
- 'USER': '',
- 'PASSWORD': '',
- 'HOST': '',
- 'PORT': '',
}
}
TIME_ZONE = None
@@ -25,7 +21,10 @@
MEDIA_ROOT = ''
MEDIA_URL = '/static_data/'
-ADMIN_MEDIA_PREFIX = '/media/'
+STATIC_URL = "/media/"
+STATICFILES_DIR = (
+ os.path.join(PROJ_ROOT, "media"),
+)
SECRET_KEY = '(okqqmuqmi_%10@ob3jn&@@s-qo(lnz9x0w=rc_9z)4jz0y+tl'
@@ -53,6 +52,7 @@
'django.contrib.messages',
'django.contrib.admin',
"django.contrib.gis",
+ "django.contrib.staticfiles",
"lands",
"adventure",
"interface",

0 comments on commit cc424ef

Please sign in to comment.