0

I am trying to clean my GeoServer deleting some redundant SLD Styles.

All this styles work in the same way, they assign some image (different for every style, which name is hardcoded in every style) to every point in the layer, passing the image as an OnlineResource, later as a ExternalGraphic and finally as a PointSimbolizer. I want to replace all this styles by one generic style who have the image name as a parameter.

TODO: Example

In my First attempt I tried to replace the hard coded name of the image using the ogc:Function name="env" and passing the name as a WMS parameter, but this fail because the name is in the OnlineResource tag.

My Second attempt whas to use a CQL_FILTER to pass the name, but i cant add the name as a feature of the layer.

     <Rule>
      <Title>Potencial hidráulico</Title>
      <MinScaleDenominator>3000000</MinScaleDenominator>
      <MaxScaleDenominator>100000000</MaxScaleDenominator>
       <PointSymbolizer>
         <Graphic>
           <ExternalGraphic xmlns="http://www.opengis.net/sld" xmlns:xlink="http://www.w3.org/1999/xlink">
             <OnlineResource xlink:type="simple" xlink:href="${IMG}"  />
             <Format>image/png</Format>
           </ExternalGraphic>
           <Size>10</Size>
         </Graphic>
       </PointSymbolizer>
    </Rule>

Calling with this URL:

http://192.168.72.26:8080/geoserver/[workspace]/wms?&CQL_FILTER=IMG=%27gen_hiroelectrica.png%27&service=WMS&version=1.1.0&request=GetMap&layers=[workspace]%3A[layer]

Giving me this error:

2022-06-06 11:43:24,712 ERROR [geoserver.ows] - org.geoserver.platform.ServiceException: The requested Style can not be used with this layer. The style specifies an attribute named 'IMG', not found in the '[workspace]:[layer]' layer

Are any of those way correct? There is other alternative way to parameterize the name of the image? It is even possible (or recommended) to replace all the redundant styles by one generic style?

2
  • Please show us what you tried and what went wrong
    – Ian Turton
    Jun 3 at 17:17
  • I am going to add the example when I come back to the office this monday. Thanks for the comment. Jun 3 at 18:06

1 Answer 1

2

If I get your request correctly, you're looking for a special customization of SLD (not standard) that is called "dynamic symbolizers" in GeoServer. See this old blog post about it (very old, SLD got ruined during the various migrations in the last 14 years):

https://geoserver.org/tips%20and%20tricks/2008/12/08/dynamic-symbolizers-part-1.html

In short, functionalty allows to embed a generic CQL expression inside the URL of a external graphic:

http://www.usautoparts.net/bmw/images/states/tn_${strToLowerCase(STATE_ABBR)}.jpg

There are however downsides to this approach: GeoServer will not be able to generate a legend image any more, as the contents of it now depend dynamically on the values of your data.

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.