![]() |
Home | Docs | Issue Tracker | FAQ | Download |
![]() ![]() |
MapServer can create an image and dump it to a local directory or send it directly to the requesting web browser, as in this example. You can view it without the need for an html page, just enter this URL: http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example1-1.map&layer=states&mode=map (Remember to replace “<insert hostname or IP address here>” with your web server’s name, e.g. “localhost”, or its IP address, e.g. “127.0.0.1”).
This URL can be broken into three parts: the first part, http://<insert hostname or IP address here>/cgi-bin/mapserv.exe?, calls the MapServer CGI program. If you invoke it as is you will get this familiar message:
No query information to decode. QUERY_STRING is set, but empty.
The next three parts are what make up the query string. The query string contains the CGI parameters (variables and their values), with each parameter separated by an ampersand (&). So, looking at the query string, the first parameter “map” has a value “/ms4w/apps/tutorial/htdocs/example1-1.map”–this tells the MapServer CGI program (mapserv or mapserv.exe) what mapfile to process/parse. The next parameter "layer=states", tells mapserv.exe to “turn on” the states layer–recall that we named our layer object “states”. The last parameter, "mode=map", tells mapserv.exe what to do with the output from the mapfile. In this case it tells mapserv.exe to dump the image directly to the web browser (the client), without first creating a temporary image on the server. The MapServer "mode" CGI variable takes values other than "map". For example if you use "mode=browse", MapServer will dump the image to a temporary directory on the server. The browse mode will not work now but we’ll come back to it again later.
This is what the mapfile looks like: Example1-1.map.
The MAPFILE is MapServer’s basic configuration mechanism. It is made up of “objects” and each object can have keywords or other objects. It has a hierarchical structure such that some objects fall under other objects... on top of this hierarchy is the MAP object, all other objects belong to it. This example shows a very straightforward heirarchy of objects. As you go through each example, the complexity of these hierarchical trees will increase.
A few quick notes about mapfiles: we define each object in the mapfile with the object name and we close it with “END” and we precede comments with a pound (#) sign.
Let’s break “example1-1.map” down by objects. Its structure looks like this:
MAP
|-LAYER
|-CLASS
|-STYLE
Let’s look at the keywords (parameters) within the MAP object:
<Lower Left X> <Lower Left Y> <Upper Right X> <Upper Right Y>
with spaces separating each value. This needs to be in the same units as the data or, if specifying a different output projection, in the same units as the output projection.
In this example our data is in geographic projection so the units are in decimal degrees. You can use the utility ogrinfo, which is part of the GDAL/OGR library package, to get the extent of a particular shapefile (or other supported vector formats). Here is the command I used to get the extent for this example:
ogrinfo -al -so states_ugl.shp
This returned the following output:
INFO: Open of `states_ugl.shp' using driver `ESRI Shapefile' successful.
Layer name: states_ugl
Geometry: Polygon
Feature Count: 204
Extent: (-97.238976, 41.619778) - (-82.122902, 49.385620)
Layer SRS WKT:(unknown)
AREA: Real (12.3)
PERIMETER: Real (12.3)
STATESP020: Real (11.0)STATE: String (20.0)
STATE_FIPS: String (2.0)
CLASS: String (5.0)</pre>
You can also use ArcView or other open source GIS packages–QGIS, Thuban, etc.
Feel free to change the values of EXTENT to get a better understanding of how it changes your map.
Now let’s look at the LAYER object parameters:
Let’s look at the CLASS object parameters:
And finally, let’s look at the STYLE object parameters:
This ends the first example in this tutorial. You are encouraged to change the values of the keywords in the mapfile. It will help you understand what these keywords do.
Back to Section 1 index | Proceed to Example 1.2