Personal tools
You are here: Home Documentation References

8. Layer

Document Actions
Up one level
The most used object in a MapFile, this one describes layers used to make up a map. Layers are drawn in their order of appearance in the MapFile (first layer is at the bottom, last in on top).
CLASS
Signals the start of a CLASS object.
CLASSITEM [attribute]
Item name in attribute table to use for class lookups.
CLASSGROUP [string]
Specify the class's group that would be considered at rendering time. The CLASS object's GROUP parameter must be used in combination with CLASSGROUP.
CONNECTION [string]

Database connection string to retrieve remote data.

An SDE connection string consists of a hostname, instance name, database name, username and password separated by commas.

A PostGIS connection string is basically a regular PostgreSQL connection string, it takes the form of "user=nobody password=****** dbname=dbname host=localhost port=5432"

An Oracle connection string: user/pass[@db]

CONNECTIONTYPE [local|sde|ogr|postgis|oraclespatial|wms]
Type of connection. Default is local. See additional documentation for any other type.
DATA [filename]|[sde parameters][postgis table/column][oracle table/column]

Full filename of the spatial data to process. No file extension is necessary for shapefiles. Can be specified relative to the SHAPEPATH option from the Map Object.

If this is an SDE layer, the parameter should include the name of the layer as well as the geometry column, i.e. "mylayer,shape,myversion".

If this is a PostGIS layer, the parameter should be in the form of "<columnname> from <tablename>", where "columnname" is the name of the column containing the geometry objects and "tablename" is the name of the table from which the geometry data will be read.

For Oracle, use "shape FROM table" or "shape FROM (SELECT statement)" or even more complex Oracle compliant queries! Note that there are important performance impacts when using spatial subqueries however. Try using MapServer's FILTER whenever possible instead. You can also see the SQL submitted by forcing an error, for instance by submitting a DATA parameter you know won't work, using for example a bad column name.

DEBUG [off|on|0|1|2|3|4|5]

Enables debugging of a layer in the current map.

Debugging with MapServer versions >= 5.0:

Verbose output is generated and sent to the standard error output (STDERR) or the MapServer errorfile if one is set using the "MS_ERRORFILE" environment variable. You can set the environment variable by using the CONFIG parameter at the MAP level of the mapfile, such as:

CONFIG "MS_ERRORFILE" "/ms4w/tmp/ms_error.txt"

You can also set the environment variable in Apache by adding the following to your httpd.conf:

SetEnv MS_ERRORFILE "/ms4w/tmp/ms_error.txt"

Once the environment variable is set, the DEBUG mapfile parameter can be used to control the level of debugging output. Here is a description of the possible DEBUG values:

DEBUG O or OFF - only msSetError() calls are logged to MS_ERRORFILE. No
                 msDebug() output at all. This is the default and
                 corresponds to the original behavior of MS_ERRORFILE in
                 MapServer 4.x

DEBUG 1 or ON  - includes all output from DEBUG 0 plus msDebug() warnings
                 about common pitfalls, failed assertions or non-fatal
                 error situations (e.g. missing or invalid values for some
                 parameters, missing shapefiles in tileindex, timeout
                 error from remote WMS/WFS servers, etc.)

DEBUG 2        - includes all output from DEBUG 1 plus notices and timing
                 information useful for tuning mapfiles and applications

DEBUG 3        - all of DEBUG 2 plus some debug output useful in
                 troubleshooting problems such as WMS connection URLs
                 being called, database connection calls, etc.  This is 
                 the recommended level for debugging mapfiles.

DEBUG 4        - DEBUG 3 plus even more details...

DEBUG 5        - DEBUG 4 plus any msDebug() output that might be more
                 useful to the developers than to the users.

You can also set the debug level by using the "MS_DEBUGLEVEL" environment variable.

The DEBUG setting can also be specified for the entire map, by setting the DEBUG parameter in the MAP object.

For more details on this debugging mechanism, please see RFC 28.

Debugging with MapServer versions < 5:

Verbose output is generated and sent to the standard error output (STDERR) or the MapServer logfile if one is set using the LOG parameter in the WEB object. Apache users will see timing details for drawing in Apache's error_log file. Requires MapServer to be built with the DEBUG=MSDEBUG option (--with-debug configure option).

