Anda di halaman 1dari 19

Editing the mapfile for a MapServer-based webGIS

Laura Carcano, Sara Lucca, Marco Minghini, Luana Valentini Spring 2011

Introduction: A mapfile is a simple text file used by MapServer to configure various features of a webGIS, such as web publishing properties of maps, definition of layers, colors, symbols, labels, etc. It is composed by hierarchical objects (i.e. some objects have to be nested inside others) that can have a general purpose (e.g. definition of paths for temporary directories) or a local purpose (e.g. definition of styles for single layers). Comments are introduced using the symbol # (hash). Objects start with a specific keyword (e.g. MAP, WEB) and finish with the keyword

END. They contain parameters, followed by their values (e.g. STATUS


they start and finish.

ON).

Remember to always close objects, otherwise MapServer will not understand where

The following pages are dedicated to a fully commented version of a mapfile. This example involvs just some of all the possible configurations, so remember to take a look also on the documentation to clear your doubts and understand how to do what is required. Also you can try out more complex solutions if you want to. Notes: Unless otherwise specified, the content of a mapfile is not case-sensitive (writing

STATUS ON is the same of writing status on). In this script the words that
define objects and parameters are written all upper-case just to make the mapfile more easily readable, and also because it has become a de facto standard among MapServer users. Strings that contain non-alphanumeric characters or a MapServer keyword must be quoted []. Anyway, it is a good habit to put all strings in double-quotes.

GIS Exercise Spring 2011

ethex.map (with full comments)


# Here starts the definition of the Map Object. # First piece of information is about general characteristics of the map we want # to create. # It starts with the MAP keyword and finishes with the END keyword.

MAP # Name of the map NAME "ethex"

# Geographic extension of the map: it is the first extension the # webGIS will display EXTENT 1486000 5056000 1525000 5088000

# Screen dimensions (pixels) of the window where the map will be drawn in SIZE 500 400

# Path of the folder containing data # (NOTE! here the path is from the mapfile) SHAPEPATH "data/shpf"

# Path of the file containing the definitions of the graphic symbols # (NOTE! here the path is from the mapfile) SYMBOLSET "graphics/symbols/Symbols.sym"

# Path of the file containing definitions of TrueType fonts # (NOTE! here the path is from the mapfile) FONTSET "graphics/fonts/fontset.txt"

# Background colour of the image where the map will be drawn # (R G B colour model) IMAGECOLOR 175 175 175

# Geographic units UNITS meters


GIS Exercise Spring 2011 2

#...........................................................................

# Here starts the definition of the Web Object. # It defines how the interface (template file) has to operate. # It starts with the WEB keyword and finishes with the END keyword. # The Web Object is nested inside the Map Object (it is a child of Map Object)

WEB # Path of the folder where MapServer writes temporary files # (NOTE! here the path is absolute) IMAGEPATH "/usr/local/mapserver_tmp/"

# Web path of the folder where MapServer writes temporary files # (NOTE! here the path is from the web root (E.g. from htdocs for # Apache web servers))

IMAGEURL "/tmp/"

# Name of the main template file TEMPLATE "ethex.html" END

# Definition of a Projection Object. # Here the global projection, i.e. the global CRS of the map, has to be defined. # The Projection Object starts with PROJECTION and finishes with END

PROJECTION # EPSG code of the CRS defined for the map. # Here 3003 is the Italian National CRS Gauss-Boaga (West zone) code. "init=epsg:3003" END

#...........................................................................

# Here starts the definition of the Reference Object. # It defines the reference map (overview map).
GIS Exercise Spring 2011 3

# It starts with the REFERENCE keyword and finishes with the END keyword. # The Reference Object is nested inside the Map Object

REFERENCE # Status of the reference map (values: ON or OFF) STATUS on

# Path of the folder where there is the reference map image # (NOTE! path is from the mapfile) IMAGE "graphics/refmap/refmap.png"

# Screen dimensions (pixels) of the window where the reference map # will be drawn in SIZE 183 150

# Geographic extension of the reference map EXTENT 1486000 5056000 1525000 5088000

# Colour for filling in the rectangle that shows the zone displayed # by the main map. (The value -1 -1 -1 sets transparent colour) COLOR -1 -1 -1

# Colour for drawing the borders of the rectangle that shows the zone # displayed by the main map. OUTLINECOLOR END 255 0 0

#...........................................................................

