1

Given is following SLD rule:

<sld:Rule>
  <sld:Name>mytrack#</sld:Name>
  <ogc:Filter>
    <ogc:PropertyIsEqualTo>
      <ogc:PropertyName>jogging</ogc:PropertyName>
      <ogc:Literal>always#</ogc:Literal>
    </ogc:PropertyIsEqualTo>
  </ogc:Filter>
  <sld:MinScaleDenominator>100</sld:MinScaleDenominator>
  <sld:MaxScaleDenominator>1000</sld:MaxScaleDenominator>
  <sld:LineSymbolizer>
    <sld:Geometry>
      <ogc:PropertyName>alltracks</ogc:PropertyName>
    </sld:Geometry>
    <sld:Stroke>
      <sld:CssParameter name="stroke">#ff0000</sld:CssParameter>
      <sld:CssParameter name="stroke-width">1</sld:CssParameter>
    </sld:Stroke>
  </sld:LineSymbolizer>
</sld:Rule>

which I would write with css like:

[jogging='always#'][@scale>100][@scale<1000] {
  stroke: #FF0000;
  stroke-width: 1;
}

and what is translated by geoserver into following sld:

    <?xml version="1.0" encoding="UTF-8"?><sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
  <sld:NamedLayer>
    <sld:Name>Default Styler</sld:Name>
    <sld:UserStyle>
      <sld:Name>Default Styler</sld:Name>
      <sld:FeatureTypeStyle>
        <sld:Rule>
          <ogc:Filter>
            <ogc:PropertyIsEqualTo>
              <ogc:PropertyName>jogging</ogc:PropertyName>
              <ogc:Literal>always#</ogc:Literal>
            </ogc:PropertyIsEqualTo>
          </ogc:Filter>
          <sld:MinScaleDenominator>100.0</sld:MinScaleDenominator>
          <sld:MaxScaleDenominator>1000.0</sld:MaxScaleDenominator>
          <sld:LineSymbolizer>
            <sld:Stroke>
              <sld:CssParameter name="stroke">#0029FF</sld:CssParameter>
              <sld:CssParameter name="stroke-width">1.5</sld:CssParameter>
            </sld:Stroke>
          </sld:LineSymbolizer>
        </sld:Rule>
        <sld:VendorOption name="ruleEvaluation">first</sld:VendorOption>
      </sld:FeatureTypeStyle>
    </sld:UserStyle>
  </sld:NamedLayer>
</sld:StyledLayerDescriptor>

How can rename

<sld:Name>Default Styler</sld:Name>

to

<sld:Name>mytrack#</sld:Name>
1
  • Good question. I couldnt figure it out as well. Changing the name within the SLD breaks the CSS workflow.
    – wumpz
    Commented Jun 25, 2015 at 7:16

1 Answer 1

2

Recently a patch of mine was integrated into GeoTools 15 (I think) to solve this issue for title and abstract (style name is on the way).

https://github.com/geotools/geotools/pull/1017

It uses the not well known possibility of CSS directives within a CSS style.

@styleTitle "myStyleTitle is here";
@styleAbstract "myStyleAbstract is here";

so your style would be:

@styleTitle "mytrack#";

[jogging='always#'][@scale>100][@scale<1000] {
  stroke: #FF0000;
  stroke-width: 1;
}

Maybe the possibility of setting the style title is enough for you.

Edit: At the moment I am not sure setting style name is needed.

2

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.