DUMP [true|false]
Switch to allow mapserver to return data in GML format. Usefull when used with WMS GetFeatureInfo operations. "false" by default.
FEATURE
Signals the start of a FEATURE object.
FILTER [string]

This parameter allows for data specific attribute filtering that is done at the same time spatial filtering is done, but before any CLASS expressions are evaluated. For OGR and shapefiles the string is simply a mapserver regular expression. For spatial databases the string is a SQL WHERE clause that is valid with respect to the underlying database.

For example: FILTER "type='road' and size <2"

FILTERITEM [attribute]
Item to use with simple FILTER expressions. OGR and shapefiles only.
FOOTER [filename]
Template to use after a layer's set of results have been sent. Multiresult query modes only.
GRID
Signals the start of a GRID object.
GROUP [name]
Name of a group that this layer belongs to. The group name can then be reference as a regular layer name in the template files, allowing to do things like turning on and off a group of layers at once.
HEADER [filename]
Template to use before a layer's set of results have been sent. Multiresult query modes only.
JOIN
Signals the start of a JOIN object.
LABELANGLEITEM [attribute]
Item name in attribute table to use for class annotation angles. Values should be in degrees.
LABELCACHE [on|off]
Specifies whether labels should be drawn as the features for this layer are drawn, or whether they should be cached and drawn after all layers have been drawn. Default is on. Label overlap removal, auto placement etc... are only available when the label cache is active.
LABELITEM [attribute]
Item name in attribute table to use for class annotation (i.e. labeling).
LABELMAXSCALEDENOM [double]
Maximum scale at which this LAYER is labeled. Scale is given as the denominator of the actual scale fraction, for example for a map at a scale of 1:24,000 use 24000. Implemented in MapServer 5.0, to replace the deprecated LABELMAXSCALE parameter.
LABELMAXSCALE [double] - deprecated
Since MapServer 5.0 the proper parameter to use is LABELMAXSCALEDENOM instead. The deprecated LABELMAXSCALE is the maximum scale at which this LAYER is labeled. Scale is given as the denominator of the actual scale fraction, for example for a map at a scale of 1:24,000 use 24000.
LABELMINSCALEDENOM [double]
Minimum scale at which this LAYER is labeled. Scale is given as the denominator of the actual scale fraction, for example for a map at a scale of 1:24,000 use 24000. Implemented in MapServer 5.0, to replace the deprecated LABELMINSCALE parameter.
LABELMINSCALE [double] - deprecated
Since MapServer 5.0 the proper parameter to use is LABELMINSCALEDENOM instead. The deprecated LABELMINSCALE is the minimum scale at which this LAYER is labeled. Scale is given as the denominator of the actual scale fraction, for example for a map at a scale of 1:24,000 use 24000.
LABELREQUIRES [expression]

Sets context for labeling this layer, for example:

LABELREQUIRES "![orthoquads]"

means that this layer would NOT be labeled if a layer named "orthoquads" is on. The expression consists of a boolean expression based on the status of other layers, each [layer name] substring is replaced by a 0 or a 1 depending on that layer's STATUS and then evaluated as normal. Logical operators AND and OR can be used.

LABELSIZEITEM [attribute]
Item name in attribute table to use for class annotation sizes. Values should be in pixels.
MAXFEATURES [integer]
Specifies the number of features that should be drawn for this layer in the CURRENT window. Has some interesting uses with annotation and with sorted data (i.e. lakes by area).
MAXSCALEDENOM [double]
Maximum scale at which this LAYER is drawn. Scale is given as the denominator of the actual scale fraction, for example for a map at a scale of 1:24,000 use 24000. Implemented in MapServer 5.0, to replace the deprecated MAXSCALE parameter.
MAXSCALE [double] - deprecated
Since MapServer 5.0 the proper parameter to use is MAXSCALEDENOM instead. The deprecated MAXSCALE is the maximum scale at which this LAYER is drawn. Scale is given as the denominator of the actual scale fraction, for example for a map at a scale of 1:24,000 use 24000.
METADATA

This keyword allows for arbitrary data to be stored as name value pairs. This is used with OGC WMS to define things such as layer title. It can also allow more flexibility in creating templates, as anything you put in here will be accessible via template tags.

Example:

METADATA
    title "My layer title"
    author "Me!"
END
MINSCALEDENOM [double]
Minimum scale at which this LAYER is drawn. Scale is given as the denominator of the actual scale fraction, for example for a map at a scale of 1:24,000 use 24000. Implemented in MapServer 5.0, to replace the deprecated MINSCALE parameter.
MINSCALE [double] - deprecated
Since MapServer 5.0 the proper parameter to use is MINSCALEDENOM instead. The deprecated MINSCALE is the minimum scale at which this LAYER is drawn. Scale is given as the denominator of the actual scale fraction, for example for a map at a scale of 1:24,000 use 24000.
NAME [string]
Short name for this layer. Limit is 20 characters. This name is the link between the mapfile and web interfaces that refer to this name. They must be identical. The name should be unique, unless one layer replaces another at different scales. Use the GROUP option to associate layers with each other.
OFFSITE [r] [g] [b]
Sets the color index to treat as transparent for raster layers.
OPACITY [integer|alpha]

Sets the opacity level (or the inability to see through the layer) of all classed pixels for a given layer. The value can either be an integer in the range (0-100) or the named symbol "ALPHA". A value of 100 is opaque and 0 is fully transparent. Implemented in MapServer 5.0, to replace the deprecated TRANSPARENCY parameter.

The "ALPHA" symbol directs the MapServer rendering code to honor the indexed or alpha transparency of pixmap symbols used to style a layer. This is only needed in the case of RGB output formats, and should be used only when necessary as it is expensive to render transparent pixmap symbols onto an RGB map image.

POSTLABELCACHE [true|false]
Tells MapServer to render this layer after all labels in the cache have been drawn. Useful for adding neatlines and similar elements. Default is false.
PROCESSING [string]

Passes a processing directive to be used with this layer. The supported processing directives vary by layer type, and the underlying driver that processes them. Here we see the SCALE and BANDs directives used to autoscale raster data and alter the band mapping. All raster processing options are described in the Raster Data Access HOWTO.

PROCESSING "SCALE=AUTO"
PROCESSING "BANDS=3,2,1"

This is also where you can enable connection pooling for certain layer layer types. Connection pooling will allow MapServer to share the handle to an open database or layer connection throughout a single map draw process. Additionally, if you have FastCGI enabled, the connection handle will stay open indefinitely, or according to the options specified in the FastCGI configuration. Oracle, ArcSDE, OGR and PostGIS currently support this approach.

