Master cartographic styling in GeoServer using Styled Layer Descriptor (SLD) and CSS, including rule-based rendering, scale dependencies, conditional filters, and rendering transformations.
Cartographic styling transforms raw spatial data into meaningful, readable maps. This module explores GeoServer's two primary styling mechanisms: Styled Layer Descriptor (SLD), an OGC-standard XML styling language, and the more concise CSS styling extension. Learners will progress from basic symbolizers to advanced rule-based rendering with scale dependencies, filters, and label placement.
The module also introduces rendering transformations, which apply processing (such as heatmaps or aggregations) during map generation, enabling dynamic, data-driven visualizations.
An SLD document is an XML file that describes how features should be rendered. It is composed of one or more <FeatureTypeStyle> elements, each containing <Rule> elements. Each rule may contain one or more symbolizers that determine the visual appearance of features.
<StyledLayerDescriptor version="1.0.0">
<NamedLayer>
<Name>workspace:roads</Name>
<UserStyle>
<FeatureTypeStyle>
<Rule>
<LineSymbolizer>
<Stroke>
<CssParameter name="stroke">#333333</CssParameter>
<CssParameter name="stroke-width">2</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
Rules control which features a style applies to. Filters restrict a rule to features matching specific conditions, while scale dependencies control visibility at different zoom levels.
>, <, >=, and <=.<MinScaleDenominator> and <MaxScaleDenominator> to control zoom visibility.| Filter Type | Purpose | Example |
|---|---|---|
| PropertyIsEqualTo | Exact match | type = 'highway' |
| PropertyIsGreaterThan | Numeric comparison | population > 10000 |
| PropertyIsBetween | Range match | value between 10 and 50 |
| And / Or | Combine conditions | type = 'road' AND lanes > 2 |
The CSS extension offers a compact alternative to SLD, using a syntax similar to web CSS. It is often easier to read and maintain for complex styles, though not all SLD features are supported.
/* Example CSS style */
* {
stroke: #333333;
stroke-width: 2;
}
[type = 'highway'] {
stroke: #ff6600;
stroke-width: 4;
}
[type = 'residential'][@scale < 50000] {
stroke: #999999;
}
Thematic styling visualizes data attributes through color and symbols. Two common approaches are:
| Style Type | Data Type | Example |
|---|---|---|
| Categorized | Qualitative | Land use: residential, commercial, industrial |
| Graduated | Quantitative | Population density ranges |
Rendering transformations apply processing during map generation, enabling dynamic visualizations that go beyond static styling.
<!-- Example heatmap rendering transformation -->
<FeatureTypeStyle>
<Transformation>
<ogc:Function name="vec:Heatmap">
<ogc:Literal>the_geom</ogc:Literal>
<ogc:Literal>weight</ogc:Literal>
</ogc:Function>
</Transformation>
</FeatureTypeStyle>
Labels improve map readability but can clutter dense datasets. GeoServer provides several strategies to manage label placement and conflicts.
<VendorOption name="conflictResolution">true</VendorOption> to hide overlapping labels.In this lab, you will create a sophisticated style for a road network layer, incorporating rule-based filters, scale dependencies, thematic coloring, and label placement.
highway, residential, and service roads, each with distinct stroke widths and colors.conflictResolution and add a halo to a text symbolizer for road name labels.| Criteria | Weight |
|---|---|
| SLD style correctness (rules, filters, scale) | 30% |
| CSS style equivalence and readability | 20% |
| Thematic styling quality | 20% |
| Label placement and conflict resolution | 15% |
| SLD vs. CSS comparison write-up | 15% |
Pass mark for this module: 70%