1

I'm using the following SLD for Rendering a Polygon using GeoServer:

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
                       xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/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>City</Name>
    <UserStyle>
      <Title>City</Title>

      <FeatureTypeStyle>
        <Rule>

          <PolygonSymbolizer>
            <Stroke>
              <CssParameter name="stroke">#FFFFFF</CssParameter>
              <CssParameter name="stroke-width">3</CssParameter>
            </Stroke>
          </PolygonSymbolizer>
        </Rule>
      </FeatureTypeStyle>

      <FeatureTypeStyle>
        <Rule>
          <Title>City</Title>
          <PolygonSymbolizer>
            <Stroke>
              <CssParameter name="stroke">#000000</CssParameter>
              <CssParameter name="stroke-width">1</CssParameter>
            </Stroke>
          </PolygonSymbolizer>
        </Rule>
      </FeatureTypeStyle>

    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

When I make a GetLegendGraphic request, I get an image like: enter image description here

As you can see, it is showing both the FeatureStyles, because of which the top part of the Legend Graphic looks empty.

I know that there is a FEATURETYPE Parameter on the GetLegendGraphic request, but I can find an example of what I need to specify here.

How do I use the FEATURETYPE for GetLegendGraphic request?

1
  • Perhaps you should rather use ´RULE. I don't know how to use it but I would have a try with &RULE=City` But if FEATURETYPE is what needs to be used then I suppose that they should have names in the SLD.
    – user30184
    Apr 25, 2018 at 6:36

1 Answer 1

3

As @user30184 says the FeatureType parameter is for situations where you have multiple types of feature in a layer and only want the legend for one of them. In your case you have multiple rules and only want one of them to be shown. For this you want the Rule parameter:

http://.......&RULE=City 

When the label of the Rule disappears, and you want to get it back, you can do so by using forceLabels:on as part of the legend_options in the request URL.

5
  • This kind of work; I see only Symbol, but the label of 'city' now disappears. Apr 25, 2018 at 7:57
  • yes since you specified the rule name you become responsible for labelling it.
    – Ian Turton
    Apr 25, 2018 at 7:58
  • And how do I do? Is there some way of getting the Label with this Legend Graphic itself? Apr 25, 2018 at 8:06
  • No, you can have all of them with labels or individual ones where you can add your own label - in an html table maybe?
    – Ian Turton
    Apr 25, 2018 at 8:27
  • 1
    I found a way to get it in the Legend Graphic by using forceLabels:on as the legendoptions in the url Apr 25, 2018 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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