2

I am working with Geoserver for some weeks now and were able to deploy some services already. For my thematic map (e.g. temperature) I created a custom style displaying all tiles in specific colors (blue, yellow, red). Therefore I want to create a legend, but I really dont know how to do this. This legend should show 3 polygons in 3 different colors and some text right of it. Something like "[red polygon] > 30".

custom style sld:

<?xml version="1.0" encoding="ISO-8859-1"?>
<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>Temperature</Name>
    <UserStyle>
      <Title>My Temperature Style</Title>
      <FeatureTypeStyle>
        <Rule>
            <PolygonSymbolizer>
               <Fill>
                 <CssParameter name="fill">
                   <ogc:Function name="Interpolate">
                     <ogc:PropertyName>dTA</ogc:PropertyName>

                     <ogc:Literal>0</ogc:Literal>
                     <ogc:Literal>#0000ff</ogc:Literal>

                     <ogc:Literal>15</ogc:Literal>
                     <ogc:Literal>#ffff00</ogc:Literal>

                     <ogc:Literal>30</ogc:Literal>
                     <ogc:Literal>#ff0000</ogc:Literal>

                     <ogc:Literal>color</ogc:Literal>
                   </ogc:Function>
                 </CssParameter>
               </Fill>
            </PolygonSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
   </NamedLayer>
</StyledLayerDescriptor>

any idea?

  • i would appreciate any kind of help – Lukas Jun 26 '18 at 6:05
1

You need to call the getLegendGraphic endpoint of your WMS service. So if your temperature layer is called topp:temperature you would add a request like:

http://localhost:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=topp:temperature

The documentation gives you details on all the possible options you can add to control fonts and sizes etc.

  • doesn't work for me, i am getting the following error: <?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE ServiceExceptionReport SYSTEM "http://localhost:8080/geoserver/schemas/wms/1.1.1/WMS_exception_1_1_1.dtd"> <ServiceExceptionReport version="1.1.1" > <ServiceException> java.lang.NullPointerException </ServiceException></ServiceExceptionReport> – Lukas Jun 21 '18 at 13:14
  • did you get the layer name and workspace correct? – Ian Turton Jun 21 '18 at 13:22
  • yes, i tried it with some other layers and they are working fine. It's just that one layer with the custom Style – Lukas Jun 21 '18 at 13:25
  • then you need to ask a new question that contains the style – Ian Turton Jun 21 '18 at 13:26
  • edited my question. You can find the used style in my question now – Lukas Jun 22 '18 at 5:08
1

fixed! I was able to add a custom legend for my style. First i added the following Rule to my style SLD:

<Rule>
  <RasterSymbolizer>
    <Opacity>1.0</Opacity>
    <ColorMap>
      <ColorMapEntry color="#2F32EA" quantity="0" label="0&#176;C" />
      <ColorMapEntry color="#956C80" quantity="7.5" />
      <ColorMapEntry color="#FAA615" quantity="15" label="15&#176;C" />
      <ColorMapEntry color="#FA540C" quantity="22.5" />   
      <ColorMapEntry color="#FA0202" quantity="30" label="30&#176;C" />
    </ColorMap>
  </RasterSymbolizer>
</Rule>

Then i could see a preview of my new legend and geoserver created a png file in the legendsamples directory. Finally i copied this png in my styles directory and added my legend by inserting the filename in the Online Resource field.

enter image description here

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.