For the city of Uster, Switzerland, Sourcepole recently extended QGIS server with the possibility to use the print composer via WMS in order to offer printing functionality for web maps. A very nice GeoExt based client can be found at http://gis.uster.ch/webgis/. Andreas Neumann used and extended the GeoExt PrintProvider and PrintExtent classes which allows the user to intuitively select a layout, extent, scale, rotation and resolution for printing. The widget then sends a GetPrint request to QGIS server and a printable PDF is returned.
Now to the technical details: in order to use the print capability of QGIS server, the published project needs to contain one or more print compositions. QGIS server includes information about the available composer templates in the GetCapabilities response:
<WMS_Capabilities> … <ComposerTemplates xsi:type=“wms:_ExtendedCapabilities”> <ComposerTemplate width=“297” height=“210” name=“Composer 1”> <ComposerMap width=“102” height=“95” name=“map0”/> <ComposerMap width=“133” height=“79.87912087912088” name=“map1”/> <ComposerLabel name=“hello_world”/> </ComposerTemplate> </ComposerTemplates> …
With a ‘GetPrint’ request, the client may now request printable output in png or pdf format. The client needs to select an available composer template and needs to pass the selected extents for the composer maps. Additionally, there is the possibility to replace the text of composer labels. An example for a ‘GetPrint’ request is (note the new ‘TEMPLATE’ and ‘map0:extent’ Parameters):
In detail, the following parameters can be used to set properties for composer maps:
- <mapname>:EXTENT=<xmin,ymin,xmax, ymax> //mandatory
- <mapname>:ROTATION=<double> //optional, defaults to 0
- <mapname>:SCALE=<double> //optional. Forces scale denominator as server and client may have different scale calculations
- <mapname>:LAYERS=<comma separated list with layer names> //optional. Defaults to all layer in the WMS request
- <mapname>:STYLES=<comma separated list with style names> //optional
- <mapname>:GRID_INTERVAL_X=<double> //set the grid interval in x-direction for composer grids
- <mapname>:GRID_INTERVAL_Y=<double> //set the grid interval in x-direction for composer grids
To replace text in composer labels, the label needs to have a text id (can be assigned in the print composer user interface of the composer label). The text to insert into the label can be passed in the GetPrint request with an additional parameter =text (of course, the label id should be different to the standard WMS parameters…).
Besides printing, an additional nice feature in the most recent developer version is the possibility to also use relative pathes in published project files. Like this, it’s possible to conveniently export a project file recursively together with the corresponding data.
Finally, I’d like to thank the city of Uster and Andreas Neumann for the generous support and the creative ideas during the implementation of the printing functionality.