Preparation
This information has been put together for those that are going to use the exercises on using the MapServer software to serve data according to Open Geospatial Consortium's OWS standards, in the setting of the ITC courses. You will need a Web Server for serving both data and services. The URL of the Web Server for your exercises is (Server settings may vary depending on your setup):
__BASEURL__
Web Server Account
Before you can do anything that involves dynamic Web pages, client-sidescripting or server-side applications, you will have to make sure you have a Web site available to test and serve your content. There are many ways to get access to such a Web server; for ITC students the simplest is to use the ITC exercises server which uses the URL shown above. Next, we will explain how to create your personal account on this server.
To start the account creation process, open a tab in your web browser and navigate to the following page:
__BASEURL__/manage
Fill in the details asked for in the form and press "OK" (do not forget). This will execute a script that creates a special directory on the server, which you can use to serve content as Web pages, the Web address of your new site will be:
__BASEURL__/student/__SNUMBER__/ __MSG002__
Test the site by starting any web browser and typing in the web address mentioned above. You should see a webpage similar to the in 1.
You can also access this directory using your computer's file system (through the so-called UNC file path, that is not using the Web):
__CODEPATH__\ __MSG002__
When using a Windows computer, the easiest way to work with this directory is to create a so-called Mapped Network Drive. To do that, in the file explorer go to This PC find the Map Network Drive menu. Choose an unused drive letter (e.g. U:) and add the UNC file path mentioned above. Be careful, you will have to use the option Connect using different credentials, and then the username AD\s1234567 (again replacing s1234567 with your own s-number). 2 shows some snapshots of this process.
Now you can edit the file default.htm in a simple text editor (e.g. NotePad++ on Windows, available in the ITC Software Manager). Change the content (e.g. add a welcome message), save it and open again in a web browser. You should see the changes. This means your website is working and all content you place in this web-enabled directory will be served by the 'gisedu' Web server.
Configure a Local Web Server
Before you can do anything that involves dynamic Web pages, client-side scripting or server-side applications, you need to setup the proper environment to create and serve Web content. This means you need a Web Server running, and a program to create and serve OGC services, etc. Next, we will explain how to configure your system to work as a Web Server.
Download the ZIP-archive [ software_stack.zip ] containing the software require for this configuration. This file contains: The Apache HTTP Server, MapServer 4.0.5, Python 3 and a bunch of JavaScript libraries. This is a self-contained package that will not interfere with other software in your system. If you already have these software packages installed and configured then proceed to use your own existing setup.
Decompress the ZIP-archive in the root of your C: drive. This should result in the creation of a couple of directories as shown below (Note that not all the content of the two new directories is shown here):
C:\
|
|___ . . .
|
|___code [web enabled folder]
|
|___ . . .
|
|___ms4w
|
|___Apache
| |___ . . .
|
|___httpd.d
| |___httpd_code.conf
| |___httpd_libraries.conf
|
|___JS-libraries
| |___ . . .
|
|___Python
| |___ . . .
|
|___ . . .
|
|___apache-install.bat [Apache installation script]
Now we need to install the Apache service so that we can start serving content. Navigate to the ms4w folder and then right-click on the apache-install.bat file and select Run as administrator and shown in 1.
This will make the Apache Web server ready and listening on port 80 in your system. To check that your configuration is working we can use the server URL and your landing site URL as shown below. 2 shows Apache's main page, and 3 your personal landing page.
The local Web Server can be accessed via:__BASEURL__
Your landing site should be located at:__APPURL__/
Required Files and Data
For this exercise, you will need to use some data files and some MapServer configuration files. To get those files to your working directory, download the ZIP-archive [ Thailand.zip ]. Then, un-zip the file in the root of the directory you created in the previous section. This creates a content structure that should match the one below:
[your web dir]
|
|___thailand
|
|___configWMS.map [MapServer configuration file]
|
|___data
| |___naturalearth.tif
|
|___fonts
| |___fonts [used by MapServer]
|
|___lib
| |___javascript and css [needed for later exercises]
|
|___templates
| |___html templates [used by MapServer]
|
|___testWMS.html [webform to test your setup]
Setup Parameters
The MapServer software is installed on the same intranet server as your web sites. You will place all the MapServer configuration files, templates etc., inside the Web directory you created above. You can use only this location! The following 3 setup parameters will be needed repeatedly in the sections of this exercise:
[ NETPATH ]__NETPATH__ __MSG002__
[ CGIPATH ]__CGIPATH__
[ URLPATH ]__URLPATH__/ __MSG002__
The [NETPATH] points to the windows UNC path to your map configuration files (the physical location on the server), as it can be found by the MapServer CGI. The [CGIPATH] points to the location where the Web Server can reach the MapServer CGI scripts. The [URLPATH] points to the web location where a browser can find either your own html files or the output that MapServer generates as a response to a request, e.g., temporary image files or HTML templates. This path is mainly an alias that actually points to the NETPATH mentioned above but uses Web addressing format.
MapServer MAP Files
In many cases during these exercises, you will have to type code in so-called MAP files (configuration files for MapServer). It's very easy to make mistakes in such code. MAP code is not case-sensitive, but proper use of the syntax is important, especially nesting of commands.
Retyping the code you see in the exercise description is not necessary: You can copy the code from the listings directly. Below in Listing 1 is an example of such a code listing. Make yourself familiar with the tools, especially the copy tool in the title bar. If you see an ellipsis [ • • • ] in the code fragments, it indicates that there is more code above and/or below the code shown in the snippet. Please DO NOT copy the dots to your files. Additionally, lines with new code are highlighted in yellow. This should give you a reference as to where to implement the changes asked for in the exercise description. 1 contains a small code fragment that shows how the content of a MapServer MAP file looks like.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
dotdotdot LAYER NAME "forest" TYPE POLYGON STATUS ON CONNECTIONTYPE postgis CONNECTION "user=exercises password=exercises dbname=exercises host=__USERHOST__ port=5432 options='-c client_encoding=UTF8'" DATA "geom FROM thailand.forest USING UNIQUE id USING srid=4326" METADATA "ows_title" "forest" "ows_extent" "97.3 5.6 105.7 20.5" END #layer metadata PROJECTION "init=epsg:4326" END #layer projection CLASS NAME "forest" OUTLINECOLOR 255 255 255 COLOR 137 205 102 END #class forest END #layer forest dotdotdot |
Client-Server Architecture
In this exercise you will learn how to set up the software MapServer as a Web Map Service using the Open Geospatial Consortium's OWS standards, from data stored in a PostGIS database. Make sure you have executed and understood the setup instructions for MapServer in the previous sections before moving forward with this exercise!
MapServer is a so–called Common Gateway Interface (CGI) application, a standard for interfacing external applications with web servers. Executed on basis of an URL Request sent to the web server, it is able to provide dynamic/real time information.
One configures the MapServer CGI service by creating a MAP file, a text file with the '.map' suffix that defines an object tree in a hierarchical structure. You will learn how to set up such MAP files in the next sections of this exercise. To get an overall view about the MapServer '.map' language, take a look at the MapFile Reference documentation in the MapServer website.
Source Data
The purpose of OGC services is to enable interoperability by making data available independently of its storage structure. In our case we want to expose various datasets that are stored in a PostgreSQL database. The data model depicted in 45 shows the structure of these datasets.