Dynamic SLD on Geoserver

747 Views Asked by At

Can somebody help me with this CSS sld on geoserver?

If someone have better option rather than my approach, please suggest.

[activity_group_id = 20] [application_status = 'PreSanction-Pending']{
  mark:symbol('ttf://ESRI Business#39');
  :symbol {
    fill:#FF0000;
    }
}

[activity_group_id = 20] [application_status = 'Payment-Done']{
  mark:symbol('ttf://ESRI Business#39');
  :symbol {
    fill:#00FF00;
    }
}

[activity_group_id = 20] [application_status = 'Work-Completed']{
  mark:symbol('ttf://ESRI Business#39');
  :symbol {
    fill:#0000FF;
    }
}

[activity_group_id = 20] [application_status = 'PreSanction-Received']{
  mark:symbol('ttf://ESRI Business#39');
  :symbol {
    fill:#00FFFF;
    }
}

this is working fine but I want to simplify this using if-then-else I'm stuck on this

as there are more than 30 unique 'activity_group_id' there

I have point data where each row have two variable 'activity_group_id' and 'activity_status', I'm using ttf symbols to display as layer but the condition is, each point needs to be assigned color (Fill) according to its status there are total 4 unique value of it, as I'm new to sld referred docs but not finding any solution.

Edit :- adding some test data for point location layer

activity_group_id application_status desk4_longitude desk4_latitude
20  "Work-Completed"    77.8912643252645    20.7848792063826
20  "PreSanction-Pending"   77.8912791454753    20.7796634062134
20  "Payment-Done"  77.874307404545 20.7786504284761
20  "PreSanction-Pending"   77.8748653559629    20.7777572907007
20  "Payment-Done"  77.8935239518168    20.7742195299066
20  "PreSanction-Pending"   77.8887775696933    20.7848194877974
20  "PreSanction-Received"  77.8829004567405    20.7622202218188
2

There are 2 best solutions below

1
Andrea Aime On BEST ANSWER

Use the recode function to simplify the style. I cannot test it, but should be something like this:

[activity_group_id = 20] {
  mark:symbol('ttf://ESRI Business#39');
  :symbol {
     fill: recode(application_status, 
           'Payment-Done', #00FF00,
           'Work-Completed', #0000FF,
           'PreSanction-Received', #00FFFF);
  }
}

If the colors are the same based on application_status, but shape changes based on the group id, then use cascading and set up separate rules:

[activity_group_id = 20] {
  mark:symbol('ttf://ESRI Business#39');
}

[activity_group_id = anotherId] {
  mark:symbol('ttf://anotherSymbol');
}

* {
  :symbol {
     fill: recode(application_status, 
           'Payment-Done', #00FF00,
           'Work-Completed', #0000FF,
           'PreSanction-Received', #00FFFF);
  }
}
0
SpiderMan On

@Andrea Aime

as from your reference I checked docs, and made some changes in syntax of your answer sharing my answer for other to help

check geoserver css doc

/* @title Apiculture */
[activity_group_id = 20] {
  mark:symbol('ttf://ESRI Business#39');
  mark-size:15;
  :symbol {
     fill: [recode(application_status,
            'PreSanction-Pending','#FF0000',
           'Payment-Done', '#00FF00',
           'Work-Completed', '#0000FF',
           'PreSanction-Received', '#00FFFF')];
  }
}

/* @title Sprinkler Irrigation */
[activity_group_id = 19] {
  mark:symbol('ttf://ESRI Business#40');
  mark-size:15;
  :symbol {
     fill: [recode(application_status,
            'PreSanction-Pending','#FF0000',
           'Payment-Done', '#00FF00',
           'Work-Completed', '#0000FF',
           'PreSanction-Received', '#00FFFF')];
  }
}