PROCESSING "CLOSE_CONNECTION=DEFER" 
PROJECTION
Signals the start of a PROJECTION object.
REQUIRES [expression]
Sets context for displaying this layer (see LABELREQUIRES).
SIZEUNITS [pixels|feet|inches|kilometers|meters|miles|
Sets the unit of CLASS object SIZE values (default is pixels). Useful for simulating buffering.
STATUS [on|off|default]

Sets the current status of the layer. Often modified by MapServer itself. Default turns the layer on permanently.

Some notes regarding the STATUS values:

  • In CGI mode, layers with STATUS DEFAULT cannot be turned off using normal mechanisms. It is recommended to set layers to STATUS DEFAULT while debugging a problem, but set them back to ON/OFF in normal use.
  • For WMS, layers in the server mapfile with STATUS DEFAULT are always sent to the client.
STYLEITEM [attribute]
Item to use for feature specific styling. This is very experimental and OGR only at the moment.
SYMBOLSCALEDENOM [double]
The scale at which symbols and/or text appear full size. This allows for dynamic scaling of objects based on the scale of the map. If not set then this layer will always appear at the same size. Scaling only takes place within the limits of MINSIZE and MAXSIZE as described above. Scale is given as the denominator of the actual scale fraction, for example for a map at a scale of 1:24,000 use 24000. Implemented in MapServer 5.0, to replace the deprecated SYMBOLSCALE parameter.
SYMBOLSCALE [double] - deprecated
Since MapServer 5.0 the proper parameter to use is SYMBOLSCALEDENOM instead. The deprecated SYMBOLSCALE is the scale at which symbols and/or text appear full size. This allows for dynamic scaling of objects based on the scale of the map. If not set then this layer will always appear at the same size. Scaling only takes place within the limits of MINSIZE and MAXSIZE as described above. Scale is given as the denominator of the actual scale fraction, for example for a map at a scale of 1:24,000 use 24000.
TEMPLATE [file|url]
Used as a global alternative to CLASS TEMPLATE.
TILEINDEX [filename|layername]

Name of the tileindex file or layer. A tileindex is similar to an ArcInfo library index. The tileindex contains polygon features for each tile. The item that contains the location of the tiled data is given using the TILEITEM parameter. When a file is used as the tileindex for shapefile or raster layers, the tileindex should be a shapefile. For CONNECTIONTYPE OGR layers, any OGR supported datasource can be a tileindex. Normally the location should contain the path to the tile file relative to the shapepath, not relative to the tileindex itself. If the DATA parameter contains a value then it is added to the end of the location. When a tileindex layer is used, it works similarly to directly referring to a file, but any supported feature source can be used (ie. postgres, oracle).

NOTE: All files in the tileindex should have the same coordinate system, and for vector files the same set of attributes in the same order.

TILEITEM [attribute]
Item that contains the location of an individual tile, default is "location".
TOLERANCE [double]
Sensitivity for point based queries (i.e. via mouse and/or map coordinates). Given in TOLERANCEUNITS. If the layer is a POINT or a LINE, the default is 3. For all other layer types, the default is 0. To restrict polygon searches so that the point must occur in the polygon set the tolerance to zero.
TOLERANCEUNITS [pixels|feet|inches|kilometers|meters|miles|dd]
Units of the TOLERANCE value. Default is pixels.
TRANSPARENCY [integer|alpha] - deprecated

Since MapServer 5.0 the proper parameter to use is OPACITY instead. The deprecated TRANSPARENCY parameter sets the transparency level of all classed pixels for a given layer. The value can either be an integer in the range (0-100) or the named symbol "ALPHA". Although this parameter is named "transparency", the integer values actually parameterize layer opacity. A value of 100 is opaque and 0 is fully transparent.

The "ALPHA" symbol directs the mapserver rendering code to honor the indexed or alpha transparency of pixmap symbols used to style a layer. This is only needed in the case of RGB output formats, and should be used only when necessary as it is expensive to render transparent pixmap symbols onto an RGB map image.

TRANSFORM [true|false ul|uc|ur|lc|cc|lr|ll|lc|lr]

Tells MapServer whether or not a particular layer needs to be transformed from some coordinate system to image coordinates. Default is true. This allows you to create shapefiles in image/graphics coordinates and therefore have features that will always be displayed in the same location on every map. Ideal for placing logos or text in maps. Remember that the graphics coordinate system has an origin in the upper left hand corner of the image, contrary to most map coordinate systems.

Version 4.10 introduces the ability to define features with coordinates given in pixels (or percentatges, see UNITS), most often inline features, relative to something other than the UL corner of an image. That is what 'TRANSFORM FALSE' means. By setting an alternative origin it allows you to anchor something like a copyright statement to another portion of the image in a way that is independent of image size.

TYPE [point|line|polygon|circle|annotation|raster|query|chart]

Specifies how the data should be drawn. Need not be the same as the shapefile type. For example, a polygon shapefile may be drawn as a point layer, but a point shapefile may not be drawn as a polygon layer. Common sense rules. Annotation means that a label point will be calculated for the features, but the feature itself will not be drawn although a marker symbol can be optionally drawn. this allows for advanced labeling like numbered highway shields. Points are labeled at that point. Polygons are labeled first using a centroid, and if that doesn't fall in the polygon a scanline approach is used to guarantee the label falls within the feature. Lines are labeled at the middle of the longest arc in the visible portion of the line. Query only means the layer can be queried but not drawn.

In order to differentiate between POLYGONs and POLYLINEs (which do not exist as a type), simply respectively use or ommit the COLOR keyword when classifying. If you use it, it's a polygon with a fill color, otherwise it's a polyline with only an OUTLINECOLOR.

For CHART layers, see the Dynamic Charting howto.

A circle must be defined by a a minimum bounding rectangle. That is, 2 points that define the smallest square that can contain it. These 2 points are the two opposite corners of said box.

The following is an example using inline points to draw a circle:

LAYER
  NAME 'inline_circles'
  TYPE CIRCLE
  STATUS ON
  FEATURE
    POINTS
      74.01 -53.8
      110.7 -22.16
    END
  END  
  CLASS
    STYLE
      COLOR 0 0 255
    END
  END
END                 
UNITS [feet|inches|kilometers|meters|miles|dd|pixels|percentages]
Units of the layer. Percentages was added in MapServer 4.10 and is mostly geared for inline features.
by Jeff McKenna last modified 2008-07-18 13:34

STATUS ON is not always on

Posted by Greg Yetman at 2005-09-09 10:09
STATUS DEFAULT means that the layer will always be displayed, ON means that the layer will be displayed <ita>if requested</ita>. OFF means that the layer is turned off. These can be changed by MapServer itself.

Template

Posted by Aaron Stafford at 2006-01-19 02:22

If you want query results for this layer, make sure that a template is defined, even if it is a zero-length file, or else mapserver will not perform the query. This is especially important for use with MapScript.

TEMPLATE

Posted by Lara Perez at 2006-07-25 02:27

¿Does mapserver resolve a query about a line layer? I have problems to get it.

Use scale in filter?

Posted by Brian DeRocher at 2006-08-15 19:00

Is it possible to use the scale in the filter query sent to the database? It would be nice to select only those cities appropriate for a given scale, say where area < 1 / log(scale).

Re: Use scale in filter?

Posted by Stephen Lime at 2006-08-20 22:08

No, that's not supported, although it's a good idea. Perhaps worthy of a feature request...

Steve

subqueries using DATA with PostGIS

Posted by C Chamberlin at 2007-01-31 16:06
Might be worth mentioning here that there's some support for subqueries in the DATA statement for PostGIS, of the form:
DATA "geom FROM (SELECT * FROM geom ORDER BY attr) AS table_2"

I found this useful to tell Mapserver to draw some features on top of others; those that come later in the sort order are drawn later.

See http://postgis.refractions.net/pipermail/postgis-users/2002-September/001472.html

URL Query Templates

Posted by David Fawcett at 2007-09-24 13:20
You can only use a URL template for a query in mode=query or mode=itemquery. If you try it with mode=nquery or mode=itemnquery, you will get the error:

Content-type: text/html msReturnPage(): Web application error. Malformed template name

Problems using filters with GEODATABASE

Posted by David Arenas at 2008-09-04 10:15
Hi everyone!

I´m trying to use filters connecting with a GDB. I type the following in my map file:

FILTERITEM "OTRAS_FORM"
FILTER ('[OTRAS_FORM]' = 'BANCO SUBMARINO' or '[OTRAS_FORM]' = 'HOYA SUBMARINA')

The thing is if I inactive those lines mapserver works perfectly....but, of course, without filters.

the error lines are:

"[Thu Sep 04 15:15:17 2008].578000 msOracleSpatialLayerWhichShapes(): OracleSpatial error. Error: ORA-00933: comando SQL no terminado correctamente
. Query statement: SELECT OBJECTID, OTRAS_FORM, SHAPE FROM (SELECT OBJECTID, SHAPE, OTRAS_FORM FROM RN_GEODMG.INFO_OTRAS_FORMAS_MED_MAR) WHERE OTRAS_FORM = '[OTRAS_FORM]' = 'BANCO SUBMARINO' or '[OTRAS_FORM]' = 'HOYA SUBMARINA' AND SDO_FILTER( SHAPE, MDSYS.SDO_GEOMETRY(2003, NULL, NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,3),MDSYS.SDO_ORDINATE_ARRAY(60298.583,3980828.85,649701.417,4298521.15) ),'querytype=window') = 'TRUE' . Check your data statement.
[Thu Sep 04 15:15:17 2008].578000 msDrawMap(): Image handling error. Failed to draw layer named 'morf_dv2'.
[Thu Sep 04 15:15:22 2008].937000 msOracleSpatialLayerWhichShapes(): OracleSpatial error. Error: ORA-00933: comando SQL no terminado correctamente"

Thanks a million

cheers

Powered by Plone