what is class, expression?

Pericles S. Nacionales pnaciona at gis.umn.edu
Tue Jun 13 14:00:39 EDT 2000


Bernard,

The CLASS keyword defines how the layer will be represented in the output
(the map and the legend).  So, if you have something like...

LAYER # start layer defs
    NAME watershed
    TYPE POLYGON
    STATUS ON
    DATA mjwshed

    CLASS
        NAME "Major Watersheds"
        SYMBOL 0
        COLOR 255 0 255
        OUTLINECOLOR 0 0 0
    END
END # layer defs

MapServer will draw the map of the watershed polygons in magenta, with black
as the outline color (to delineate the boundary of each polygon).  It will
also create a legend with the name "Major Watersheds" (sans quotes).  Here
you have created a layer with a single class--much like what you would see
when you add a new theme in ArcView.

However, you probably would like to give each watershed polygon (catchment,
if you prefer) a different color to emphasize their uniqueness (or to
separate the different regions, etc.).  That's when you need to specify
several classes.  That's also when you need to use the CLASSITEM and
EXPRESSION tags (or keywords, in MapServer-speak).  Basically, the CLASSITEM
keyword defines which table attribute, and the EXPRESSION keyword defines
what attribute values, to use in defining the classes.  For example, if the
"mjwshed" shapefile (the example data above) has a database with an
attribute "Region" with values that define which region each major watershed
belongs to, you can use it to define your classes.  So, your LAYER
definition would then look something like:

LAYER # start layer defs
    NAME watershed
    TYPE POLYGON
    STATUS ON
    DATA mjwshed
    CLASSITEM "region"

    CLASS
        NAME "Upper Mississippi"
        EXPRESSION "1"
        SYMBOL 0
        COLOR 255 128 128
        OUTLINECOLOR 0 0 0
    END

    CLASS
        NAME "Great Lakes"
        EXPRESSION "2"
        SYMBOL 0
        COLOR 128 255 128
        OUTLINECOLOR 0 0 0
    END

    CLASS
        NAME "Souris-Red-Rainy"
        EXPRESSION "3"
        SYMBOL 0
        COLOR 255 128 128
        OUTLINECOLOR 0 0 0
    END

END # layer defs

In this example the EXPRESSION keyword uses the values in the "Region"
attribute.  (Note:  this is a simple example and EXPRESSION can have far
more advanced uses).

I hope my explanations didn't confuse you any further.  If you want to see
an example, go to
http://terrasip.gis.umn.edu/cgi-bin/mapserv?map=/data/projects/avhrr/avhrr_j
ava.map&layer=watershed

The map you'll see is nearly identical to the output of the example layer
definition above.  If you want more examples, go to the MapServer tutorial
at http://terrasip.gis.umn.edu/projects/tutorial.

Good luck!
Perry Nacionales

----- Original Message -----
From: "Lap Lo" <lap at cs.wisc.edu>
To: <mapserver-users at lists>
Sent: Saturday, June 10, 2000 11:37 AM
Subject: what is class, expression?


> Hi,
>
> I am new to mapserver. I just installed mapserver 3.3. I got a copy of
> demo from the web and I have trouble understanding some of the features of
> Class Object.
>
> This is a brief introduction of class object given by mapserver 3.3
> documentation,
>
> "Used to define thematic classes for a given layer and each (vector) layer
> must have at least one class. In cases with more than one class,
> membership is determined using attribute values and regular expressions.
> Starts with the keyword class and terminates with the
> keyword end."
>
> These are my questions,
>
> 1) what is the function of a class inside the layer object?
> 2) Why do we need more than one class?
> 3) Please look at some example code below,
>
>    CLASSITEM usclass
>    CLASS
>      NAME "Water & Rivers"
>      EXPRESSION "421"
>      COLOR 49 117 185
>      BACKGROUNDCOLOR 32 201 201
>      OUTLINECOLOR 0 0 0
>    END
>    CLASS
>      EXPRESSION "^-"
>      COLOR 255 0 0
>      OUTLINECOLOR 0 0 0
>    END
>
> a)what is the function of expressions?
> b)why do they have some strange values like "421"? Can I say "422"?
>
> Thanks a lot.
>
> Bernard
>




More information about the mapserver-users mailing list