# Here starts the definition of the Querymap Object. # It defines the query map (map drawn to display query results). # It starts with the QUERYMAP keyword and finishes with the END keyword. # The Querymap Object is nested inside the Map Object

QUERYMAP # Status of the query map (values: ON or OFF)


GIS Exercise Spring 2011 4

STATUS on

# Colour used to highlight queried features (default: yellow) COLOR 255 0 0

# STYLE says how to underline the queried features # # # # # hilite: queried features are underlined with the colour defined by COLOR; the other features are not underlined and they are displayed with their graphic configurations normal: queried features are not underlined and they are displayed with their graphic configurations (like not queried features)

# selected: queried features are displayed with their graphic # configurations and unqueried features are not displayed

STYLE hilite END

#...........................................................................

# Here starts the definition of the Legend Object. # It defines the static legend. # It starts with the LEGEND keyword and finishes with the END keyword. # The Legend Object is nested inside the Map Object (it is a child of Map Object)

LEGEND # Status of the legend (values: ON or OFF) STATUS on

# Legend background colour IMAGECOLOR 255 255 255

# Dimensions of the legend symbols (in pixels) default= 20 x 10 KEYSIZE 18 12

# Here starts the definition of the Label Object. The Label Object defines the # characteristics of the legend symbols. LABEL
GIS Exercise Spring 2011 5

# Here there is the definition of the font to be used; Generally bitmap fonts # are faster to be drawn than TrueType fonts. But TrueType fonts are scalable # and available in a variety of faces. # When truetype is selected the FONT parameter must be also defined. TYPE truetype FONT "courier"

# Text size. # It has to be defined has: # [integer] for truetype type # [tiny|small|medium|large|giant] for bitmap type. SIZE 10

# As an alternative # # TYPE bitmap SIZE small (o giant o medium)

# Here we define the color used COLOR 0 0 130 END END

#...........................................................................

# Here starts the definition of the Scalebar Object. # It defines the scalebar. # It starts with the SCALEBAR keyword and finishes with the END keyword. # The Scalebar Object is nested inside the Map Object

SCALEBAR # Status of the scalebar (values: ON or OFF) STATUS on

# Color to be used for odd intervals COLOR 0 0 0

GIS Exercise Spring 2011

#Color to be used for outlining individual intervals OUTLINECOLOR 50 50 50

# Color to be used for even intervals BACKGROUNDCOLOR 255 255 224

# Background color for the scalebar IMAGECOLOR 215 215 200

# Output scale bar units ([feet|inches|kilometers|meters|miles) UNITS kilometers

# Number of intervals of the scalebar(integer) INTERVALS 4

# Scalebar image size(in pixel) SIZE 200 2

# Scalebar style: (available values: 0,1) STYLE 0

# Here starts the definition of the Label Object. The Label Object defines the # characteristics of the scalebar symbols. LABEL TYPE bitmap SIZE small COLOR 50 50 50 END

# As an alternative: # # # # # END
GIS Exercise Spring 2011 7

LABEL TYPE BITMAP SIZE tiny COLOR 255 0 0 END

#...........................................................................

# Here starts the first Layer Object. The Layer Object determines the make-up of # a specific cartographic layer in the map. Layers are drawn in their order of # appearance in the MapFile (first layer is at the bottom, last is on top). # There is a maximum of 50 layers per mapfile. # This can be changed by editing the map.h file to change the value of # MS_MAXLAYERS to the desired number and recompiling Mapserver. # It starts with the LAYER keyword and finishes with the END keyword. # The Layer Object is nested inside the Map Object

# 1st LAYER: our first layer corresponds to a shapefile layer.

LAYER # Layer name: it is the link between the MapFile and web interfaces that refer # to this name (max=20 characters) NAME "municipalities"

# Layer status (values: DEFAULT = always displayed, ON = displayed on demand or # OFF = not displayed) STATUS default

# Path and filename of the shapefile to process (without extension). # It has to be specified relatively to the SHAPEPATH option of the Map Object. DATA "municipalities"

# Data type; most used: point/line/polygon/raster TYPE polygon

# Item name in the attribute table to be used for labeling. LABELITEM "NAME"

# Item name in the attribute table to be used for defining different thematic # classes. CLASSITEM "DISTRICT"
GIS Exercise Spring 2011 8

# Maximum scale at which the layer is labeled (double). LABELMAXSCALE 100000

