[Geoserver-users] GetLegendGraphic - Multiple Rules are not properly rendered.

Dear All,

I have a 2-Rule SLD file, to be applied to a raster (see below).

The style is well applied in the GetMap request, but not in the GetLegendGraphic one.

In fact, only the first rule is rendered, but not the second one.

This is against what have been reported in the documentation:
https://docs.geoserver.org/stable/en/user/services/wms/get_legend_graphic/index.html

RULE - Optional - Rule of style to produce legend graphic for, if applicable.
In the case that a style has multiple rules but no specific rule is selected,
then the map server is obligated to produce a graphic that is representative
of all of the rules of the style.

If I request a GetLegendGraphic with:

…&rule=Data (the first rule, it works)
…&rule=Flags (the second rule, it works)

but I’m not able to retrieve the legend formed by the full rules list.


to workaround this issue I’ve tried to have 2 RasterSymbolizer in the same Rule.

It fails, with the error message:

“Unable to create a legend for this style, we need exactly 1 Symbolizer”

while in the documentation is reported: (https://docs.geoserver.org/latest/en/user/styling/sld/reference/rules.html)

“A rule combines a filter with any number of symbolizers.”

and

“ 0…N Specifies styling for raster data.”


Thanks in advance

Davide Battista


<?xml version="1.0" ?>

<sld:StyledLayerDescriptor version=“1.0.0” xmlns=“http://www.opengis.net/sld” xmlns:gml=“http://www.opengis.net/gml” xmlns:ogc=“http://www.opengis.net/ogc” xmlns:sld=“http://www.opengis.net/sld”>
sld:UserLayer
sld:LayerFeatureConstraints
sld:FeatureTypeConstraint/
</sld:LayerFeatureConstraints>
sld:UserStyle
sld:NameDrought Intensity (Annual) - Cropland</sld:Name>
sld:Title/
sld:FeatureTypeStyle
sld:Name/
sld:Rule
sld:NameData</sld:Name>
sld:RasterSymbolizer
sld:Geometry
ogc:PropertyNamegrid</ogc:PropertyName>
</sld:Geometry>
sld:Opacity1</sld:Opacity>
<sld:ColorMap type=“intervals”>
<sld:ColorMapEntry color=“#c00000” label=" <25 (Extreme)" opacity=“1.0” quantity=“0.25”/>
<sld:ColorMapEntry color=“#ca6664” label=" 25 - 35 (Severe)" opacity=“1.0” quantity=“0.35”/>
<sld:ColorMapEntry color=“#ffff30” label=" 35 - 38 (Moderate)" opacity=“1.0” quantity=“0.38”/>
<sld:ColorMapEntry color=“#e2efda” label=" 38 - 42 (Mild)" opacity=“1.0” quantity=“0.42”/>
<sld:ColorMapEntry color=“#aad08e” label=" >=42 (None)" opacity=“1.0” quantity=“251”/>
</sld:ColorMap>
</sld:RasterSymbolizer>
</sld:Rule>
sld:Rule
sld:NameFlags</sld:Name>
sld:RasterSymbolizer
sld:Geometry
ogc:PropertyNamegrid</ogc:PropertyName>
</sld:Geometry>
sld:Opacity1</sld:Opacity>
<sld:ColorMap type=“values”>

<sld:ColorMapEntry color=“#000000” label=" insufficient data" opacity=“1.0” quantity=“252”/>
<sld:ColorMapEntry color=“#666666” label=" no season" opacity=“1.0” quantity=“253”/>
<sld:ColorMapEntry color=“#cccccc” label=" no cropland" opacity=“1.0” quantity=“254”/>

</sld:ColorMap>
</sld:RasterSymbolizer>
</sld:Rule>
</sld:FeatureTypeStyle>
</sld:UserStyle>
</sld:UserLayer>
</sld:StyledLayerDescriptor>


The style is pretty weird, probably the first time I see one with raster symbolizers and two colormaps
against the same source raster (seen multiple with rendering transformations, but that’s another story)

The same map could be obtained fusing them into a single raster symbolizer, but it seems like you’re trying to
separate them for legend generation purposes. As you noticed, it won’t work, the raster legend generation code
only supports one raster symbolizer:
https://github.com/geoserver/geoserver/blob/aa1e49d0023e60e529182a6e45a1f2119d67dd05/src/wms/src/main/java/org/geoserver/wms/legendgraphic/RasterLayerLegendHelper.java#L44

If it’s something you actually need, I’d warmly suggest working on a PR to change the legend generation code,
it’s unlikely that someone else might sponsor such work. See:
https://github.com/geoserver/geoserver/blob/master/CONTRIBUTING.md

Best regards
Andrea

···

Regards, Andrea Aime

== GeoServer Professional Services from the experts! Visit http://goo.gl/it488V for more information. == Ing. Andrea Aime @geowolf Technical Lead GeoSolutions S.A.S. Via di Montramito 3/A 55054 Massarosa (LU) phone: +39 0584 962313 fax: +39 0584 1660272 mob: +39 339 8844549 http://www.geo-solutions.it http://twitter.com/geosolutions_it ------------------------------------------------------- Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia. This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail.

Please keep the list in CC at all times. This is part of the list guidelines, which I recommend reading if you haven’t
done so yet: http://geoserver.org/comm/userlist-guidelines.html
It’s also linked from the footer of all mails posted to this list.

So you should fix the documentation at least.

LOL no, if you care about getting the doc fixed, you must do it. Each page in the documentation has
an edit link that will create a PR for you. I warmly suggest looking at this presentation before
any further comment on the matter:

https://media.ccc.de/v/bucharest-322-the-secret-life-of-open-source-developers

Anyway, I dig into the code and I found something that ooks weird to me, but for sure I’m wrong:

In the LegendUtils file (https://github.com/geoserver/geoserver/blob/2.11.4/src/wms/src/main/java/org/geoserver/wms/legendgraphic/LegendUtils.java)

That’s an outdated version of the source code, using deprecated API (getRules) that was turned into “rules()” a few years later. Let’s look at the current source code:
https://github.com/geoserver/geoserver/blob/master/src/wms/src/main/java/org/geoserver/wms/legendgraphic/LegendUtils.java#L562

Because looking at the code, there is no reason for not rendering both the rules.

I already pointed you at the class that builds the full legend in case there is a raster symbolizer in the style.
The legend utils code you were looking at is used only for vector data legends:
https://github.com/geoserver/geoserver/blob/master/src/wms/src/main/java/org/geoserver/wms/legendgraphic/BufferedImageLegendGraphicBuilder.java#L189

while this branch is chosen for raster legends:
https://github.com/geoserver/geoserver/blob/master/src/wms/src/main/java/org/geoserver/wms/legendgraphic/BufferedImageLegendGraphicBuilder.java#L175

Regards
Andrea

···

== GeoServer Professional Services from the experts! Visit http://goo.gl/it488V for more information. == Ing. Andrea Aime @geowolf Technical Lead GeoSolutions S.A.S. Via di Montramito 3/A 55054 Massarosa (LU) phone: +39 0584 962313 fax: +39 0584 1660272 mob: +39 339 8844549 http://www.geo-solutions.it http://twitter.com/geosolutions_it ------------------------------------------------------- Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia. This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail.

Thanks Andrea for the helpful advice!

Regards

Davide

On Fri, Dec 11, 2020 at 3:07 PM Andrea Aime <andrea.aime@anonymised.com> wrote:

Please keep the list in CC at all times. This is part of the list guidelines, which I recommend reading if you haven’t
done so yet: http://geoserver.org/comm/userlist-guidelines.html
It’s also linked from the footer of all mails posted to this list.

On Fri, Dec 11, 2020 at 2:49 PM Davide Battista <davide.battista@anonymised.com4…> wrote:

So you should fix the documentation at least.

LOL no, if you care about getting the doc fixed, you must do it. Each page in the documentation has
an edit link that will create a PR for you. I warmly suggest looking at this presentation before
any further comment on the matter:

https://media.ccc.de/v/bucharest-322-the-secret-life-of-open-source-developers

Anyway, I dig into the code and I found something that ooks weird to me, but for sure I’m wrong:

In the LegendUtils file (https://github.com/geoserver/geoserver/blob/2.11.4/src/wms/src/main/java/org/geoserver/wms/legendgraphic/LegendUtils.java)

That’s an outdated version of the source code, using deprecated API (getRules) that was turned into “rules()” a few years later. Let’s look at the current source code:
https://github.com/geoserver/geoserver/blob/master/src/wms/src/main/java/org/geoserver/wms/legendgraphic/LegendUtils.java#L562

Because looking at the code, there is no reason for not rendering both the rules.

I already pointed you at the class that builds the full legend in case there is a raster symbolizer in the style.
The legend utils code you were looking at is used only for vector data legends:
https://github.com/geoserver/geoserver/blob/master/src/wms/src/main/java/org/geoserver/wms/legendgraphic/BufferedImageLegendGraphicBuilder.java#L189

while this branch is chosen for raster legends:
https://github.com/geoserver/geoserver/blob/master/src/wms/src/main/java/org/geoserver/wms/legendgraphic/BufferedImageLegendGraphicBuilder.java#L175

Regards
Andrea

== GeoServer Professional Services from the experts! Visit http://goo.gl/it488V for more information. == Ing. Andrea Aime @geowolf Technical Lead GeoSolutions S.A.S. Via di Montramito 3/A 55054 Massarosa (LU) phone: +39 0584 962313 fax: +39 0584 1660272 mob: +39 339 8844549 http://www.geo-solutions.it http://twitter.com/geosolutions_it ------------------------------------------------------- Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia. This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail.

There are just times when best approach to legend is to make simple versions covering what you need, screenshot, then take them into a good image editor and make them pretty. Add the composite pretty output to the style with the Add Legend button.

···

From: Davide Battista <davide.battista@…84…>
Sent: Saturday, 12 December 2020 04:15
To: andrea.aime@…1107…
Cc: GeoServer Mailing List List geoserver-users@lists.sourceforge.net
Subject: Re: [Geoserver-users] GetLegendGraphic - Multiple Rules are not properly rendered.








Note: External sender:


Thanks Andrea for the helpful advice!

Regards

Davide

On Fri, Dec 11, 2020 at 3:07 PM Andrea Aime <andrea.aime@…1107…> wrote:

Please keep the list in CC at all times. This is part of the list guidelines, which I recommend reading if you haven’t

done so yet: http://geoserver.org/comm/userlist-guidelines.html

It’s also linked from the footer of all mails posted to this list.

On Fri, Dec 11, 2020 at 2:49 PM Davide Battista <davide.battista@…84…> wrote:

So you should fix the documentation at least.

LOL no, if you care about getting the doc fixed, you must do it. Each page in the documentation has

an edit link that will create a PR for you. I warmly suggest looking at this presentation before

any further comment on the matter:

https://media.ccc.de/v/bucharest-322-the-secret-life-of-open-source-developers

Anyway, I dig into the code and I found something that ooks weird to me, but for sure I’m wrong:

In the LegendUtils file (https://github.com/geoserver/geoserver/blob/2.11.4/src/wms/src/main/java/org/geoserver/wms/legendgraphic/LegendUtils.java)

That’s an outdated version of the source code, using deprecated API (getRules) that was turned into “rules()” a few years later. Let’s look at the current source code:

https://github.com/geoserver/geoserver/blob/master/src/wms/src/main/java/org/geoserver/wms/legendgraphic/LegendUtils.java#L562

Because looking at the code, there is no reason for not rendering both the rules.

I already pointed you at the class that builds the full legend in case there is a raster symbolizer in the style.

The legend utils code you were looking at is used only for vector data legends:

https://github.com/geoserver/geoserver/blob/master/src/wms/src/main/java/org/geoserver/wms/legendgraphic/BufferedImageLegendGraphicBuilder.java#L189

while this branch is chosen for raster legends:

https://github.com/geoserver/geoserver/blob/master/src/wms/src/main/java/org/geoserver/wms/legendgraphic/BufferedImageLegendGraphicBuilder.java#L175

Regards

Andrea

== GeoServer Professional Services from the experts! Visit http://goo.gl/it488V for more information. == Ing. Andrea Aime @geowolf Technical Lead GeoSolutions S.A.S. Via di Montramito 3/A 55054 Massarosa (LU) phone: +39 0584 962313 fax: +39 0584 1660272 mob: +39 339 8844549 http://www.geo-solutions.it http://twitter.com/geosolutions_it ------------------------------------------------------- Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia. This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail.