Opened 13 years ago

Last modified 13 years ago

#3978 new enhancement

SLD each FeatureTypeStyle in a single NamedLayer as separate maplayer

Reported by: matthijsln Owned by: assefa
Priority: normal Milestone:
Component: WMS Server Version: unspecified
Severity: minor Keywords: sld ogc
Cc:

Description

As per the SLD docs, MapServer has a concept of one feature type style per layer.

In the OGC SLD spec 02-070, on page 25 it says

"Note that there is no restriction against a single UserStyle from including multiple FeatureTypeStyles that reference the same FeatureTypeName. This case does not create an exception in the rendering semantics, however, since a map styler is expected to process all FeatureTypeStyles in the order that they appear, regardless, plotting one instance over top of another."

I guess you can interpret this as: all features for a FeatureTypeStyle should be drawn before features for a following FeatureTypeStyle element are drawn.

I have a single (unsorted) data source where one feature should be drawn first and another feature should be drawn on top using another style. Another example is drawing the same feature twice, first with a wide stroke and then a thin center line on top. So I make a SLD like the following:

<StyledLayerDescriptor>
  <NamedLayer><Name>mylayer</Name>
    <UserStyle>...
      <FeatureTypeStyle>...<Rule><Name> bottom </Name>...</Rule></FeatureTypeStyle>
      <FeatureTypeStyle>...<Rule><Name> top </Name>...</Rule></FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

As of now a single maplayer (with classes for Rules for all FeatureTypeStyle childs of the NamedLayer) is created in the temporary mapfile. This of course means with an unsorted data set there is no guarantee all features matching a certain class for a SLD Rule are drawn before another (also a feature can only be drawn once using one class). So, multiple maplayers are needed.

Now with the patch r11717 for #1260 the following SLD works like I want:

<StyledLayerDescriptor>
  <NamedLayer><Name>mylayer</Name>
    <UserStyle>...
      <FeatureTypeStyle>...<Rule><Name> bottom </Name>...</Rule></FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
  <NamedLayer><Name>mylayer</Name>
    <UserStyle>...
      <FeatureTypeStyle>...<Rule><Name> top </Name>...</Rule></FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

This is great, but in my tests GeoServer only picks the first NamedLayer (but supports multiple FeatureTypeStyle elements). It would be nice if I could use the same SLD for both (although multiple NamedLayers is certainly legal in the spec as per the example on page 19 of OGC 02-070).

I have attached a patch that creates a maplayer for each NamedStyle or FeatureTypeStyle found in a SLD.

The biggest changes are in msSLDParseSLD(). msSLDParseNamedLayer() is split up into msSLDParseNamedStyle() and msSLDParseFeatureTypeStyle(), but most of the changed lines are removed spaces for indentation.

It leverages the changes in r11717 for supporting multiple NamedLayers with the same name. The effect of the patch is the same as if the SLD where transformed to move siblings of the first FeatureTypeStyle element to a separate NamedLayer each with the same name (like 2namedlayers.sld).

I've also attached a testcase (testcase.zip) and the results using the two SLD's and various MapServer versions.

Description of testcaseresults.png:

6.1-dev 2fts.sld:
  only HAM features drawn using LAN style, incorrect?!

6.1-dev 2namedlayers.sld:
  correct

6.0.0-beta5 2fts.sld:
  features drawn using correct styles but HAM feature is not drawn last

6.0.0-beta5 2namedlayers.sld:
  only first NamedLayer drawn (pre-r11717)

6.1-dev-patch 2fts.sld:
  correct (maplayer_per_fts.patch)

5.6.3-patch:
  correct (maplayer_per_fts_5.6.3.patch includes r11717 backported)

Attachments (4)

maplayer_per_fts.patch (22.2 KB ) - added by matthijsln 13 years ago.
testcase.zip (73.2 KB ) - added by matthijsln 13 years ago.
testcaseresults.png (155.2 KB ) - added by matthijsln 13 years ago.
maplayer_per_fts_5.6.3.patch (23.1 KB ) - added by matthijsln 13 years ago.
patch for 5.6.3 including r11717 changes

Download all attachments as: .zip

Change History (7)

by matthijsln, 13 years ago

Attachment: maplayer_per_fts.patch added

by matthijsln, 13 years ago

Attachment: testcase.zip added

by matthijsln, 13 years ago

Attachment: testcaseresults.png added

by matthijsln, 13 years ago

patch for 5.6.3 including r11717 changes

comment:1 by matthijsln, 13 years ago

Our client is still using 5.6.x so I also added a patch for 5.6.3 which includes the changes in r11717 backported (no big deal only msStrdup replaced by strdup).

comment:2 by matthijsln, 13 years ago

Component: WMS ClientWMS Server

comment:3 by matthijsln, 13 years ago

My patch for 5.6.3 is missing the changes to mapwms.c though, so it may not be correct.

Note: See TracTickets for help on using tickets.