GeoServer – Refer to Other SLD for GetLegendGraphic

geoservergetlegendgraphicsldwms

I have a group layer in geoserver with all layers having one style each.

However, for the legend I want to refer to an "external" SLD (basically a simplified "dummy legend"). The SLD is in the same workspace as the group layer and I guess you can specify the SLD you want to get by GetLegendGraphic Parameters? Here specifically, I'm thinking of the SLD parameter.

The solution (I think) is something like this:

https://wms.myserver.com/geoserver/my_workspace/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=30&HEIGHT=30&LAYER=my_group_layer&SLD=**???**

In the SLD documentation it says thatt you can refer to an external SLD by a URL. How do i know what URL to use as a parameter?

Best Answer

If your style is already published by GeoServer then you can just use the style parameter in the GetLegend request:

http://localhost:8080/geoserver/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=topp%3Astates&style=pophatch

If you need to send specific SLD then the process is the same as sending it for a layer as discussed in this question and the manual