Example 1.3: Displaying Classes in a Layer

By using non-spatial attribute information in the data, we can create a map like this:


This is what the mapfile looks like (Example1-3.map):


The mapfile structure, by objects, looks like this:

                                  MAP
      (states_poly) LAYER----------|---------LAYER (states_line)
                      |                      |
       (land) CLASS---|---CLASS (water)      |-CLASS
                  |       |                    |
            STYLE-|       |-STYLE              |-STYLE

Our mapfile still only has two layers but the polygon layer has been broken down into two classes. Let's have a look at the additional parameters:

CLASSITEM
This keyword is used to specify what attribute to use in separating the class objects. In this example that attribute is "CLASS". If you open the database file associated with this layer's shapefile, you'll see that there's a column (attribute) called "CLASS".

How do we know which attribute to use? It is recommended to use ogrinfo to display basic attribute info in your vector data-look back at example 1.1 (the last few lines after "Layer SRS WKT:" show the attribute names and types). In this case, since database records in shapefiles are stored in DBF files, we can also open it in a spreadsheet program such as LibreOffice, or in desktop software such as QGIS. If your data came with a metadata (and it should!), you can skim through through that metadata file for attribute information..

EXPRESSION
For each class, we specify what attribute value to use. This is the simplest form of EXPRESSION. EXPRESSIONs can be even more complex than this, allowing one to evaluate regular or logical expressions. Please look at the mapfile reference page to see what you can do with EXPRESSION.


Back to Example 1.2 | Back to the Section 1 | Back to the Sections Page | Proceed to Example 1.4