Various software can style maps and generate a proper SLD document for OGC compliant WMS like GeoServer to use. However, in most occasions, the styling allowed by the graphical tools is pretty limited and not good enough to achieve good looking, readable and efficient cartographic output. For those that like to write their own styles CSS also represents a nice alternatives thanks to its compactness and expressiveness.
Several topics will be covered, providing examples in both SLD and CSS for each, including: mastering multi-scale styling, using GeoServer extensions to build common hatch patterns, line styling beyond the basics, such as cased lines, controlling symbols along a line and the way they repeat, leveraging TTF symbol fonts and SVGs to generate good looking point thematic maps, using the full power of GeoServer label lay-outing tools to build pleasant, informative maps on both point, polygon and line layers, including adding road plates around labels, leverage the labeling subsystem conflict resolution engine to avoid overlaps in stand alone point symbology, blending charts into a map, dynamically transform data during rendering to get more explicative maps without the need to pre-process a large amount of views.
The presentation aims to provide the attendees with enough information to master SLD/CSS documents and most of GeoServer extensions to generate appealing, informative, readable maps that can be quickly rendered on screen.
2. GeoSolutions
Founded in Italy in late 2006
Expertise
• Image Processing, GeoSpatial Data Fusion
• Java, Java Enterprise, C++, Python
• JPEG2000, JPIP, Advanced 2D visualization
Supporting/Developing FOSS4G projects
GeoServer, MapStore
GeoNetwork, GeoNode, Ckan
Clients
Public Agencies
Private Companies
http://www.geo-solutions.it
FOSS4G 2017, Boston
August 14th-19th 2017
3. SLD vs CSS
Styled Layer Descriptor
OGC standard
XML based, verbose, hard to hand edit
Only showing relevant bits of the SLD
GeoCSS
CSS with extensions for map rendering
Simple, Compact, designed for human beings
Not a standard (several incompatible variants for
mapping, GeoServer one has nothing to do with
CartoDB/MapBox one)
FOSS4G 2017, Boston
August 14th-19th 2017
4. CSS features
Familiar for web developers
Compact syntax
Symbolization triggered by “key” properties
(stroke, fill, mark, label, channel-selection)
CQL based filtering
Cascading keeps complex styling compact (you
just express the overrides to the base)
Interactive editor for productive style
development
FOSS4G 2017, Boston
August 14th-19th 2017
5. GeoCSS in a nutshell
• Filter by attribute/env variable in CQL
• Filter by scale
• Set properties to control symbolization
• Key properties activate certain symbolization:
– mark/fill/stroke/label/raster-channels
FOSS4G 2017, Boston
August 14th-19th 2017
[admin_level < 2][@sd < 1M][@sd > 100k] {
label: name;
font-family: ‘Noto Sans’;
…
/* this is nested rule */
[special = true][@sd < 500k] {
font-weight: bold;
…
}
}
6. SLD equivalents
FOSS4G 2017, Boston
August 14th-19th 2017
<sld:Rule>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>admin_level</ogc:PropertyName>
<ogc:Literal>2</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<sld:MinScaleDenominator>100000</sld:MinScaleDenominator>
<sld:MaxScaleDenominator>1000000</sld:MaxScaleDenominator>
<sld:TextSymbolizer>
<sld:Label>
<ogc:PropertyName>name</ogc:PropertyName>
</sld:Label>
<sld:Font>
<sld:CssParameter name="font-family">
Noto Sans
</sld:CssParameter>
<sld:CssParameter name="font-size">10
...
</sld:TextSymbolizer>
<!–- Override would require a separate rule specifying everything again -->
</sld:Rule>
Filter
Scale
dependency
Symbolizers
and their
properties
8. Types of Scale dependency
Decide whether to symbolize based on the scale or not
E.g., at lower scales/lower zoom levels do not show buildings
Symbolize in a different way depending on the scale
E.g., different thickness based on the current zoom
FOSS4G 2017, Boston
August 14th-19th 2017
9. Expressing scale dependency filters
SLD:
<MinScaleDenominator>
<MaxScaleDenominator>
CSS
Legacy: [@scale > 10000000]
GeoServer 2.12+: [@sd > 1M]
More compact variable, more correct (it’s a scale
denominator, not a scale!)
Compact expression of large numbers makes them readable
at a glance, e.g., 100k, 1M
FOSS4G 2017, Boston
August 14th-19th 2017
10. Unit of Measure
FOSS4G 2017, Boston
August 14th-19th 2017
Useful if you have real world measures of line
thicknesses and the like
<LineSymbolizer uom="http://www.opengeospatial.org/se/units/metre">
<Stroke>
<CssParameter name="stroke">#0000FF</CssParameter>
<CssParameter name="stroke-width">5</CssParameter>
</Stroke>
</LineSymbolizer>
* {
stroke: blue;
stroke-width: 5m;
}
11. Transformation functions
FOSS4G 2017, Boston
August 14th-19th 2017
OSM like, setting a different value depending on
the current scale/zoom level
Not a linear scale mind
[class = 'highway’
and type in ('motorway’,
'motorway_link’)]
[@sd < 25M] {
stroke: #e66e89;
stroke-width: categorize(@sd,
2, 400k,
1.9, 800k,
1.4, 1.5M,
1, 3M,
0.8, 6M,
0.5);
…
Less than 400k 2px
[400k, 800k] 1.9px
[800k, 1.5M] 1.4px
[1.5M, 3M] 1
[3M, 6M] 0.8
Above 6M -> 0.5
17. Many other options!
Built-in symbol names (well known marks): circle,
square, triangle, …
From TTF fonts using the name
ttf://<fontname>#charcode
Windbarbs, e.g.:
windbarbs://default(15)[kts]
WKT specification, e.g.
wkt://MULTILINESTRING((-0.25 -0.25, -0.125 -0.25), (0.125 -
0.25, 0.25 -0.25), (-0.25 0.25, -0.125 0.25), (0.125 0.25, 0.25
0.25))
See more here:
http://docs.geoserver.org/latest/en/user/styling/sld/exte
nsions/pointsymbols.html
Other mark options
FOSS4G 2017, Boston
August 14th-19th 2017
21. Filling with repeating images (SLD)
FOSS4G 2017, Boston
August 14th-19th 2017
<sld:Rule>
<ogc:Filter>
<ogc:And>
<ogc:Or>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>type</ogc:PropertyName>
<ogc:Literal>cemetery</ogc:Literal>
</ogc:PropertyIsEqualTo>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>type</ogc:PropertyName>
<ogc:Literal>grave_yard</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Or>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>religion</ogc:PropertyName>
<ogc:Literal>jewish</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:And>
</ogc:Filter>
<sld:MaxScaleDenominator>50000.0</sld:MaxScaleDenominator>
One sample rule (the Jewish religion one).
Three more needed to get the same
display as with CSS
27. Alternating dashes with marks
FOSS4G 2017, Boston
August 14th-19th 2017
* {
stroke: darkRed, symbol('circle');
stroke-dasharray: 10 14, 6 18;
stroke-dashoffset: 14, 0;
:stroke {
fill: darkRed;
size: 6;
}
}
Two coordinated dashed lines
One made with lines
One made with circles
The offset shifts them to have
one appear in the empty
spaces of the other
40. Masking via alpha compositing
FOSS4G 2016, Bonn
24nd – 24th August 2016
destination-in
41. Color blendin
FOSS4G 2017, Boston
August 14th-19th 2017
http://docs.geoserver.org/stable/user/styling/sld-extensions/composite-blend/index.html
More info at:
44. Autocomplete for CSS editor
Because there are too many properties to
remember!
FOSS4G 2017, Boston
August 14th-19th 2017
45. No more -gt- prefix in CSS
Vendor options used to be prefixed with “-gt-”
But CSS is its own language, no need to mark
something as “vendor” or refer to GeoTools
Don’t worry, old syntax still supported
FOSS4G 2017, Boston
August 14th-19th 2017
* {
...
-gt-mark-label-obstacle: true;
-gt-label-priority: 200000;
-gt-label-auto-wrap: 100;
}
* {
...
mark-label-obstacle: true;
label-priority: 200000;
label-auto-wrap: 100;
}
46. GeoCSS env variable expansion
Use @var or @var(defaultValue) in place of calling the
env function
@var -> env(‘var’)
@var(defaultValue) env(‘var’, defaultValue)
Exception for @sd
@sd -> env(‘wms_scale_denominator’)
to get a more fluent syntax for scale dependencies
New in 2.12
FOSS4G 2017, Boston
August 14th-19th 2017
47. Underline and strikethrough
New vendor options to control underline and
strikethrough
FOSS4G 2017, Boston
August 14th-19th 2017
<VendorOption name="underlineText">true</VendorOption>
<VendorOption name="strikethroughText">true</VendorOption>
48. Char and word spacing
Control how much space there is between each
char
And between words
FOSS4G 2017, Boston
August 14th-19th 2017
<VendorOption name="charSpacing">3</VendorOption>
<VendorOption name="wordSpacing">5</VendorOption>
charSpacing = 3 wordSpacing = 5
49. SVG marks
Refer to a SVG file insinde
mark/WellKnownMark
The outline of the SVG will be extracted
Then filled and stroked as requested
Suitable for simple shapes
FOSS4G 2017, Boston
August 14th-19th 2017
:mark {
fill: red;
stroke: yellow;
stroke-width: 3;
stroke-opacity: 50%;
}
50. More QGIS SLD export work
In QGIS 3.0 support for label exports (thanks for
OpenGeoGroep sponsoring)
Want to see more? Help us fund the effort
FOSS4G 2017, Boston
August 14th-19th 2017