Maps

How Mapserver Works

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

 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 etc folder, there are the true type fonts used for the labels, with a .ttf extension. 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 last time. It basically contains an index file that redirects to a phtml extension, and this in turn raises the functions built on top of a php and the maps. A folder contains the images linked from the page.

Mapserver geoserver

If we look at it, the phtml is just the shell built from tables, and calls 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 that then comes out of that shell. But most of the science is in .map files, not to 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 script form. These can be created with desktop programs like Quantum GIS, if you notice there is one for the main map, one for the Keymap and two for the OGC wms and wfs 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 #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 display coordinates. 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 design
  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 raster layer: that goes in the background, with a description in the list as "Orthophoto", 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 / orthophotoGral.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" "Theme 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 "VALUE"
  CLASSITEM "VALUE"
  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

Hence, working with mapserver, although it is quite simple, becomes 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 that is why tools such as CartoWeb arise, which works on Mapserver but brings built-in plugins and examples with characteristics that make this primitive version look like the 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.

Golgi Alvarez

Writer, researcher, specialist in Land Management Models. He has participated in the conceptualization and implementation of models such as: National Property Administration System SINAP in Honduras, Management Model of Joint Municipalities in Honduras, Integrated Cadastre-Registry Management Model in Nicaragua, Territory Administration System SAT in Colombia . Editor of the Geofumadas knowledge blog since 2007 and creator of the AulaGEO Academy that includes more than 100 courses on GIS - CAD - BIM - Digital Twins topics.

Related Articles

3 Comments

  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”
    "

    <a href="http://www.myescortgirls.com/en/">xxxxx</a>
    EXEC…….
    Eess_id
    WkbPoint
    WGS84

    "

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

  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 a comment

Your email address will not be published. Required fields are marked with *

Back to top button