1

I have a style that divide features in PostGIS layer to four categories based on atributte Z_KAT. In the fourth category I want to specify that Z_KAT is equal to '04' OR null value.

Condition for text value '04' works well but condition for null value doesn't work (only selected features with value '04'). In SLD it works well so I can compare the result in "layer preview" but i need the style in CSS.

I also tried something like this: Problem with NotEqualTo filters in SLD and CSS but without success.

How can I get this to work?

Version of GeoServer and CSS extension is 2.16.2.

Here is my code:

/* @title Vodní nádrž I. kategorie TBD*/
[Z_KAT='01']{
  mark: symbol(square);
  mark-size: 7;
  mark-rotation: 45;
  :mark{
    fill: #ff0000;
  }
}

/* @title Vodní nádrž II. kategorie TBD*/
[Z_KAT='02']{
  mark: symbol(square);
  mark-size: 7;
  mark-rotation: 45;
  :mark{
    fill: #008080;
  }
}

/* @title Vodní nádrž III. kategorie TBD*/
[Z_KAT='03']{
  mark: symbol(square);
  mark-size: 7;
  mark-rotation: 45;
  :mark{
    fill: #00ffff;
  }
}

/* @title Vodní nádrž IV. kategorie TBD*/
[Z_KAT='04'],[Z_KAT is Null]{
  mark: symbol(square);
  mark-size: 7;
  mark-rotation: 45;
  :mark{
    fill: #0000ff;
  }
}
3
  • OR queries are generally inefficient. You might try using the coalesce function in a single term (equivalent to WHERE coalesce(Z_CAT,'04') = '04')
    – Vince
    Aug 9, 2022 at 11:47
  • Good to know, but my problem is with null values, I need to define style for features that have null value in atributte Z_KAT. I also tried it with single term 'Z_KAT is Null' without OR...
    – TomyPoty
    Aug 9, 2022 at 11:57
  • Welcome to Geographic Information Systems! You need to turn up the logging level to developer in the global settings page, and then make the request again. Then edit your question with the relevant part of the log file.
    – Ian Turton
    Aug 9, 2022 at 13:25

1 Answer 1

0

After many attemps I solved the problem!

I added translation mode to flat that translate CSS rules to SLD almost in 1:1. (The Flat translation mode)

Then I adjusted the conditions in my code to match my categories like this:

@mode "Flat";

/* @title Vodní nádrž I. kategorie TBD*/
[Z_KAT='01']{
  mark: symbol(square);
  mark-size: 7;
  mark-rotation: 45;
  :mark{
    fill: #ff0000;
  }
}

/* @title Vodní nádrž II. kategorie TBD*/
[Z_KAT='02']{
  mark: symbol(square);
  mark-size: 7;
  mark-rotation: 45;
  :mark{
    fill: #008080;
  }
}

/* @title Vodní nádrž III. kategorie TBD*/
[Z_KAT='03']{
  mark: symbol(square);
  mark-size: 7;
  mark-rotation: 45;
  :mark{
    fill: #00ffff;
  }
}

/* @title Vodní nádrž IV. kategorie TBD*/
[Z_KAT not in ('01','02','03')],[Z_KAT is Null]{
  mark: symbol(square);
  mark-size: 7;
  mark-rotation: 45;
  :mark{
    fill: #0000ff;
  }
}

Now the null values are correctly selected and the legend contains the correct categories.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.