2006-05-30 21:58:22 +00:00
|
|
|
# $Id$
|
|
|
|
|
|
|
|
Mapnik OGC Server
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
|
|
Introduction
|
|
|
|
------------
|
|
|
|
|
2008-11-15 01:24:19 +00:00
|
|
|
Mapnik provides a server package to allow the publishing of maps
|
2006-05-30 21:58:22 +00:00
|
|
|
through the open and standard WMS interface published by the Open Geospatial
|
2009-03-28 01:51:59 +00:00
|
|
|
Consortium (OGC). It is in implemented in Python, around the core Mapnik C++
|
2006-05-30 21:58:22 +00:00
|
|
|
library.
|
|
|
|
|
2009-03-31 22:23:18 +00:00
|
|
|
This is the very first implementation of a WMS for Mapnik. Although inital
|
|
|
|
testing seems to suggest it works well, there may be bugs, and it lacks some
|
|
|
|
useful features. Comments, contributions, and requests for help should all be
|
|
|
|
directed to the Mapnik mailing list.
|
|
|
|
|
2006-05-30 21:58:22 +00:00
|
|
|
|
2009-03-28 01:51:59 +00:00
|
|
|
Features
|
|
|
|
--------
|
2006-05-30 21:58:22 +00:00
|
|
|
|
|
|
|
- WMS 1.1.1 and 1.3.0
|
2009-03-28 01:51:59 +00:00
|
|
|
- CGI/FastCGI, WSGI, mod_python
|
2007-01-25 02:07:00 +00:00
|
|
|
- Supports all 3 requests: GetCapabilities, GetMap and GetFeatureInfo
|
2006-05-30 21:58:22 +00:00
|
|
|
- JPEG/PNG output
|
|
|
|
- XML/INIMAGE/BLANK error handling
|
2006-07-23 19:50:52 +00:00
|
|
|
- Multiple named styles support
|
2006-10-19 01:25:24 +00:00
|
|
|
- Reprojection support
|
|
|
|
- Supported layer metadata: title, abstract
|
2009-03-31 22:23:18 +00:00
|
|
|
- Ability to request all layers with LAYERS=__all__
|
2009-03-28 01:51:59 +00:00
|
|
|
|
|
|
|
|
2009-03-31 22:23:18 +00:00
|
|
|
Caveats
|
2009-03-28 01:51:59 +00:00
|
|
|
----------------
|
|
|
|
- GetFeatureInfo supports text/plain output only
|
|
|
|
- PNG256(8-bit PNG not yet supported)
|
|
|
|
- CGI/FastCGI interface needs to be able to write to tempfile.gettempdir() (most likely "/tmp")
|
2009-03-31 22:23:18 +00:00
|
|
|
- Need to be further evaluated for thread safety
|
2006-05-30 21:58:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
Dependencies
|
|
|
|
------------
|
|
|
|
|
|
|
|
Please properly install the following before proceeding further:
|
|
|
|
|
2009-03-28 01:51:59 +00:00
|
|
|
- Mapnik python bindings (which will also install the `ogcserver` module code)
|
2006-05-30 21:58:22 +00:00
|
|
|
- lxml (http://codespeak.net/lxml/)
|
|
|
|
- PIL (http://www.pythonware.com/products/pil)
|
2009-03-28 01:51:59 +00:00
|
|
|
|
|
|
|
For the CGI/FastCGI interface also install:
|
|
|
|
|
|
|
|
- jonpy (http://jonpy.sourceforge.net/)
|
2006-05-30 21:58:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
Installation
|
|
|
|
------------
|
|
|
|
|
2009-06-29 00:11:14 +00:00
|
|
|
- The OGC Server uses the Mapnik interface to the Proj.4 library for projection support
|
2009-03-31 22:23:18 +00:00
|
|
|
and depends on integer EPSG codes. Confirm that you have installed Proj.4 with
|
2009-03-28 01:51:59 +00:00
|
|
|
all necessary data files (http://trac.osgeo.org/proj/wiki/FAQ) and have added any custom
|
2009-06-29 00:11:14 +00:00
|
|
|
projections to the 'epsg' file usually located at '/usr/local/share/proj/epsg'.
|
2009-03-28 01:51:59 +00:00
|
|
|
|
|
|
|
- Test that the server code is available and installed properly by importing it within a
|
|
|
|
python interpreter::
|
|
|
|
|
|
|
|
>>> from mapnik import ogcserver
|
|
|
|
>>> # no error means proper installation
|
2006-05-30 21:58:22 +00:00
|
|
|
|
2009-03-31 22:23:18 +00:00
|
|
|
- There is a sample python script called "wms.py" in the utils/ogcserver folder of the
|
2009-03-28 01:51:59 +00:00
|
|
|
Mapnik source code that will work for both CGI and FastCGI operations. Where to place it
|
2009-03-31 22:23:18 +00:00
|
|
|
will depend on your server choice and configuration and is beyond this documentation.
|
|
|
|
For information on FastCGI go to http://www.fastcgi.com/.
|
2006-05-30 21:58:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
Configuring the server
|
|
|
|
----------------------
|
|
|
|
|
2009-04-01 18:37:05 +00:00
|
|
|
- You will need to create two simple python scripts:
|
2009-03-31 22:23:18 +00:00
|
|
|
|
|
|
|
1) The web-accessible python script ('wms.py') which will import the
|
|
|
|
ogcserver module code and associate itself with the 'ogcserver.conf'
|
|
|
|
configuration file. The code of this script will depend upon whether
|
|
|
|
you deploy the server as cgi/fastcgi/wsgi/mod_python. See the Mapnik
|
|
|
|
Community Wiki for examples: http://trac.mapnik.org/wiki/OgcServer and
|
|
|
|
see the cgi sample in the /utils/ogcserver folder.
|
|
|
|
|
|
|
|
2) A 'map_factory' script which loads your layers and styles. Samples of this
|
|
|
|
script can be found below.
|
|
|
|
|
2006-05-30 21:58:22 +00:00
|
|
|
|
2009-04-01 18:37:05 +00:00
|
|
|
- Next you need to edit the ogcserver.conf file to:
|
2006-05-30 21:58:22 +00:00
|
|
|
|
2009-03-31 22:23:18 +00:00
|
|
|
1) Point to the 'map_factory' script by using the "module" parameter
|
|
|
|
|
|
|
|
2) Fill out further settings for the server.
|
|
|
|
|
|
|
|
Edit the configuration file to your liking, the comments within the file will
|
2009-06-29 00:11:14 +00:00
|
|
|
help you further. Be sure to, at the very minimum, edit the "module"
|
|
|
|
parameter. The server will not work without setting it properly first.
|
2006-05-30 21:58:22 +00:00
|
|
|
|
|
|
|
|
2009-03-31 22:23:18 +00:00
|
|
|
Defining Layers and Styles
|
|
|
|
--------------------------
|
2006-05-30 21:58:22 +00:00
|
|
|
|
2009-03-31 22:23:18 +00:00
|
|
|
The ogcserver obviously needs layers to publish and styles for how to display those layers.
|
2006-05-30 21:58:22 +00:00
|
|
|
|
2009-06-29 00:11:14 +00:00
|
|
|
You create your layers and styles in the 'map_factory' script.
|
2009-03-31 22:23:18 +00:00
|
|
|
|
|
|
|
For now this can be done by either loading an XML mapfile inside that script using the
|
|
|
|
'loadXML()' function or by writing your layers and styles in python code, or both.
|
|
|
|
|
2009-06-29 00:11:14 +00:00
|
|
|
If you load your layers and styles using an existing XML mapfile the 'map_factory' module
|
|
|
|
should look like::
|
2006-05-30 21:58:22 +00:00
|
|
|
|
2008-11-15 01:24:19 +00:00
|
|
|
from mapnik.ogcserver.WMS import BaseWMSFactory
|
|
|
|
|
|
|
|
class WMSFactory(BaseWMSFactory):
|
2009-03-31 22:23:18 +00:00
|
|
|
def __init__(self):
|
|
|
|
BaseWMSFactory.__init__(self)
|
2009-06-29 00:11:14 +00:00
|
|
|
self.loadXML('/full/path/to/mapfile.xml')
|
2009-03-31 22:23:18 +00:00
|
|
|
self.finalize()
|
|
|
|
|
2009-06-29 00:11:14 +00:00
|
|
|
Or if you want to define your layers and styles in pure python you might
|
2009-03-31 22:23:18 +00:00
|
|
|
have a 'map_factory' more like::
|
|
|
|
|
|
|
|
from mapnik.ogcserver.WMS import BaseWMSFactory
|
|
|
|
from mapnik import *
|
|
|
|
|
|
|
|
SHAPEFILE = '/path/to/world_borders.shp'
|
|
|
|
PROJ4_STRING = '+init=epsg:4326'
|
2008-11-15 01:24:19 +00:00
|
|
|
|
2009-03-31 22:23:18 +00:00
|
|
|
class WMSFactory(BaseWMSFactory):
|
|
|
|
def __init__(self):
|
|
|
|
BaseWMSFactory.__init__(self)
|
|
|
|
sty,rl = Style(),Rule()
|
|
|
|
poly = PolygonSymbolizer(Color('#f2eff9'))
|
|
|
|
line = LineSymbolizer(Color('steelblue'),.1)
|
|
|
|
rl.symbols.extend([poly,line])
|
|
|
|
sty.rules.append(rl)
|
|
|
|
self.register_style('world_style',sty)
|
|
|
|
lyr = Layer('world',PROJ4_STRING)
|
|
|
|
lyr.datasource = Shapefile(file=SHAPEFILE)
|
|
|
|
lyr.title = 'World Borders'
|
|
|
|
lyr.abstract = 'Country Borders of the World'
|
|
|
|
self.register_layer(lyr,'world_style',('world_style',))
|
|
|
|
self.finalize()
|
|
|
|
|
2006-05-30 21:58:22 +00:00
|
|
|
The rules for writing this class are:
|
|
|
|
|
|
|
|
- It MUST be called 'WMSFactory'.
|
|
|
|
- It MUST sub-class mapnik.ogcserver.WMS.BaseWMSFactory.
|
2009-03-28 01:51:59 +00:00
|
|
|
- The __init__ MUST call the base class.
|
2006-10-19 01:25:24 +00:00
|
|
|
- Layers MUST be named with the first parameter to the constructor.
|
2009-03-31 22:23:18 +00:00
|
|
|
- Layers MUST define an EPSG projection in the second parameter of the
|
2006-10-19 01:25:24 +00:00
|
|
|
constructor. This implies that the underlying data must be in an EPSG
|
|
|
|
projection already.
|
2009-06-29 00:11:14 +00:00
|
|
|
- Style and layer names are meant for machine readability, not human. Keep
|
2006-05-30 21:58:22 +00:00
|
|
|
them short and simple, without spaces or special characters.
|
2006-10-19 01:25:24 +00:00
|
|
|
- For human readable info, set the title and abstract properties on the layer
|
|
|
|
object.
|
2006-07-23 19:50:52 +00:00
|
|
|
- DO NOT register styles using layer.styles.append(), instead, provide style
|
2008-11-15 01:24:19 +00:00
|
|
|
information to the register_layer() call::
|
2006-07-23 19:50:52 +00:00
|
|
|
|
2009-03-31 22:23:18 +00:00
|
|
|
register_layer(layerobject, defaultstylename, (tuple of alternative style names,))
|
2006-07-23 19:50:52 +00:00
|
|
|
|
2006-05-30 21:58:22 +00:00
|
|
|
- No Map() object is used or needed here.
|
2009-03-31 22:23:18 +00:00
|
|
|
- Be sure to call self.finalize() once you have registered everything! This will
|
|
|
|
validate everything and let you know if there are any problems.
|
2007-01-25 02:07:00 +00:00
|
|
|
- For a layer to be queryable via GetFeatureInfo, simply set the 'queryable'
|
2008-11-15 01:24:19 +00:00
|
|
|
property to True::
|
2007-01-25 02:07:00 +00:00
|
|
|
|
2008-11-15 01:24:19 +00:00
|
|
|
lyr.queryable = True
|
2006-07-23 19:50:52 +00:00
|
|
|
|
2006-05-30 21:58:22 +00:00
|
|
|
|
|
|
|
To Do
|
|
|
|
-----
|
|
|
|
|
|
|
|
- Investigate moving to cElementTree from lxml.
|
|
|
|
- Add some internal "caching" for performance improvements.
|
|
|
|
- Switch to using C/C++ libs for image generation, instead of PIL (also
|
|
|
|
requires core changes). PIL requirement will remain for INIMAGE/BLANK
|
2009-03-31 22:23:18 +00:00
|
|
|
error handling.
|