1

Can I set the title of an SLD rule using a feature's field?

I have a very dynamic dataset where the value of a polygon changes after each update, therefore I need to be able to compare using one field and label the style rule with another field to create a legible legend.

Below I have a rule using the SLD syntax. I am able to use a PropertyName tag to compare two values, is it possible to similarly use a PropertyName tag (or equivalent) to change the Description's Title tag?

    <se:Rule>
      <se:Name>0</se:Name>
      <se:Description>
        <se:Title>0</se:Title>
      </se:Description>
      <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
        <ogc:PropertyIsEqualTo>
          <ogc:PropertyName>myFieldName</ogc:PropertyName>
          <ogc:Literal>1</ogc:Literal>
        </ogc:PropertyIsEqualTo>
      </ogc:Filter>
      <se:PolygonSymbolizer>
        <se:Fill>
          <se:SvgParameter name="fill">#820000</se:SvgParameter>
        </se:Fill>
        <se:Stroke>
          <se:SvgParameter name="stroke">#000001</se:SvgParameter>
          <se:SvgParameter name="stroke-width">1</se:SvgParameter>
          <se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
        </se:Stroke>
      </se:PolygonSymbolizer>
    </se:Rule>

In GeoServer simply adding a PropertyName tag returns the following:

Element 'se:Title' is a simple type, so it must have no element information item [children].

I've tried adding a function within the tag and get the same result. Adding a PropertyName tag within the Description tag returns:

line 11: cvc-complex-type.2.4.a: Invalid content was found starting with element 'ogc:PropertyName'. One of '{"http://www.opengis.net/se":Title, "http://www.opengis.net/se":Abstract}' is expected.

  • 1
    What did you try? What happened when you did that? – Ian Turton Jun 25 '18 at 17:14
  • I'm asking a general question about what is possible within the SLD syntax. Can you pull a field from a feature and use it as a title instead of setting a static title? – WxPilot Jun 25 '18 at 18:23
  • 1
    Please take the tour and get a feel for the sort of questions that we like around here. – Ian Turton Jun 25 '18 at 18:27
  • Does my edited question better fit your community standard? – WxPilot Jun 25 '18 at 18:58
  • 1
    why not try this out for yourself? – Ian Turton Jun 25 '18 at 18:59
1

No, a rule title cannot be feature dependent, it's a static element that cannot depend on features (a single rule normally matches many, and the rule title is also used to generate legends, in complete absence of features).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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