How Mapserver Works

The previous time we talked about some criteria why MapServer and the basics of the installation. Now let's see some of its operation in an exercise with the maps of the Chiapanecans.

Mapserver geoserver Where is mounted

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

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

  • Then inside, the data folder contains the layers, orthophoto, etc.
  • In the folder etc, the true type fonts used for the labels, with extension .ttf. Also here is a txt file that lifts them and another that defines symbols.
  • And finally in the folder httdocs go the web pages that raise the service.
  • Mapserver geoserver

The website

In the example, I will use the case shown the previous time. It basically contains an index file that redirects to a phtml extension, and this in turn raises the functions built on a php and maps. A folder contains the linked images from the page.

Mapserver geoserver

If we look, the phtml is only the shell built from tables, and called to the mapscript / php functions. You should get up using:

http://localhost/gis/gispalenque.phtml

Below is the result:

  • To the center the function GMapDrawMap (),
  • On the right the call to GMapDrawKeyMap () keymap,
  • The scale bar below GMapDrawScaleBar (),
  • And in case of the deployment functions, a condition with respect to the listbox if (! IsHtmlMode ()) echo "<! -" With decisions: ZOOM_IN, ZOOM_OUT, RECENTER, QUERY_POINT.

Already running, the deployment looks like this:

Mapserver geoserver

The .map files

The combination of Mapserver's publication is in what Apache raises, which sends php through Mapscript and then it goes through that shell. But most of the science is in the .map files, which should not be confused with those generated by Mapinfo, Manifold or Mobile Mapper Office with the same extension.

These .map are text files, which contain the map in the form of a script. These can be created with desktop programs such as Quantum GIS, if they are set there is one for the main map, one for the Keymap and two for the OGC services wms and wfs. Let's see how mapscript works:

MAP

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

  • MAP indicates start script
  • STATUS, indicates if the default map comes on or not
  • SIZE is the size of the deployment
  • SYMBOLSET shows the path of the symbols
  • EXTENT are the coordinates of the display. The # symbol is used to make annotations
  • UNITS for units
  • SHAPEPATH, the path where the layers are
  • Everything at the end will end with the END command

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

WEB
MINSCALE 2000000
MAXSCALE 50000000

IMAGEPATH "C: \ OSGeo4W / tmp / ms_tmp /"
IMAGEURL "/ ms_tmp /"
END

Mapserver geoserverThe 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
END

Mapserver geoserverA layer of raster: that goes of fund, with description in the listing like "Ortofoto", from a tiff located in the data folder:

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

A shp layer of polygons, thematized based on criteria, lifting some data on an html template, with a sans font label, size 6, black color and white edges of 5 buffer ...

Mapserver geoserver

LAYER
NAME sector02Zone
TYPE POLYGON
STATUS OFF
TRANSPARENCY 50
EXTENT 607852 1935706 610804 1938807 METADATA
"DESCRIPTION" "Thematic by Value Sector 02"
"RESULT_FIELDS" "MsLink Cve_Mz Cve_Pred prop Area Perimeter VALUE"
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 ([VALUE] = 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 0 value
CLASS
SYMBOL 3
COLOR 255 128 128
#COLOR -1 -1 -1 #SIN FILLING

.... And so to close with

END
END #Class Value
END # Layer

In conclusion

From here, that working with mapserver, although it is quite simple, it becomes medium complex and very limited for large jobs because everything is in the .map. The biggest disadvantage is that everything is done on foot, such as defining each color in a theming, and this is why tools such as CartoWeb, which works on Mapserver but come with built-in plugins and examples with features that make this primitive version remain as he Readme first:

  • Work separate frames with AJAX in order to refresh them separately
  • Parse the code, provided a script rewrites the .map based on parametrizable criteria
  • Dynamic back scrolling without requiring refresh, as if it were a flash layer
  • Online vector editing, immediate cache write
  • Download layer in vector form
  • Export to Google Earth
  • Generate PDF from the deployment

In a next we will take a look CartoWeb, here I leave the link to the main examples.

3 Replies to "How Mapserver works"

  1. Hello,

    I'm trying to call a layer from the .map as follows:

    LAYER
    NAME test_houses
    TYPE POINT
    CONNECTIONTYPE OGR
    CONNECTION # »virtual.ovf»
    »

    xxxxx
    EXEC .......
    Eess_id
    WkbPoint
    WGS84

    »

    My problem is that the DSN service is giving problems: when requesting a GetCapabilities I am returning the database password ... can I put a call to a file to avoid "giving away" the password or is it a DSN error ???? Thank you!

  2. MapServer is a popular Open Source project whose purpose is to display dynamic spatial maps over the Internet. A mounted drive is a drive that is mapped to an empty folder on a volume that uses the NTFS file system. Mounted drives function as any other drives, but they are assigned drive paths instead of drive letters.

Leave an answer

Your email address will not be published.

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