9

I visualize a shape-layer in the mapserver. Now I want to make some requests for only some classes of this layer. I want for example one request for only the water-classes and later for only the wood-classes. Can I realise this with the mapserver?

3 Answers 3

7

Here is another way that you can do it. This way involves using one layer with expressions in each class. It is a little more 'expensive' to do it this way because it involves logical expressions, but you may never notice the difference unless you hit really high-load situations.

Each class has a two-part expression. Both parts of the expression need to be true for the features to be drawn. The first part of the expression selects the features that should fall into that class based on an attribute in your shapefile. The second part of the expression evaluates the value of a variable passed in through the url. It doesn't matter what you name the variable in your url (don't use any reserved words like 'layer'), it just has to match the variable name in your expression.

Here are some sample layers:

LAYER
  NAME "watersheds"
  STATUS DEFAULT
  DATA 'majclip'
  TYPE POLYGON
    CLASS
       NAME "water"
       EXPRESSION ([MAJOR] < 42 AND '%wanted%' = 'water')
       STYLE
          COLOR 0 0 255
       END
    END
    CLASS
       NAME "wood"
       EXPRESSION ([MAJOR] >= 42 AND '%wanted%' = 'wood')
       STYLE
          COLOR 0 255 0
       END
    END
END

To draw just the water features, you would use a URL request like this: http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/mymapfile.map&mode=map&wanted=wood

Since this is the third valid way of accomplishing your goal, you really want to think about what your objectives are. If your data changes frequently, you may want to go with this option. If your data doesn't change as often, I would personally go with two layers. I might even split the shapefile into multiple shapefiles by land use type if that improved performance. (It might not, layer filters are pretty efficient). With Web mapping, the more you pre-optimize your data, the better.

7

You should in your case have two layers, one for wood and one for water. You can have two layers using the same shapefile..

Then you canchoose what layers to visualize directly in the request by the LAYERS parameter. The classes only represent different parts of the data (e.g. how data in that layers should be rendered).

4

If you really, really need them all in one layer, you can used Named Styles to achieve this. See here for more details. Peter's suggestion of multiple layers is in many ways a much simpler approach, however.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.