MapServer's publishing Web Map service (Wms-web map Services)

Source: Internet
Author: User
Tags windows 7 x64 postgis

First, Environment construction
    • Operating system: Windows 7 x64;
    • Map server: MapServer 6.40;
    • Web server: Apache httpd 2.2;
    • Spatial database: Postgresql/postgis 9.2.

1. Apache HTTP Server
Apache HTTP Server (httpd) is an open-source web server that can run on multiple operating systems, including UNIX, Linux, and Windows, to provide secure, efficient, and extensible Web services. Provides an HTTP service that synchronizes with the current HTTP standard.

The HTTPD project, which started in 1995 and became the most popular web server software in April 1996, has a history of more than 20 years.

The most recent version, released on January 29, 2015, has a version number of 2.4.12, compared to the previous version, there are a number of new features, mainly including: Dynamic loading MPM (multi-processing Modules, multi-channel processing module), OCSP (Online Certificate status Protocol, line Certificate Status Protocol) support, add ' Mod_lua ' module, dynamic reverse proxy configuration, authentication/authorization, fastcgi Proxy, new expression parser, a small object cache API.

2, MapServer
MapServer is an open source real-time map publishing system based on the FAT server-side/thin-client mode, where the client sends data requests, the server handles the spatial data in real time, and sends the generated data to the client. The core part of MapServer is the map operation module written by C, which itself relies on some open source or free libraries, and uses GEOS, ogr/gdal to support various vector and raster data, and transform the projection in real time through proj.4 shared library. At the same time, the collection of PostGIS and open source database PostgreSQL for geospatial data Storage and SQL query operations, based on Ka-map, Maplab, Cartoweb and chameleon a series of client-side JavaScript API to support the transmission and expression of geospatial data, and to comply with a set of specifications such as WMS, WFS, WCS, WMC, SLD, GML, and filter Encoding, as developed by OGC.

MapServer relies on some open source libraries, such as SHAPELIB,FREETYPE,PROJ.4,GDAL/OGR, GD Library,regex. Because MapServer is written in C, it relies on sub-projects that have the corresponding C language implementation version.

    • Shapelib provides the ability to read, write, and update "ESRI Shapefile" format data, and can modify the corresponding property file (. dbf);
    • FreeType is a library of rendered fonts, capable of rendering most of the vector and bitmap font formats, and design ideas are small, efficient, highly customizable, and as lightweight as possible without sacrificing performance and functionality;
    • Proj.4 is a geo-projection library that provides a variety of projection definitions and usage interfaces;
    • Gdal/ogr,gdal (Geospatial Data Abstraction Library) is an open source raster spatial data Conversion Library under the X/mit license agreement. It uses an abstract data model to express the various file formats supported. It also has a series of command-line tools for data conversion and processing. OGR is a branch of the Gdal project, similar in function to Gdal, except that it provides support for vector data. There are many well-known GIS products that use the GDAL/OGR library, including Esri's ArcGIS 9.3,google Earth and cross-platform grass GIS systems.
    • GD Library, which generates images dynamically, supports most formats: JPEG, GIF, WEBP, XPM, BMP. Often used to dynamically generate graphs, pictures, thumbnails, etc., commonly used in web environments;
    • Regex, which provides regular expression support for mapserver.

3, Postgresql/postgis
PostgreSQL is a well-known open source "Object-relational" database that supports spatial data formats; PostGIS is a spatial tool extension of PostgreSQL that includes functions for manipulating spatial data in a PostgreSQL database, including additions and deletions, and the corresponding calculation function based on the original data: including the function of the center of the polygon.

The most recent release version for 9.4.1,9.3.6,9.2.10,9.1.15 and 9.0.19,postgresql releases multiple versions at once, which is a bug that fixes the corresponding previous version. 9.4 Changed the way that Unicode string escapes in JSON and JSONB data types.

Second, the WMS Service Release 1. Publishing services

The WMS (Web map Service) generates a map of spatial data from geographic information, and the WMS defines the map as a digital picture that fits on the computer screen, not the data itself, but rather renders the original data into a picture format (PNG, GIF, JPEG), vector-based element svg, or WEBCGM format.

MapServer publishes WMS, which defines the access path of the WMS through a file in a map format; The source of the data source, including the database and local files, and the styles of some WMS layers, including color, line thickness, whether the corresponding attributes are used to identify figures, and so on.

1.1 Map configuration file
The map file is wrapped in a MAP element, and all elements are terminated with end, and the web element defines the layer's Web access path; The layer element defines the layer, and the layers are styled with the "class" element, and the most important part of the layer is the source path that defines the layer's data. are divided into different types. We used MapServer to publish a polygon layer containing the borders of the world's countries.

