MapServer's mapfile configuration file

Source: Internet
Author: User
Tags postgis

MapServer is a map rendering program, simply put, is the server side of the space data rendering into a map of the program, follow the basic CGI specification, accept input, return output. Its input parameters are not passed through the URL, but are specified by Mapfile, Mapfile is a text file with a suffix named. map, strictly speaking, this mapfile is a configuration file that tells MapServer the location of the space data entered by the main program (that is, the renderer). The format, style, etc. of the output map. As you can see in the diagram, the principle:


Fig. 1 Status of Mapfile

In the use of mapserver, the most important and most core is based on the data itself and the output map needs to configure Mapfile files, not one, so mastering the mapfile configuration is the necessary skills to use MapServer. By configuring the MapServer mapfile configuration file, you can post WMS, WFS, WCS, and SOS services via MapServer, and the following image is the result of the WMS Map Service, which is called:


Figure 2 Map Global View


Fig. 3 The details after the map enlargement

After watching the effect of the picture, is not also a desire to try. But, anything, want to do well, must start from the foundation, the foundation may be boring, but is the only way. The basics here are basic maps and GIS knowledge, and configure mapfile knowledge, of course, some people may not understand the basic map and GIS knowledge, do not worry, even if you do not understand, you can understand the content of this article, and the basic knowledge of configuration mapfile is what we want to learn. First, Mapfile basic knowledge

Mapfile is a text file similar to XML, starting with tags and closing tags, which are case-insensitive, preferably uppercase, which makes it easy to differentiate between labels and content. The outermost label for a mapfile file is map, which represents the mapping object, and one map object corresponds to one or more layer objects-LAYER, and a layer contains the data and output styles. MapServer reads and executes the configuration of the Mapfile file sequentially from top to bottom, so when there are multiple layer objects, the preceding layer is drawn first, followed by the layer, and superimposed on the previously drawn layer. So generally put the face of the background-colored layer in front of the layer containing points or lines of ground objects to put the back. This will be the point, line layer on the surface, so that the map will not be blocked.

Each object has many configuration parameters, and the parameters of these configurations do not have to be closed, and the objects are closed. The map object is essential, the LAYER object is a visible mapping layer, and must be specified, while the WEB object defines the storage location and service type and configuration of the mapserver generated map. 1.1 Map Object

The map object starts with a map, ends with end, and has many configuration options, mainly: name, name of the map, projection, the projection coordinate system used by the map, Imagecolor,[r] [g] [b], set the background color of the map; WEB, configuration Mapserv Er temporarily place the address of the generated map picture; LAYER, layer, is a child of the map object; status, control whether the maps are active; 1.2 projection Objects

Define the coordinate system of the map, this is also the necessary object, otherwise the map will not display properly. 1.3 WEB Objects Iamgepath, the path to the picture of the generated map and the temporary file, the base path of the Imageurl,imagepath, the METADATA, the configuration metadata, which is primarily used to support OGC services; 1.4 LAYER Object NAME, String, The name of the layer, the projection, the string, the coordinate system of the layer data, METADATA, the configuration object of the service to configure, status, whether the layer is active, connectiontype, the type of connection, the default is local, the local disk file; CONNECTION, a string that connects to a database that is used when the layer data is in the database, data, location path, or SQL query statement. ii. Examples of mapfile

Let's look at a mapfile file with a mapserver WMS service, with Notepad to open the text as follows. The main objects in this example are map, projection, WEB, LAYER, all objects are child objects of map, each object has many configuration parameters, here is just the most basic configuration. With these basic objects, you have the basic elements to publish a map (and, of course, more complex configuration objects and parameters). Below we look at a configuration MapServer provides WMS (Network map Services) Services Examples:

map NAME "Beijing Downtown" projection "init=epsg:3857" End #PROJECTION end WEB METADATA "Wms_title" "Beijing urban Area" "Wms_version" "1.3.0" "Wms_onlineresource" "HTTP://12" 7.0.0.1:8081/cgi-bin/mapserv.exe? "" Wms_enable_request "" * "" Wms_srs "" epsg:3857 "End # MAP METADATA # WEB LAYER NAM E "Beijing urban area" TYPE POLYGON METADATA "Wms_title" "Beijing urban Area" "Wms_srs" "epsg:3857" EN D # LAYER METADATA connectiontype postgis CONNECTION "host=127.0.0.1 port=xxxx dbname= ' xxxx ' user=xxxx PA Ssword=xxxx "DATA" Geom from beijing_3857 using unique gid using srid=3857 "CLASS NAME" Polygo
            N_style "Style COLOR" #e563ff "OutlineColor" #45ff57 "WIDTH 2 End # STYLE End # CLASS End # LAYER End # MAP 

The projection object defines the published map coordinate system as the epsg:3857 coordinate system, which is actually the coordinate system used by Google Maps and Bing maps.

Then, in METADATA, some configurations for publishing WMS services are defined, and "Wms_title" defines the names contained in the content returned using the WMS Getcapability method; "Wms_version" the version of the WMS Agreement is 1.3.0, "WM S_onlineresource "Defines the location of the MapServer CGI (map renderer) program," Wms_enable_request "stipulates that all functions on WMS are enabled, and" Wms_srs "stipulates the WMS The coordinate reference system for the service (it doesn't matter if you don't understand).

Finally LAYER configured the displayed map data and style, the type parameter sets the element type of the layer, here is the polygon (POLYGON), and the parameter of the configuration map data is ConnectionType, this is PostGIS, namely PostgreSQL Spatial data in a database; CONNECTION specify the parameters of the connection database; data specifies the SQL query statement of the query space data; CLASS specifies the shape of the polygon elements in the layer, color specifies the fill colour of the polygon, OutlineColor The boundary color of the polygon is specified, and the width of the border line of the polygon is specified.

Through the above configuration, we have successfully configured a service with WMS service capability, as opposed to MapServer, a mapfile represents a service. third, map call display

When the service is released, we can see the map at the opening. Of course not, that is the effect that is displayed on the browser side or other client after invoking this service. Browser-side or other client, to request this service, and then resolve the results of its return, the WMS here is actually a return of a picture rendered by MapServer, browser to the user's zoom, translation and other operations to correctly display the map, and need to deal with a lot of other events, and MapServer Communication, and this more complex thing, can be given to some front-end libraries, such as openlayers, so that we do not have to implement ourselves from the bottom.

This process is represented by a schematic diagram (in the case of a client-side browser):


Fig. 4 schematic diagram of the process

If you are unfamiliar with openlayers, you can look at my openlayers article, or what you want to know, you can comment under the blog. Using Openlayers to invoke the service correctly, the map effect begun in this article can be realized. Iv. Summary

In fact, this article is not only about the Mapfile configuration, but also the science of Mapfile for mapserver significance, Mapfile is what, as well as the configuration of the WMS example. In short, configuration mapfile is MapServer publishing services, in addition to the Mapfile object and parameters described in this article, there are some configuration objects and parameters, can be more detailed control of MapServer, to see detailed configuration instructions, see its official website on Introduction of Mapfile.

OK, just write here, what is the problem, you can go to the article below comment.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.