[GIS] GetLegendGraphic request string is too long

geoservergetlegendgraphicopenlayers-2requestwms

I am setting the SLD Body of a WMS layer on the client side. I set the style in JSON and I have some functions that convert the JSON to SLD (OpenLayers functions). It works fine for displaying the layer with all its colors.

But when I use a legend (GetLegendGraphic from GeoServer), I have a limit in the size of the SLD Body. The limit of characters is about 20.000. When I perform the GetLegendGraphic request and the url is longer than (about) 20.000 characters, an error occurs and the legend is not displayed. BUT the layer is still correctly displayed (as you can see in the images below).

Below the 20.000 characters, the legend works fine.

I find it strange that the layer is correctly displayed and the legend isn't. Both are fetched via GeoServer requests.

Could you help me solve this?

I wanted a way to accept long strings in the GetLegendGraphic or a way to compress the string with the SLD body (so that it has fewer characters).

EXAMPLES:

SLD Body with 18006 characters (this shows a correct legend)

GOOD

SLD Body with 24245 characters (this does not show the legend, still draws the layer correctly)

BAD

Best Answer

You could post the sld to a php-file which writes a sld-file on the server(considering some security aspects). Then you could point to this file:

Example: 4 times the same layer, getlegendgraphic with 4 different sld's:

http://suite.opengeo.org/geoserver/wms?TRANSPARENT=true&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetLegendGraphic&SLD=https://raw.githubusercontent.com/boundlessgeo/suite-data/master/default/styles/states.sld&EXCEPTIONS=application/vnd.ogc.se_xml&LAYER=usa:states&FORMAT=image/png&width=150&height=50

http://suite.opengeo.org/geoserver/wms?TRANSPARENT=true&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetLegendGraphic&SLD=https://raw.githubusercontent.com/ROGUE-JCTD/COPECO-Layers/master/Layers/edificios/polygon.sld&EXCEPTIONS=application/vnd.ogc.se_xml&LAYER=usa:states&FORMAT=image/png&width=150&height=50

http://suite.opengeo.org/geoserver/wms?TRANSPARENT=true&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetLegendGraphic&SLD=https://raw.githubusercontent.com/opengeogroep/NLExtract/master/top10nl/style/sld/jw_van_aalst/Top10NL-Gebouw_vlak_(kas).sld&EXCEPTIONS=application/vnd.ogc.se_xml&LAYER=usa:states&FORMAT=image/png&width=150&height=50

http://suite.opengeo.org/geoserver/wms?TRANSPARENT=true&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetLegendGraphic&SLD=https://gist.githubusercontent.com/dwins/425748/raw/67e7c243b23a20f9bc78cb1b26b30834a6925b52/planet_polygon.sld.xml&EXCEPTIONS=application/vnd.ogc.se_xml&LAYER=usa:states&FORMAT=image/png&width=150&height=50

Or as user stuporglue mentioned you could use geoservers rest interface but there you would have to consider how to erase unused styles again: http://docs.geoserver.org/stable/en/user/rest/examples/curl.html