[Geoserver-devel] Something that SLD seems to be doing better than CSS?

Hi,
one of the thing that I’m having troubles emulating in CSS is the Rule else filter behavior.
Sometimes what one wants is “do this when no other rules matches this feature”,
and CSS seems to be making my life hard at doing that.

As an example, I have just added an env variable which allows the style to know whether
we are generating KML output as ground overlays or vector output (https://jira.codehaus.org/browse/GEOS-5983).
In SLD I would express it with something like:

kmlOutputMode vector

Now, I cannot find a way to get that exact representation from a CSS style, but the following two
are functionally equivalent:

  1. Making a perfect negation of the first expression to control the creation of the red square mark:

[env(‘kmlOutputMode’) = ‘vector’]
{
mark: url('http://maps.google.com/mapfiles/kml/pal4/icon25.png’);
mark-mime: ‘image/png’;
}

[env(‘kmlOutputMode’) <> ‘vector’]
{
mark: symbol(square);
mark-size: 8;
}

:mark [env(‘kmlOutputMode’) <> ‘vector’] {
fill: red;
}

  1. Try to use cascading somehow:

[env(‘kmlOutputMode’) = ‘vector’]
{
mark: url('http://maps.google.com/mapfiles/kml/pal4/icon25.png’);
mark-mime: ‘image/png’;
mark-size: none;
}

{
mark: symbol(square);
mark-size: 8;
}

:mark {
fill: red;
}

Funny enough, if I do the following instead I don’t end up getting the png icon
in the output style, but two rules with a :

{
mark: symbol(square);
mark-size: 8;
}

:mark {
fill: red;
}

[env(‘kmlOutputMode’) = ‘vector’]
{
mark: url('http://maps.google.com/mapfiles/kml/pal4/icon25.png’);
mark-mime: ‘image/png’;
mark-size: none;
}

:mark [env(‘kmlOutputMode’) = ‘vector’]
{
fill: none;
}

(the last rule is trying to make the engine stop trying to generate a mark,
the result is the same whether it’s there, or not)

Hmmm… anyways, can anybody think of a better way?
Of course the first solution works, but I was hoping for something simpler

Cheers
Andrea

==
Our support, Your Success! Visit http://opensdi.geo-solutions.it for more information.

Ing. Andrea Aime

@geowolf
Technical Lead

GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it


Your second example is almost right. It should be like this:

···

On Thu, Aug 22, 2013 at 5:26 AM, Andrea Aime <andrea.aime@anonymised.com> wrote:

Hi,
one of the thing that I’m having troubles emulating in CSS is the Rule else filter behavior.
Sometimes what one wants is “do this when no other rules matches this feature”,
and CSS seems to be making my life hard at doing that.

As an example, I have just added an env variable which allows the style to know whether
we are generating KML output as ground overlays or vector output (https://jira.codehaus.org/browse/GEOS-5983).
In SLD I would express it with something like:

kmlOutputMode vector

Now, I cannot find a way to get that exact representation from a CSS style, but the following two
are functionally equivalent:

  1. Making a perfect negation of the first expression to control the creation of the red square mark:

[env(‘kmlOutputMode’) = ‘vector’]
{
mark: url('http://maps.google.com/mapfiles/kml/pal4/icon25.png’);
mark-mime: ‘image/png’;
}

[env(‘kmlOutputMode’) <> ‘vector’]
{
mark: symbol(square);
mark-size: 8;
}

:mark [env(‘kmlOutputMode’) <> ‘vector’] {
fill: red;
}

  1. Try to use cascading somehow:

[env(‘kmlOutputMode’) = ‘vector’]
{
mark: url('http://maps.google.com/mapfiles/kml/pal4/icon25.png’);
mark-mime: ‘image/png’;
mark-size: none;
}

{
mark: symbol(square);
mark-size: 8;
}

:mark {
fill: red;
}

Funny enough, if I do the following instead I don’t end up getting the png icon
in the output style, but two rules with a :

{
mark: symbol(square);
mark-size: 8;
}

:mark {
fill: red;
}

[env(‘kmlOutputMode’) = ‘vector’]
{
mark: url('http://maps.google.com/mapfiles/kml/pal4/icon25.png’);
mark-mime: ‘image/png’;
mark-size: none;
}

:mark [env(‘kmlOutputMode’) = ‘vector’]
{
fill: none;
}

(the last rule is trying to make the engine stop trying to generate a mark,
the result is the same whether it’s there, or not)

Hmmm… anyways, can anybody think of a better way?
Of course the first solution works, but I was hoping for something simpler

Cheers
Andrea

==
Our support, Your Success! Visit http://opensdi.geo-solutions.it for more information.

Ing. Andrea Aime

@geowolf
Technical Lead

GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it



Introducing Performance Central, a new site from SourceForge and
AppDynamics. Performance Central is your source for news, insights,
analysis and resources for efficient Application Performance Management.
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk


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

On Thu, Aug 22, 2013 at 3:34 PM, David Winslow <dwinslow@anonymised.com> wrote:

Your second example is almost right. It should be like this:

*
{
  mark: symbol(square);
  mark-size: 8;
}

[env('kmlOutputMode') = 'vector']
{
   mark: url('http://maps.google.com/mapfiles/kml/pal4/icon25.png’);
   mark-mime: 'image/png';
   mark-size: none;
}

:mark {
  fill: red;
}

That is, swap the first and second rules.

What's going on here is that since '*' includes features where
[env('kmlOutputMode') = 'vector'] too, the properties from both rules are
combined, using the normal specificity scoring to determine precedence.
Usually this would mean that the * rule is less specific and any
properties in the more specific rule override, but the scoring function
assigns a specificity of (0, 0, 0) to that one too. We use position in the
file as a tiebreaker in this case, so swapping the rules means that the
'env' rule overrides the '*' rule rather than the other way around.

It might make sense to modify the specificity scoring so that filters like
this get a non-zero specificity. A filter normally gets a score according
to the number of feature attributes that it references, but maybe when no
properties are referenced it should be scored like a scale constraint. Or
we could do it based on the number of functions used, I guess we have
several options here.

Could we count the accesses to env as variables (one for each env variable
accessed)?
In the end, that's what they are, they are just coming from the enviroment
instead of the current feature

There are some notes on specificity handling in the CSS converter in the
source code:
https://github.com/dwins/geoscript.scala/blob/master/geocss/src/main/scala/org/geoscript/geocss/CssOps.scala#L179

Thank you, will have a look

Cheers
Andrea

--

Our support, Your Success! Visit http://opensdi.geo-solutions.it for more
information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it

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