Nikweb – Mapnik GeoJSON Web Service for nice Static Maps
05 Feb
Autor: Martin - Kategorie: Mapnik
At the end of last year, a new open source GIS tool slipped into Google Code. Nikweb is a GeoJSON web service for Mapnik, enabling you to render feature data you submit into a map. It was annouced as a new tool with the Mapnik 0.7.0 release and it’s been licensed by Alpstein Tourismus GmbH & Co. KG under the LGPL as part of the mapnik-utils project.
Mapnik is much valued for its beautiful cartography. Here at Alpstein we use Mapnik for all sorts of map rendering across outdooractive.com and other sites. One requirement we kept running into was how to produce nice “static” maps for use on pages where an interactive map wasn’t necessary, or for offline use in print.
We started with several GeoServer instances some time ago. We decided to switch to Mapnik because of the rendering advantages of Mapnik at that time. And we wanted to get rid of the need to connect each GeoServer instance to our database instances just to allow GeoServer to have access to the dynamic part of our data (which are tours and points of interest).
So we came up with the idea of having a web service we could submit geometries to, that Mapnik would render together with our base-maps and other layers, add labels, and return the finished map. A bit like Google Static Maps-API, Yahoo! Map Image API or the Open Street Map static maps API, except:
- Takes geometries and attributes, and applies styling to them, including labels.
- Can render any data with any base-maps and any projection.
- Can render data “within” the map, not just on top of it. eg. draw a submitted polygon under the roads and labels.
- Uses standard GeoJSON and Mapnik’s XML map definitions.
- Able to output any of Mapnik’s formats (images, PDF, SVG)
Nikweb is the result. So, now we can take our feature data, which is just a GeoJSON FeatureCollection with some extra fields (e.g. padding values, bbox calculation, …) and submit it via HTTP POST to Nikweb. It then gets rendered into our Map XML file, where the GeoJSON gets loaded into the layer named “NIKWEB”. Any filtering and style rules defined by our map XML apply as normal, the “properties” in our GeoJSON object are available as attributes to filter on or use for labels or symbol selection.
The extra fields in our JSON define how our map is rendered – defining the width, height, bounding-box, padding, and output format (these are mostly optional). They are comparable to OGC Web Map Service GetMap Parameters. The result of our request is an image (or soon: PDF & SVG) of a our completed map.
See the following JSON example to see how easy a GeoJson LINESTRING and a GeoJson Point may be rendered into a complex map:
{
"width":600, "height":400,
"format":"image\/jpeg",
"bbox_image":[1129892.83155173,6035613.97648191,1135458.80609139,6036934.02767432],
"type":"FeatureCollection",
"features":
[
{ "geometry": { "type":"Linestring", "coordinates": [ [10.15337,47.57021],[10.188389,47.577621],[10.192509,47.571602],[10.15337,47.57021],[10.15337,47.57021] ] },
"type":"Feature",
"properties": { "class":"tour_geom" } },
{ "geometry": { "type":"Point", "coordinates":[10.15337,47.57021] },
"type":"Feature",
"properties":{"class":"tour_start"}
}
]
}
The following map image shows how the input data from above gets rendered on top of Alpstein’s Outdoor Map cartography (the map data is held inside a postgresql/postgis data base on server side and all style definitions are done with help of a mapnik style file):

Nikweb Beispiel
Nikweb comes bundled with a WebOb application (runs in any WSGI container, and includes a simple server) as well as some Django views for building it into a GeoDjango app.
Feedback and contributions are most welcome, leave some comments below or jump onto the mapnik mailing lists.
Nikweb:
Trackback Uri kopieren
http://www.alpstein.com/blog/outdoor-geo-technology/2010/02/05/nikweb-mapnik-geojson-web-service-for-nice-static-maps/trackback/
Ihr Kommentar
Alle Felder mit Sternchen (*) sind Pflichtfelder. Ihre E-Mail wird nicht veröffentlicht.