# Templates to be used to publish a set of results (multiresult query modes) HEADER "header.html" FOOTER "footer.html" TEMPLATE "query.html"

# Metadata definition needed for attribute queries (MapServer version 5+) METADATA qstring_validation_pattern '.' END

# Here starts the first Class Object. It defines the thematic classes of the # layer. # Each layer must have at least one class. # If more than one class has to be defined, membership is determined using # attribute values and expressions. # It starts with the keyword CLASS and terminates with the keyword END. CLASS # Name to be used in the legend for the specific class. If it has not been # defined, in the legend this class doesn't appear. NAME "Como district"

# Value of the attribute item defined in CLASSITEM EXPRESSION "Como"

# Label to be used LABEL TYPE TRUETYPE FONT "times" SIZE 8

# Label positioning; available values: auto, ul|uc|ur|cl|cc|cr|ll|lc|lr; in # this latter case first letter refers to
GIS Exercise Spring 2011 9

# Y coordinate (u= up, c= center, l= low), the second to X # left, c= center, r= right. # By selecting the value "auto"

coordinate(l=

MapServer is requested to calculate a

# label position that will not interfere with other labels. POSITION auto

# Label color COLOR 155 155 155 END

# Style to be used for the feautures of the layer. STYLE

# Color to be used for drawing features. COLOR 0 0 255

# Color to be used for outlining polygons. OUTLINECOLOR 0 255 0 END END

# See previous class for comments CLASS NAME "Varese district" EXPRESSION "Varese" LABEL TYPE TRUETYPE FONT "times" SIZE 8 POSITION AUTO COLOR 155 155 155 END STYLE COLOR 110 210 55 OUTLINECOLOR 225 0 0 END
GIS Exercise Spring 2011 10

END END

#...........................................................................

# 2nd LAYER: it is a raster layer

LAYER NAME "NWraster"

# Name of the group that the layer belongs to. # The group allows to do things like turning on and off a group of layers at # once. #GROUP "raster4"

STATUS on

# Name of the data file: a path relative to SHAPEPATH is used. DATA "../raster/nw.tif" TYPE RASTER

# Scale at which the layer is drawn. MINSCALEDENOM 2000 MAXSCALEDENOM 25000 END

#...........................................................................

# 3rd LAYER: it is a raster layer (see 2nd layer)

LAYER NAME "NEraster" #GROUP "raster4" STATUS on DATA "../raster/ne.tif" TYPE raster
GIS Exercise Spring 2011 11

MINSCALEDENOM 2000 MAXSCALEDENOM 25000 END

#...........................................................................

# 4th LAYER: it is a raster layer (see 2nd layer)

LAYER NAME "SWraster" #GROUP "raster4" STATUS on DATA "../raster/sw.tif" TYPE raster MINSCALEDENOM 2000 MAXSCALEDENOM 25000 END

#...........................................................................

# 5th LAYER: it is a raster layer (see 2nd layer)

LAYER NAME "SEraster" #GROUP "raster4" STATUS on DATA "../raster/se.tif" TYPE raster MINSCALEDENOM 2000 MAXSCALEDENOM 25000 END

#...........................................................................

# 6th LAYER: it is a vector (shp file) layer

GIS Exercise Spring 2011

12

LAYER NAME "lakes" STATUS default DATA "lakes" TYPE polygon LABELITEM "NAME" CLASS NAME "Lakes" STYLE

# Name

(or number) of the symbol to be used for the features

# Symbols are defined in the file given in the SYMBOLSET parameter SYMBOL "lakes_ellipse"

COLOR 0 215 240 OUTLINECOLOR 0 215 240 END LABEL TYPE truetype FONT "mtypcors" SIZE 11

# Label positioning; available values: auto, ul|uc|ur|cl|cc|cr|ll|lc|lr; in # this latter case first letter refers to Y coordinate (u= up, c= center, # l= low), the second to X coordinate(l= left, c= center, r= right).

# By selecting the value "auto", MapServer is requested to calculate a # label position that will not interfere with other labels. POSITION AUTO

COLOR 0 0 255 BACKGROUNDCOLOR 255 255 0 END END END

#...........................................................................
GIS Exercise Spring 2011 13

# 7th LAYER: it is a vector (shp file) layer

LAYER NAME "railways" STATUS on DATA "railways" TYPE line MAXSCALEDENOM 100000

CLASS NAME "Railways" STYLE SYMBOL "point" COLOR 0 0 0 SIZE 7 END STYLE SYMBOL "point" COLOR 255 255 0 SIZE 5 END STYLE SYMBOL "line10-10" COLOR 0 0 0 SIZE 1 END END END

#...........................................................................

# 8th LAYER:it is a vector (shp file) layer. A different projection (UTM32/WGS84 # characterises the data.

LAYER
GIS Exercise Spring 2011 14

NAME "stations" STATUS on DATA "stations" TYPE point CLASSITEM "COMP_CODE" LABELITEM "NAME" LABELMAXSCALEDENOM 100000 HEADER "header_f.html" FOOTER "footer_f.html" TEMPLATE "query_f.html"

# Projection: # Here 32632 is the CRS UTM32/WGS84 code. PROJECTION "init=epsg:32632" END

METADATA qstring_validation_pattern '.' END

CLASS NAME "FNM stations (WGS84-UTM)"

# Four different kind of EXPRESSION are available to define the membership # to one specific class: # # # # # # # # # # strings comparison (case sensitive and fastest to evaluate). regular expression (a regular expression ( regexp or regex is a string that describes or matches a set of strings, according to certain syntax rules. For example they are used by text editors and utilities to search and manipulate bodies of text based on certain patterns). Examples available at: http://umn.mapserver.ch/index_en.php logical expression, delimited by parentheses "(expression)". Attribute
15

GIS Exercise Spring 2011

# # # # # #

names are delimited by square brackets "[ATTRIBUTE]". The following logical operators are supported: =,>,<,<=,>=,=,or,and,lt,gt,ge,le,eq,ne. lenght function of the string; example: EXPRESSION (length('[NAME_E]') < 8)

# In the following, by using expression, "FNM" and "FS" stations are # given different symbols and colors. EXPRESSION "FNM"

LABEL TYPE truetype FONT "arial" SIZE 9 POSITION auto COLOR 0 200 0 BACKGROUNDCOLOR 200 255 0 #SHADOWSIZE 1 1 #SHADOWCOLOR 0 0 0 #BACKGROUNDSHADOWSIZE 5 5 #BACKGROUNDSHADOWCOLOR 0 100 0 END STYLE SYMBOL "7x7square" COLOR 0 200 0 END END

CLASS NAME "FS stations (WGS84-UTM)" EXPRESSION "FS" LABEL TYPE truetype FONT "mtypcors" SIZE 10 POSITION auto
GIS Exercise Spring 2011 16

COLOR 0 0 157 BACKGROUNDCOLOR 0 220 255 END STYLE SYMBOL "7x7square" COLOR 0 0 157 END END END

#...........................................................................

# 9th LAYER: it is a vector (MapInfo) layer. It is read through the OGR library.

LAYER NAME "alluvional-cones" STATUS on TYPE line

# CONNECTIONTYPE specifies the connection: # CONNECTIONTYPE [local|sde|ogr|postgis|oraclespatial|wms] CONNECTIONTYPE OGR

# Relative path and data file (here the path is from the mapfile) CONNECTION "data/ogr/alluvional-cones.tab"

MAXSCALEDENOM 100000 CLASS NAME "Alluvional cones" STYLE COLOR 214 49 148 END END END

#...........................................................................
GIS Exercise Spring 2011 17

# 10th LAYER: it is the same as the 8th layer but in the Gauss/Boaga projection.

LAYER NAME "stationsgb" STATUS on DATA "GaussBoaga/stations" TYPE point CLASSITEM "COMP_CODE" LABELITEM "NAME" LABELMAXSCALEDENOM 100000 HEADER "header_f.html" FOOTER "footer_f.html" TEMPLATE "query_f.html"

CLASS NAME "FNM stations (GB)" EXPRESSION "FNM" LABEL TYPE truetype FONT "arial" SIZE 9 POSITION auto COLOR 0 200 0 BACKGROUNDCOLOR 200 255 0 END STYLE SYMBOL "7x7square" COLOR 250 215 0 END END

CLASS NAME "FS stations (GB)" EXPRESSION "FS" LABEL


GIS Exercise Spring 2011 18

TYPE truetype FONT "mtypcors" SIZE 10 POSITION auto COLOR 0 0 157 BACKGROUNDCOLOR 0 220 255 END STYLE SYMBOL "7x7square" COLOR 230 70 157 END END END

# end of the Map Object END

GIS Exercise Spring 2011

19

Anda mungkin juga menyukai