[Geoserver-users] SLD RasterSymbolizer: ColorMapEntry variable substitution doesn't work when there are multiple rules in the SLD

Hi,

Color variable substitution works only when there is ONE SINGLE RULE in the SLD; when the SLD contains 2 or more rules, the variable substitution is broken and default color values are always used.
It is reproducible on any raster layer in GeoServer 2.8.3/2.9.0.

Did someone found a workaround to this issue?

Here below a minimalist SLD (for DEM geotiff layer) with 2 similar rules with reversed default colors. The filter allows the client to explicitly call the 1st rule by using "ENV=rule:1".
A WMS GetMap query with a different color value for a color (e.g. "ENV=rule:1;c1:%230000FF”, i.e. Blue instead default Read) returns as follows:
- NOK: the default (Red) color when the SLD contain 2 rules
- OK: the ENV value (Blue) color send in the query if the SLD only contains the 1st rule (i.e. the 2nd is manually removed from the SLD)

<Rule><Name>Red_Water</Name>
     <ogc:Filter><ogc:PropertyIsEqualTo><ogc:Literal>1</ogc:Literal><ogc:Function name="env"><ogc:Literal>rule</ogc:Literal></ogc:Function></ogc:PropertyIsEqualTo></ogc:Filter>
     <RasterSymbolizer><Opacity>1.0</Opacity><ChannelSelection><GrayChannel><SourceChannelName>1</SourceChannelName></GrayChannel></ChannelSelection>
          <ColorMap type="intervals"><ColorMapEntry color= "${env('c1','#FF0000')}" quantity= "10"/><ColorMapEntry color= "${env('c2','#000000')}" quantity= "9000"/></ColorMap>
     </RasterSymbolizer>
</Rule>

<Rule><Name>Black_Water</Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:Literal>2</ogc:Literal><ogc:Function name="env"><ogc:Literal>rule</ogc:Literal></ogc:Function></ogc:PropertyIsEqualTo></ogc:Filter>
     <RasterSymbolizer><Opacity>1.0</Opacity><ChannelSelection><GrayChannel><SourceChannelName>1</SourceChannelName></GrayChannel></ChannelSelection>
          <ColorMap type="intervals"><ColorMapEntry color= "${env('c1','#000000')}" quantity= "10"/> <ColorMapEntry color= "${env('c2','#FF0000')}" quantity= "9000"/></ColorMap>
     </RasterSymbolizer>
</Rule>

Many Thanks,
Victor
________________________________
This message is subject to and does not create or vary any contractual relationship between Campbell Scientific Limited, its subsidiaries or affiliates ("CSL") and you. Internet communications are not secure and therefore CSL does not accept legal responsibility for the contents of this message. The message is intended for the addressee only and its contents and any attached files are strictly confidential. If you have received it in error, please telephone +44 (0)1509 601141 or email postmaster@...7702... Thank you.
Campbell Scientific Ltd.
Company Registration Number: 1933935 (England and Wales) Registered Address: Campbell Park, 80 Hathern Road, Shepshed, Loughborough, Leicestershire LE12 9GX, UK
Tel: +44 (0) 1509 601141
Fax: +44 (0) 1509 601091
Web: www.campbellsci.co.uk

________________________________

Hi Victor,
no, we’re aware it does not work when there are two layers in the request… it’s odd to have two raster symbolizes in one style though…

Cheers
Andrea

···

On Thu, Jun 16, 2016 at 3:11 PM, Victor.Sinceac <Victor.Sinceac@anonymised.com188…> wrote:

Hi,

Color variable substitution works only when there is ONE SINGLE RULE in the SLD; when the SLD contains 2 or more rules, the variable substitution is broken and default color values are always used.
It is reproducible on any raster layer in GeoServer 2.8.3/2.9.0.

Did someone found a workaround to this issue?

Here below a minimalist SLD (for DEM geotiff layer) with 2 similar rules with reversed default colors. The filter allows the client to explicitly call the 1st rule by using “ENV=rule:1”.
A WMS GetMap query with a different color value for a color (e.g. "ENV=rule:1;c1:%230000FF”, i.e. Blue instead default Read) returns as follows:

  • NOK: the default (Red) color when the SLD contain 2 rules
  • OK: the ENV value (Blue) color send in the query if the SLD only contains the 1st rule (i.e. the 2nd is manually removed from the SLD)

Red_Water
ogc:Filterogc:PropertyIsEqualToogc:Literal1</ogc:Literal><ogc:Function name=“env”>ogc:Literalrule</ogc:Literal></ogc:Function></ogc:PropertyIsEqualTo></ogc:Filter>
1.01


Black_Waterogc:Filterogc:PropertyIsEqualToogc:Literal2</ogc:Literal><ogc:Function name=“env”>ogc:Literalrule</ogc:Literal></ogc:Function></ogc:PropertyIsEqualTo></ogc:Filter>
1.01


Many Thanks,
Victor


This message is subject to and does not create or vary any contractual relationship between Campbell Scientific Limited, its subsidiaries or affiliates (“CSL”) and you. Internet communications are not secure and therefore CSL does not accept legal responsibility for the contents of this message. The message is intended for the addressee only and its contents and any attached files are strictly confidential. If you have received it in error, please telephone +44 (0)1509 601141 or email postmaster@anonymised.com. Thank you.
Campbell Scientific Ltd.
Company Registration Number: 1933935 (England and Wales) Registered Address: Campbell Park, 80 Hathern Road, Shepshed, Loughborough, Leicestershire LE12 9GX, UK
Tel: +44 (0) 1509 601141
Fax: +44 (0) 1509 601091
Web: www.campbellsci.co.uk



What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports. http://pubads.g.doubleclick.net/gampad/clk?id=1444514421&iu=/41014381


Geoserver-users mailing list
Geoserver-users@anonymised.comsts.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

==
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

AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy’s New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.


Hi Andrea,

Yes, keeping 1 rule by SLD could be a possible workaround, but it would be difficult to manage at some level…

Actually we often use different rules (filtered by ENV values) in a same SLD, for different reasons, e.g. to handle:

  • reversed values on legends (values growing from bottom to top) : 1 rule for GetMap queries and a 2nd one with reversed colormap entries for GetLegendGraphic queries

  • SQL Views layers which can return different columns from db tables (e.g. temperatures or pressures), which require different colormaps

  • different colormaps (e.g. ramp and values), selectable by ENV in the GetMap query

  • values from different bands in a GeoTIFF

  • different colormap resolution at different scales

  • etc…

I think many people uses multiple RasterSymbolyzer rules in one SLD: there are many discussions on the forums about GetLegend results for such an SLD.

Best regards,

Victor

···

From: andrea.aime@…84… [mailto:andrea.aime@…84…] On Behalf Of Andrea Aime
Sent: Thursday, June 16, 2016 1:28 PM
To: Victor.Sinceac <Victor.Sinceac@…5188…>
Cc: geoserver-users@lists.sourceforge.net; Sylvain.Ladoire <Sylvain.Ladoire@…5188…>
Subject: Re: [Geoserver-users] SLD RasterSymbolizer: ColorMapEntry variable substitution doesn’t work when there are multiple rules in the SLD

Hi Victor,

no, we’re aware it does not work when there are two layers in the request… it’s odd to have two raster symbolizes in one style though…

Cheers

Andrea

On Thu, Jun 16, 2016 at 3:11 PM, Victor.Sinceac <Victor.Sinceac@…5188…> wrote:

Hi,

Color variable substitution works only when there is ONE SINGLE RULE in the SLD; when the SLD contains 2 or more rules, the variable substitution is broken and default color values are always used.
It is reproducible on any raster layer in GeoServer 2.8.3/2.9.0.

Did someone found a workaround to this issue?

Here below a minimalist SLD (for DEM geotiff layer) with 2 similar rules with reversed default colors. The filter allows the client to explicitly call the 1st rule by using “ENV=rule:1”.
A WMS GetMap query with a different color value for a color (e.g. "ENV=rule:1;c1:%230000FF”, i.e. Blue instead default Read) returns as follows:

  • NOK: the default (Red) color when the SLD contain 2 rules
  • OK: the ENV value (Blue) color send in the query if the SLD only contains the 1st rule (i.e. the 2nd is manually removed from the SLD)

Red_Water
ogc:Filterogc:PropertyIsEqualToogc:Literal1</ogc:Literal><ogc:Function name=“env”>ogc:Literalrule</ogc:Literal></ogc:Function></ogc:PropertyIsEqualTo></ogc:Filter>
1.01


Black_Waterogc:Filterogc:PropertyIsEqualToogc:Literal2</ogc:Literal><ogc:Function name=“env”>ogc:Literalrule</ogc:Literal></ogc:Function></ogc:PropertyIsEqualTo></ogc:Filter>
1.01


Many Thanks,
Victor


This message is subject to and does not create or vary any contractual relationship between Campbell Scientific Limited, its subsidiaries or affiliates (“CSL”) and you. Internet communications are not secure and therefore CSL does not accept legal responsibility for the contents of this message. The message is intended for the addressee only and its contents and any attached files are strictly confidential. If you have received it in error, please telephone +44 (0)1509 601141 or email postmaster@…7706…. Thank you.
Campbell Scientific Ltd.
Company Registration Number: 1933935 (England and Wales) Registered Address: Campbell Park, 80 Hathern Road, Shepshed, Loughborough, Leicestershire LE12 9GX, UK
Tel: +44 (0) 1509 601141
Fax: +44 (0) 1509 601091
Web: www.campbellsci.co.uk



What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports. http://pubads.g.doubleclick.net/gampad/clk?id=1444514421&iu=/41014381


Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

==

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

AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy’s New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.


On Thu, Jun 16, 2016 at 4:16 PM, Victor.Sinceac <Victor.Sinceac@anonymised.com>
wrote:

I think many people uses multiple RasterSymbolyzer rules in one SLD: there
are many discussions on the forums about GetLegend results for such an SLD.

Thinking about it... this scenario basically disables the fast raster
rendering path just like having two layers,
and you end up working with the generic one, which is the one where
variables do not work.
So the fix Mauro is making for the two layers case will also work for this
case, but mind, but using
this kind of styles you're setting yourself for limited performance and
scalability.

It would be possible to recognize that the other rules are not going to
trigger and keep on using
the fast raster rendering code, but of course that would require some extra
work.
In case you are interested in contributing code improvements I'òò show you
were that would have to be done:
https://github.com/geoserver/geoserver/blob/master/src/wms/src/main/java/org/geoserver/wms/map/RenderedImageMapOutputFormat.java#L880

Cheers
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

*AVVERTENZE AI SENSI DEL D.Lgs. 196/2003*

Le informazioni contenute in questo messaggio di posta elettronica e/o
nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il
loro utilizzo è consentito esclusivamente al destinatario del messaggio,
per le finalità indicate nel messaggio stesso. Qualora riceviate questo
messaggio senza esserne il destinatario, Vi preghiamo cortesemente di
darcene notizia via e-mail e di procedere alla distruzione del messaggio
stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso,
divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od
utilizzarlo per finalità diverse, costituisce comportamento contrario ai
principi dettati dal D.Lgs. 196/2003.

The information in this message and/or attachments, is intended solely for
the attention and use of the named addressee(s) and may be confidential or
proprietary in nature or covered by the provisions of privacy act
(Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection
Code).Any use not in accord with its purpose, any disclosure, reproduction,
copying, distribution, or either dissemination, either whole or partial, is
strictly forbidden except previous formal approval of the named
addressee(s). If you are not the intended recipient, please contact
immediately the sender by telephone, fax or e-mail and delete the
information in this message that has been received in error. The sender
does not give any warranty or accept liability as the content, accuracy or
completeness of sent messages and accepts no responsibility for changes
made after they were sent or for other risks which arise as a result of
e-mail transmission, viruses, etc.

-------------------------------------------------------

Hi,
I had a look at the issue, and it is related to EnvFunction not getting correctly filled with environment variables when rendering involveves more threads.
I tried a quick fix transforming the related ThreadLocal in EnvFunction in a InheritableThreadLocal, but that broke some geotools unit tests, so I don’t think that’s an option.

Regards,
Mauro

···

2016-06-16 16:31 GMT+02:00 Andrea Aime <andrea.aime@anonymised.com>:


What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports. http://pubads.g.doubleclick.net/gampad/clk?id=1444514421&iu=/41014381


Geoserver-users mailing list
Geoserver-users@anonymised.comsts.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

On Thu, Jun 16, 2016 at 4:16 PM, Victor.Sinceac <Victor.Sinceac@anonymised.com> wrote:

I think many people uses multiple RasterSymbolyzer rules in one SLD: there are many discussions on the forums about GetLegend results for such an SLD.

Thinking about it… this scenario basically disables the fast raster rendering path just like having two layers,
and you end up working with the generic one, which is the one where variables do not work.
So the fix Mauro is making for the two layers case will also work for this case, but mind, but using
this kind of styles you’re setting yourself for limited performance and scalability.

It would be possible to recognize that the other rules are not going to trigger and keep on using
the fast raster rendering code, but of course that would require some extra work.
In case you are interested in contributing code improvements I’òò show you were that would have to be done:
https://github.com/geoserver/geoserver/blob/master/src/wms/src/main/java/org/geoserver/wms/map/RenderedImageMapOutputFormat.java#L880

Cheers

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

AVVERTENZE AI SENSI DEL D.Lgs. 196/2003

Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo è consentito esclusivamente al destinatario del messaggio, per le finalità indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003.

The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy’s New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc.


On Thu, Jun 16, 2016 at 6:29 PM, Mauro Bartolomeoli <
maurobartolomeoli@anonymised.com> wrote:

Hi,
I had a look at the issue, and it is related to EnvFunction not getting
correctly filled with environment variables when rendering involveves more
threads.
I tried a quick fix transforming the related ThreadLocal in EnvFunction in
a InheritableThreadLocal, but that broke some geotools unit tests, so I
don't think that's an option.

Another option is to work at the renderer level, and transform all
expressions in the colormap into literals
by using a custom subclass of the DuplicatinStyleVisitor. This needs to be
done before the colormap is passed
to the rendering thread, around this location:

https://github.com/geotools/geotools/blob/master/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java#L2509

Cheers
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

*AVVERTENZE AI SENSI DEL D.Lgs. 196/2003*

Le informazioni contenute in questo messaggio di posta elettronica e/o
nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il
loro utilizzo è consentito esclusivamente al destinatario del messaggio,
per le finalità indicate nel messaggio stesso. Qualora riceviate questo
messaggio senza esserne il destinatario, Vi preghiamo cortesemente di
darcene notizia via e-mail e di procedere alla distruzione del messaggio
stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso,
divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od
utilizzarlo per finalità diverse, costituisce comportamento contrario ai
principi dettati dal D.Lgs. 196/2003.

The information in this message and/or attachments, is intended solely for
the attention and use of the named addressee(s) and may be confidential or
proprietary in nature or covered by the provisions of privacy act
(Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection
Code).Any use not in accord with its purpose, any disclosure, reproduction,
copying, distribution, or either dissemination, either whole or partial, is
strictly forbidden except previous formal approval of the named
addressee(s). If you are not the intended recipient, please contact
immediately the sender by telephone, fax or e-mail and delete the
information in this message that has been received in error. The sender
does not give any warranty or accept liability as the content, accuracy or
completeness of sent messages and accepts no responsibility for changes
made after they were sent or for other risks which arise as a result of
e-mail transmission, viruses, etc.

-------------------------------------------------------