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"
      <Title>My Temperature Style</Title>
                 <CssParameter name="fill">
                   <ogc:Function name="Interpolate">





any idea?

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

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:


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

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

      <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" />

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.