Plugins mapserver export

提供: OSGeo.JP Wiki
2009年10月5日 (月) 22:55時点におけるSanak (トーク | 投稿記録)による版

移動: 案内検索

MapServer Export Plugin

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. <P>


Subsections



Creating the Project File

<P> 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.

<P>

<A NAME="fig:mapserver_export_qgs"></A><A NAME="7"></A>
Figure: Arrange raster and vector layers for QGIS project file

[clip=true, width=12cm]mapserver_export_qgis

<P> 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 #label_sampledata.

<P>

  1. Add the raster layer landcover.tif clicking on the mActionAddRasterLayerAdd Raster Layer icon.
  2. Add the vector Shapefiles lakes.shp, majrivers.shp and airports.shp from the QGIS sample dataset clicking on the mActionAddNonDbLayerAdd Vector Layer icon.
  3. Change the colors and symbolize the data as you like (For example see Figure #fig:mapserver_export_qgis)
  4. Save a new project named mapserverproject.qgs using File > mActionFileSaveSave Project.

<P>


Creating the Map File

<P> The tool msexport to export a QGIS project file to a MapServer map file is installed in your QGIS binary directory and can be used independently of QGIS. To use it from within QGIS, you need to enable the MapServer Export Plugin first using the Plugin Manager (see Section #sec:load_core_plugin).

<P>

<A NAME="fig:mapserver_export_dialog"></A><A NAME="32"></A>
Figure: Export to MapServer Dialog

[clip=true, width=9cm]mapserver_export_dialog

<P>

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

<P> Only the Map file and QGIS project file inputs 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 59):

<P>

  1. Start the MapServer dialog (see Figure 59) by clicking the mapserver_exportMapServer Export icon in the toolbar menu.
  2. Enter the name (e.g., qgisproject.map) for your new map file.
  3. Browse and find the QGIS project file (e.g., mapserverproject.qgs) you previously saved.
  4. Enter a name (e.g., MyMap) for the map.
  5. Enter the width and height (e.g., 600 for the width and 400 for the height) for your output image.
  6. For this example, the layers are in meters, so we change the units to meters.
  7. Choose ``png for the image type.
  8. Click OK to generate the new map file qgisproject.map. QGIS displays the success of your efforts.

<P> 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.

<P>


Testing the Map File

<P> We can now test our work 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:

<P>

  • Open a terminal window
  • If you didn't save your map file in your home directory, change to the folder where you saved it.
  • Run shp2img -m qgisproject.map -o mapserver_test.png and display the image

<P> 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 <A HREF="#fig:mapserver_export_test">60</A>, all information except the airport symbols are included.

<P>

<A NAME="fig:mapserver_export_test"></A><A NAME="74"></A>
Figure: Test PNG created by shp2img with all MapServer Export layers

[clip=true, width=12cm]mapserver_export_test

<P> 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.