1. First define the layer size and range, font path, and layer background color in the map file

2. Then define the appropriate MapServer service provider


The comment symbol in the map file is "#", "Wfs_onlineresource" defines the address of the MapServer and specifies the corresponding image address according to the geographic information: ImageUrl "/ms_tmp/".

3. Next, define the source of the layer, which comes from the Postgresql/postgis layer, the connection and the Read configuration

4, next define the style element, define the layer's color, the boundary color, the transparency

5. Next we want to add a label to each country, showing the name of each country


The text of the displayed label must be dynamic, or you would write a static file containing more than 200 country names for the idea, so we made the label text into a field of the layer table in the PostgreSQL database so that the dynamic purpose, text ' [name] ', Represents the ' Name ' field of the layer table, the color of the text, the font representation of the fonts used, the position to place the label position, the UL for the Up-left, the upper left corner, the same as Ur, bl, and BR; Read data from a database, especially a table containing Chinese You must indicate the encoding of the database, otherwise it will display garbled characters.

6. Finally, close layer and map tags

2. WMS Access Methods

Finally, access is done in a specific way, and the OGC WMS specification provides access to the WMS Service to support the HTTP GET method, where HTTP get transmits data in plaintext in the URL, primarily in key=value form, and the specification defines the method for constructing the access URL:


We construct a URL to access the layer we just published, based on the definition in the corresponding map:
Http://127.0.0.1/cgi-bin/mapserv.exe?map=mapfiles/boundries.map&mode=map
The port defaults to 80, which can be omitted, the URL defines the run in map mode, the profile address is mapfile/boundries.map, which is just the published map configuration file, which defines the configuration of the layer.

The program that accepts the request is Mapserv.exe, and the path to the program is Http://127.0.0.1/cgi-bin/mapserv.exe, which appears in the form of an extension of httpd, followed by the CGI specification, written in C. In addition to map= "and mode=", you can also accept more parameters, such as the size of the map.

1. Enter the URL of the construct into the browser

As you can see, the browser displays a picture in PNG format, which is the default output format of MapServer, the size of 800*400, combined with the previous map configuration file, let's see how the configuration file works:

The configuration file is the configured output picture size is 800*400, the color of the picture is the configured color. But we see that our configured display tag is not successful, why? Let's look at the configuration file:


The two-line configuration file tells MapServer that when the target feature (that is, the country) is at least 50 pixels in size, the label text is displayed and the text is 10 pixels minimum.

2. Change the layer size to display the label

Now let's change the size of a layer:

To see the effect:


When the size of the picture exceeds the size of the browser viewport, it shrinks the image by default and has a magnifying glass option by default, clicking to enlarge to its original size:


You can see that the original text is displayed.

3. Discussion

That is like Baidu map and gold map can be arbitrarily zoom and pan, what is the principle of it? The principle is very simple, is unceasingly requests, unceasingly refreshes, but does not see Baidu and the Gold will refresh the page, actually here is uses the Ajax,ajax application so widespread, unexpectedly everywhere.

With JavaScript, you can define a DIV element in the HTML, then display the requested picture into the corresponding Div, define some HTML elements as controls, and use JavaScript to bind some events to trigger the request MapServer service. And the request is in AJAX form, so that the map zoom and Pan is implemented.

The famous web GIS JavaScript Library openlayers This principle, but openlayers supports more layer types.

4. Extension: Map slices

If every time this request, every time mapserver to carry out the rendering process, then the efficiency is too low, and then think of the often requested layer directly into the image slice, stored in the corresponding directory, each access, directly across the MapServer directly read out of the picture, so that the rendering process is omitted, Reduces the cost of the server.


Slice is the rendered picture into a number of small pieces, according to the index number, splicing, make up the entire map, so that you can only load the user visible areas of the slice, the rest does not load, which also speeds up the access speed.


If you want to further speed up the access, then put the slices in the cache, which will speed up the read speed, because the hard disk read and the SSD read is not an order of magnitude, the SSD and memory is still not an order of magnitude, so performance can be greatly improved.

Iii. Summary

A WMS service is a Web service that generates a picture of geographic information (a picture-map with spatial information) and defines the rules for access, and the implementation of each map server software may be slightly different, but the general principle is the same!

Other map Server software, such as ArcGIS for server and GeoServer, differs in that ArcGIS for server encapsulates these complex underlying operations, more like a commercial software, GeoServer is another open source map Server software, The implementation of Java, but also the complex configuration, into a graphical management interface. The two software is a bit similar, there is a management interface running in the browser, visual configuration to publish WMS services.

MapServer Publishing the Web Map service (Wms-web map Services)

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.