0

I am trying to use dynamic styling by providing the sld& parameter in the WMS request. The parameter is pointing to a local file that is modified by a script. Like this: sld=file:///D:/testStyle.sld&.

The issue is that the layer is always displayed with the default style defined on GeoServer. Here is the content of the file:

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0" 
 xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" 
 xmlns="http://www.opengis.net/sld" 
 xmlns:ogc="http://www.opengis.net/ogc" 
 xmlns:xlink="http://www.w3.org/1999/xlink" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <NamedLayer>
    <Name>ne:testLayer</Name>
    <UserStyle>
      <Name>testStyle</Name>
      <Title>simple</Title>
      <FeatureTypeStyle>
        <Rule>
            <PointSymbolizer>
              <Graphic>
                <Mark>
                  <WellKnownName>circle</WellKnownName>
                  <Fill>
                    <CssParameter name="fill">#FF0000</CssParameter>
                  </Fill>
                </Mark>
              <Size>6</Size>
            </Graphic>
          </PointSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

I have tried the following:

  1. Omit the layers& parameter in the WMS request so I do not go into Library Mode. This works fine, but unfortunately I am constrained to use the layers& parameter in the request so this is not an option.
  2. Using the layers& and sld& parameters in the WMS request. I am aware that this will trigger Library Mode. When I do this, the layer is displayed with the default style, not with the style defined in the SLD.
  3. Using the layers&, sld&, styles=testStyle& parameters in the WMS request. When I do this I get an error that tells me the testStyle could not be found. (even though there are no typos)
  4. Using the layers& and sld& parameters in the WMS and also adding the <IsDefault>1</IsDefault> tag in the UserStyle defined in the SLD. In this case, the layers is displayed again with the default style - defined in GeoServer.

The request I am using to preview the layer (only for point 3- since for the other points I just remove some of the parameters):

http://localhost:8080/geoserver/ne/wms?service=WMS&version=1.1.0&request=GetMap&layers=ne%3AtestLayer&bbox=51.230123%2C25.192783%2C51.619153%2C25.405197&width=768&height=419&srs=EPSG%3A404000&format=application/openlayers#toggle&sld=file:///D:/testStyle.sld&styles=testStyle&

What am I doing wrong?

8
  • For using &styles=testStyle the style must be configured on the server side. It will then be included also in the GetCapabilities. One thing that you have not tried yet is to use &SLD_BODY=... with GetMap.
    – user30184
    Nov 16, 2023 at 14:40
  • @user30184 If i configure it on the server side, then the layer will be displayed with the style present on the server side even after I modify the local .sld file. At least this was the behavior when I tried. I will give it a shot with the SLD_BODY=, but this will not meet the requirements because I will not be able to dynamically modify the request from the client side) Nov 16, 2023 at 14:54
  • 1
    I made a test with the default demo layers. Test URL localhost:8080/geoserver/topp/…. I edited the "default_polygon.sld" file in the data directory by changing the stroke-width or fill color with a text editor. The new style is changing the map immediately.
    – user30184
    Nov 16, 2023 at 15:35
  • What do you actually mean by "the layer will be displayed with the style present on the server side even after I modify the local .sld file"? Are you not testing on the same computer that runs GeoServer? If you do not modify the physical file that GeoServer is using, you must either send the SLD inside SLD_BODY or place the SLD file into web where GeoServer can read it through http.
    – user30184
    Nov 16, 2023 at 15:40
  • does gis.stackexchange.com/a/227750/79 help?
    – Ian Turton
    Nov 16, 2023 at 15:43

1 Answer 1

1

I can achieve the result I am looking for by editing the .sld files located in the data directory of GeoServer directly and not passing any &sld parameters to the request.

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.