Home > Geoespatial / GIS > How Mapserver works

How Mapserver works

TRANSLATION NOTES: Please read some comments at the end of this post.

clip_image001[1]Last time we talk about some criteria of why MapServer and its basic installation. Now let’s look at some of its performance in a mapping exercise from the Chiapas buddies (*).

Where it is mounted

Once installed Apache, the default publishing directory for MapServer is the OSGeo4W folder directly on C: /

Inside, there are different folders with applications based on what is installed, but the folder for publication should go within apache. In this case the folder is called gis.

  • Then, inside the data folder, contains layers, orthophotos, etc.
  • In the etc folder, goes true type fonts used for labels, with .ttf extension. Also here, there is a txt file that sets up those symbols and other that defines the symbols.
  • And finally, in the folder httdocs goes the web pages that lift the service.
  • clip_image002

The Web page

In the example, I will use the case shown last time. Basically contains an index file that redirects to other with a phtml extension and this in turn raises built functions on a php file and the maps. There is a folder containing the images linked from the page.

clip_image003

If we look, the phtml is only the shell built from tables, and calls to php/mapscript functions. It should be lifted using:

http://localhost/gis/gispalenque.phtml

Below it is shown the result functioning:

  • On the center the GMapDrawMap() function,
  • On the right the keymap GMapDrawKeyMap() call,
  • Below it’s the GMapDrawScaleBar() scale bar,
  • And in case of display functions, a condition regarding the listbox if (!IsHtmlMode()) echo “<!—”  with the decisions:  ZOOM_IN, ZOOM_OUT, RECENTER, QUERY_POINT.

Already running the application, the display looks like this:

clip_image004

The .map files

The combination of MapServer’s publication is what apache lifts, what php is sending through mapscript and then exits by the shell. But most of the science is in .map files, which should not be confused with those generated by MapInfo, Manifold or Mobile Mapper Office with the same extension files.

These .map files are text files that contain the map as a script. These can be created with desktop programs such as Quantum GIS; if you look there’s one for the main map, one for the Keymap and two for WMS and WFS OGC services. Let’s see how Mapscript works:

MAP

NAME PALENQUE_DEMO
STATUS ON
SIZE 600 450
SYMBOLSET ../etc/symbols.txt
EXTENT 604299 1933386 610503 1939300 #VIEW OF ALL PALENQUE MAP
#EXTENT 605786 1935102 608000 1938800 #ONLY SECTOR 01
UNITS METERS
SHAPEPATH “../data”
TRANSPARENT ON
IMAGECOLOR 255 255 255
FONTSET ../etc/fonts.txt

  • MAP indicates that the script starts
  • STATUS, indicates whether the map by default is on or not
  • SIZE is the size of the deployment
  • SYMBOLSET shows the route of symbols
  • EXTENT is the display’s coordinates.  The # symbol is used to make annotations
  • UNITS is for units
  • SHAPEPATH, is the path where the layers are placed
  • Finally, everything will end up with the END command

Inside, the code starts with a command line, and ends with END, for example for minimum and maximum scale, the temporary images directory is:

WEB
MINSCALE 2000000
MAXSCALE 50000000

IMAGEPATH “C:OSGeo4W/tmp/ms_tmp/”
IMAGEURL “/ms_tmp/”
clip_image005END

Scale bar:

SCALEBAR
IMAGECOLOR 255 255 255
LABEL
COLOR 0 0 0
SIZE SMALL
END
SIZE 300 5
COLOR 255 255 255
BACKGROUNDCOLOR 0 0 0
OUTLINECOLOR 0 0 0
UNITS kilometers
INTERVALS 3
STATUS ON
clip_image006END

A raster layer: goes in the background, with description as “Orthophoto” in the listing, from a tiff located in the folder data:

LAYER
NAME ortofoto
METADATA
“DESCRIPTION” “OrtoFoto”
END
TYPE RASTER
STATUS OFF
DATA “C:OSGeo4W/apps/gis/data/ortofotoGral.tif”
#OFFSITE 0 0 0
END

A polygon layer .shp, thematised based on criteria, by raising some data on an html template, with a label that has sans font, size 6, black and white borders buffer 5…

clip_image007

LAYER
NAME sector02Zona
TYPE POLYGON
STATUS OFF
TRANSPARENCY 50
EXTENT 607852 1935706 610804 1938807   METADATA
“DESCRIPTION”   “Tematico por Valor Sector 02”
“RESULT_FIELDS” “MsLink Cve_Mz Cve_Pred prop Area Perimetro VALOR”
END
DATA PALENQUE_SECTOR01
TEMPLATE “ttt_query.html”
TOLERANCE 5
#TOLERANCEUNITS PIXELS
LABELITEM “VALOR”
CLASSITEM “VALOR”
LABELCACHE ON
CLASS
SYMBOL 1
COLOR 128 128 128
OUTLINECOLOR 0 0 0
NAME “ZonaNULL”
EXPRESSION ([VALOR]=0)
LABEL
ANGLE AUTO
COLOR 0 0 0
FONT sans
TYPE TRUETYPE
POSITION cc
PARTIALS FALSE
BUFFER 5
SIZE 6
OUTLINECOLOR 200 200 200
END
END #class valor 0
CLASS
SYMBOL 3
COLOR 255 128 128
#COLOR -1 -1 -1 #NO FILL

… And so until it closes up with

END
END #Class Valor
END # Layer

In conclusion

From here, to work with mapserver, although is very simple, it becomes such complex and limited for large jobs because everything is in the .map. The major disadvantage is that everything is done manually(**), like defining each color in a themed, and this is the reason arise tools as CartoWeb, that works on Mapserver but brings built plugins and examples with features that make this primitive version stays as the readme first:

  • Work separate frames with AJAX in order to refresh them separately
  • Parsing the code, so that a script rewrites .map based on configurable criteria.
  • Return dynamic movement without requiring refreshing, as if it were a flash layer
  • Vector editing on line and immediate writing on cache
  • Layer’s download in vector’s shape
  • Export to Google Earth
  • Generate PDF for deployment

In a forthcoming we’ll take a look to CartoWeb, here are the links to the main examples.

TRANSLATION NOTES:

(*) buddies: In Mexican jargon, this word is the same like ‘cuates’.

(**) manually: In Spanish when you want to refer that something is going to be done manually, it is used this Idiom: “Se hace de a pie”.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.