You can use QGIS to ‘compose’ your map by adding and arranging layers, symbolizing them, customizing the colors and then creating a map file for MapServer.
Notitie
Currently the plugin only works when you use ‘Old Symbology’ in QGIS. ‘New Symbology’ is not yet supported.
The MapServer Export Plugin operates on a saved QGIS project file and not on the current contents of the map canvas and legend. This has been a source of confusion for a number of users. As described below, before you start using the MapServer Export Plugin, you need to arrange the raster and vector layers you want to use in MapServer and save this status in a QGIS project file.
Figure Mapserver Export 1:
In this example, we demonstrate the four steps required to create a simple project file which can be used to create the MapServer map file. We use raster and vector files from the QGIS sample dataset Voorbeeld Data.
To use the Mapserver Export plugin from within QGIS, you need to enable the MapServer Export Plugin first using the Plugin Manager (see Loading a QGIS Core Plugin).
Figure Mapserver Export 2:
Map file | Enter the name for the map file to be created. You can use the button at the right to browse for the directory where you want the map file created. |
Qgis project file | Enter the full path to the QGIS project file (.qgs) you want to export. You can use the button at the right to browse for the QGIS project file. |
Map Name | A name for the map. This name is prefixed to all images generated by the mapserver. |
Map Width | Width of the output image in pixels. |
Map Height | Height of the output image in pixels. |
Map Units | Units of measure used for output. |
Image type | Format for the output image generated by MapServer |
Web Template | Full path to the MapServer template file to be used with the map file |
Web Header | Full path to the MapServer header file to be used with the map file |
Web Footer | Full path to the MapServer footer file to be used with the map file |
Only the inputs Map file and QGIS project file are required to create a map file, however by omitting the other parameters, you may end up creating a non-functional map file, depending on your intended use. Although QGIS is good at creating a map file from your project file, it may require some tweaking to get the results you want. For this example, we will create a map file using the project file mapserverproject.qgs we just created (see Figure_mapserver_export_2):
Figure Mapserver Export 3:
You can view the map file in any text editor or visualizer. If you take a look, you’ll notice that the export tool adds the metadata needed to enable our map file for WMS.
If you get error messages from mapserver like:
loadSymbolSet(): Unable to access file. (./symbols/symbols.txt)
or:
msLoadFontset(): Unable to access file. Error opening fontset ./fonts/fonts.txt.
This means that that the map file is requesting for fonts or symbol definition files but that Mapserver cannot find those.
Either comment the lines containing those names in the map file (this is possible if you do not have labels or use styles from the symbols.txt). Or create those files (see below).
The most simple fonts.txt file (because arial is used in the QGIS generated map files) contains the following line
# either relative to the map file or a full path:
arial /usr/share/fonts/truetype/msttcorefonts/arial.ttf
The most simple symbols.txt file contains the definition of a circle symbol (because a circle symbol is used for point layers)
SYMBOLSET
SYMBOL
NAME "circle"
TYPE ellipse
FILLED true
POINTS
1 1
END
END
END
We can now test our work.
If the map file is accessible for you mapserver cgi you can use the one of the url’s from the success dialog.
Another option is using the shp2img tool to create an image from the map file. The shp2img utility is part of MapServer and FWTools. To create an image from our map:
This creates a PNG with all the layers included in the QGIS project file. In addition, the extent of the PNG will be the same as when we saved the project. As you can see in figure_mapserver_export_4, all information except the airport symbols are included.
Figure Mapserver Export 4:
If you plan to use the map file to serve WMS requests, you probably don’t have to tweak anything. If you plan to use it with a mapping template or a custom interface, you may have a bit of manual work to do. To see how easy it is to go from QGIS to serving maps on the web, take a look at Christopher Schmidt’s 5 minute flash video. He used an older version of QGIS (version 0.8), but the demo applies equally well to newer versions.