Monday 4 February 2019

GeoServer SLD - size by scale and color by attribute



I would like to write an SLD that defines point size by zoom level using zoom denominators and color by a comparison operator. I am having trouble combining the two into rules because I cannot find evidence in the SLD cookbook that logical (And) operators are supported for anything other than combinations of spatial and comparison operators. Here is what I have for my first zoom level (denominator based off Bing maps scales, this part works fine), can anyone suggest a work-around or a missing step? [Note: the only thing that is changing in the rule filter is the color based off of whether the point belongs to Company A or Company B.] Thanks for any insight!



default_point

Default Point
A sample style that draws a point


Local company A
Local Company A




company
A

144447.93






circle

#000080


8





Local Company B
Local Company B


144447.93

company
B







circle

#696969



8






Answer



The usual way to set a point size based on the scale denominator is to use the and elements across multiple rules. So, to take your example you would need to do something like:




Local Company A - Large
Local Company A
100000


company
A






circle

#000080


12





Local Company A - Medium
Local Company A
100000
500000


company
A






circle

#000080



8




Local Company A - Small
Local Company A
500000



company
A





circle

#000080



4




So the above three rules will set the size of the point for company A based on the current scale denominator in relation to ranges. The three rules in this case are:


Rule 1: <= 1:100000 point size = 12


Rule 2: 1:100000 to 1:500000 point size = 8



Rule 3: >= 1:500000 point size = 4


So the point size gets progressively smaller the more the user zooms out. These three rules would then need to be repeated for Company B to give you the different coloured points based on company name.


GeoServer does also contain the ability to get properties from the request and then use these within the SLD. There may be potential to use this, as an environment variable that GeoServer provides for all WMS requests is wms_scale_denominator. It might be possible to set the point size dynamically using this, for example by doing something with the number you get.





circle

#000080




wms_scale_denominator





This is a poor example because the value returned will be huge and so the point would be huge, or it will kill GeoServer. Much more likely would be to do something with that number so as it changes the point size changes in a more appropriate way. You could use for example to divide the number by something (map resolution maybe) to get a sensible point size.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...