We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Creating Maps in GeoServer using CSS and SLD

00:00

Formal Metadata

Title
Creating Maps in GeoServer using CSS and SLD
Title of Series
Number of Parts
351
Author
License
CC Attribution 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language
Production Year2022

Content Metadata

Subject Area
Genre
Abstract
The presentation aims to provide attendees with enough information to master GeoServer styling documents and most of GeoServer extensions to generate appealing, informative, readable maps that can be quickly rendered on screen. Examples will be provided from GeoSolutions training material (docs.geoserver.geo-solutions.it/edu/en/), as well as from the OSM data directory (github.com/geosolutions-it/osm-styles) we shared with the community. Several topics will be covered, providing examples in CSS and SLD, including: - Mastering common symbolization, filtering, multi-scale styling. - Using GeoServer extensions to build common hatch patterns, line styling beyond the basics, 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. - Dynamically transform data during rendering to get more explicative maps without the need to pre-process a large amount of views. - Generating styles with external tools.
Keywords
202
Thumbnail
1:16:05
226
242
Source codeSoftwareCore dumpMultiplication signOpen setMereologyOpen sourceStandard deviationServer (computing)Computer animation
StatisticsLevel (video gaming)Drill commandsServer (computing)GeometryMultiplication signComputer animation
Extension (kinesiology)Data modelSample (statistics)AbstractionRule of inferenceFraction (mathematics)Virtual machineSource codeSoftwareGenetic programmingBoilerplate (text)Scale (map)Computer-generated imageryFile formatVariable (mathematics)LeakSuite (music)Compact spaceSoftware developerUniform resource locatorFraction (mathematics)Formal languageRule of inferenceScaling (geometry)Military baseImplementationExpressionPoint (geometry)Open sourceText editorMaxima and minimaType theoryWeb 2.0Representation (politics)Level (video gaming)Artistic renderingCore dumpZoom lensCategory of beingMultiplication signGraphical user interfaceCNNObject modelCompact spaceBoilerplate (text)Extension (kinesiology)Term (mathematics)Filter <Stochastik>Line (geometry)Server (computing)Endliche ModelltheorieVirtual machineComputer iconStandard deviationSemiconductor memoryVolumenvisualisierungSingle-precision floating-point formatPointer (computer programming)Computer animationSource code
Genetic programmingVideoconferencingGame theorySource codeSoftwareBoilerplate (text)Computer-generated imageryRevision controlScale (map)Digital filterComputer iconPositional notationData typePositional notationLevel (video gaming)Web 2.0Universe (mathematics)Point (geometry)Performance appraisalSoftware engineeringGenetic programmingMedical imagingScaling (geometry)ExpressionStudent's t-testZoom lensGenetic programmingArithmetic meanSoftwareComputer animation
Source codeSoftwareSteady state (chemistry)Scale (map)Fraction (mathematics)Real numberComputer clusterClique-widthMaß <Mathematik>SummierbarkeitFormal languageScaling (geometry)Fraction (mathematics)Level (video gaming)Point (geometry)BuildingRepository (publishing)Maß <Mathematik>Different (Kate Ryan album)MetreElectronic visual displayWeb 2.0Natural numberClique-widthMappingFunctional (mathematics)Transformation (genetics)Revision controlVariable (mathematics)Ocean currentMaxima and minimaOpen setGraph coloringGaussian eliminationComputer animation
SoftwareSource codeClique-widthFunction (mathematics)ExpressionNumberBoilerplate (text)Point (geometry)BitSource codeComputer animation
Carry (arithmetic)Uniform resource locatorSource codeSoftwareSymbol tableShape (magazine)Filter <Stochastik>Genetic programmingPoint (geometry)MathematicsMedical imagingScaling (geometry)Level (video gaming)Graph coloringOpen setComputer configurationCASE <Informatik>Server (computing)CircleSource codeComputer animation
Social classJava appletCodeGeometryComputer configurationPoint (geometry)Computer fontExtension (kinesiology)RandomizationType theorySource codeComputer animation
Cross-site scriptingClique-widthSource codeSoftwareSupersonic speedInterior (topology)Generic programmingUniform resource locatorSymbol tableShape (magazine)PolygonBitGraph coloringPairwise comparisonResultantGenetic programmingVisualization (computer graphics)Type theoryShape (magazine)Genetic programmingDifferent (Kate Ryan album)Computer fontMultiplication signCASE <Informatik>Line (geometry)Inheritance (object-oriented programming)DiagonalComputer animation
SoftwareSource codeLine (geometry)Object-oriented analysis and designLine (geometry)Different (Kate Ryan album)Graph coloringWhiteboardCASE <Informatik>Level (video gaming)Order (biology)Open setComputer animation
SoftwareSource codeSymbol tableLine (geometry)Line (geometry)Array data structureMultiplicationHash functionComplex (psychology)Genetic programmingSynchronizationComputer animation
Local GroupDisplacement MappingWordControl flowGroup actionComputer configurationDifferent (Kate Ryan album)Line (geometry)Source codeComputer animation
State diagramSoftwareSource codeAttribute grammarComputer-generated imageryRadiusCross-site scriptingComputer fontDisplacement MappingLine (geometry)Local GroupLine (geometry)Level (video gaming)Point (geometry)Goodness of fitPolygonCategory of beingRule of inferenceResultantSoftwarePixelComputer configurationNumberDisplacement MappingMultiplication signArithmetic meanBitGenetic programmingMaxima and minimaTerm (mathematics)CASE <Informatik>Source codeComputer animationEngineering drawing
Network operating systemSoftwareSource codeRaster graphicsRaster graphicsTerm (mathematics)SatelliteReliefGraph coloringConcentricSurfaceClassical physicsComputer animation
Extension (kinesiology)Source codeSoftwareLevel (video gaming)Medical imagingContrast (vision)SatelliteTesselationPoint (geometry)
SoftwareSource codeAlpha (investment)Extension (kinesiology)Graph coloringLevel (video gaming)INTEGRALReliefAlpha (investment)Computer animation
SoftwareSource codeExtension (kinesiology)Local GroupClique-widthPrice indexReal numberRepresentation (politics)Level (video gaming)Transformation (genetics)WordDatabaseComputer animation
Singuläres IntegralPrice indexComputer fontRadiusSoftwareSource codeRaster graphicsComputer clusterComa BerenicesLogarithmResultantActive contour modelProcess (computing)Transformation (genetics)Artistic renderingGraph coloringDifferential (mechanical device)Raster graphicsClient (computing)Level (video gaming)Musical ensembleCASE <Informatik>AlgebraRow (database)Right angleGame controllerDynamical systemArithmetic meanSubject indexingComputer animation
Graph coloringPoint (geometry)Text editorFormal languageType theoryComputer animation
Vector spaceEvolutionarily stable strategyReceiver operating characteristicSource codeSoftwareCodeText editorRevision controlQuantileDigital filterBit rateCategory of beingDemo (music)Genetic programmingParsingSet (mathematics)Representational state transferLimit (category theory)Server (computing)Attribute grammarPoint (geometry)Computer configurationResultantMultilaterationRaster graphicsData storage deviceText editorLine (geometry)Vector spaceLevel (video gaming)MereologyGeometryComputer animation
Transcript: English(auto-generated)
My name is Andrea Aime, I've been working on GeoServer for a long time on GeoSolutions. GeoSolutions is one of the core contributors to GeoServer. We are about openness, so we are a part of OSGeo, open source, open standards, and so on. So today, I'm going to give you
a quick overview of how to style a map in GeoServer. I'm not going to get into the details of every single stat that we see, because it's going to take too much time. You can look into the slides and drill into the details later. I'm just going to give you some ideas about how the styling works. So first of all, in GeoServer, we don't have a single styling language.
We have a pluggable extension point that allows us to implement multiple styling languages support in GeoServer. So at the core stands an SLD 1.0 inspired object model that is an in-memory representation of the styles, which is based on SLD. And then we can parse from XML, SLD 1.0 and 1.1.
But we also support a CSS derived language called GeoCSS, a JSON-based language, which is Mapbox styles, and a YAML-based language, which is YSLD. Since they have to be parsed into a common model, they have to have common concepts.
So the concepts are the layers that we are rendering. Each layer gets a bunch of rules applied to it that identify what I want to render, basically. And this is done through filters or selectors, depending on the language, that identify the features that I want to render, scale dependencies that
tell the rendering engine when to render a certain feature. So a certain feature might not be visible at one zoom level, but will become visible at another. OK. And then symbolizers. That is how I paint that particular feature.
So SLD 1.0 and 1.1 are OGC styling standards. They were meant for machine-to-machine export. They were not meant for human editing. The thing is, we ended up using them as the first implementation of the styling language with an XML editor for you to type in such lovely XML. And it's still there today.
This is an SLD example. I'm omitting a lot of boilerplate, but at the top you can see an OGC filter tag, which is the filter, identifying all the features whose type is alpine hut. We can see a scale dependency, a max scale denominator of 1 to 100,000.
So 1 to 200,000, for example, this point is not going to be visible. And then the rest is just pointing to one particular icon, which is going to be used to display the point. Why SLD is basically SLD in a YAML syntax. YAML can represent pretty much all
that you can represent in XML, but typically with a much more compact syntax. And you can see this time a full style. I didn't remove any boilerplate here. Doing exactly the same. So you can see the filter, you can see the scale dependency, and the reference to the point.
It's doing exactly what the SLD is doing, but with a fraction of the text. GeoCSS is based on the concepts of CSS for the web, but it only borrows, let's say, concepts and syntax. The filtering or selectors and scale dependencies
and the properties are unique to map rendering. So in these three lines, I'm basically saying, if type is alpine art and the scale denominator is less than 100,000, then use this point. It's as compact as it gets in terms of expressiveness. And this is close to what I would like to type
if I have to type the style. And this is indeed what I'm using when I'm writing style myself. MB styles, Mapbox GL styles is JSON based. It's definitely designed not for hand editing, but for GUI editing.
For example, using Maputnik, which is a popular open source style editor for Mapbox styles, which is all point a click. It has a few things that annoy me a lot, like it's only working with Web Mercator because all the scale dependencies are expressed as zoom levels in Web Mercator.
It's strange in that, for example, symbology points to sprites, which are these large images with many sub-images inside. And then you say, which sub-image you want to use? So you basically prepare a sprite for that one stylesheet. And then it has the scale dependencies. As you can see, mean zoom nine,
which is referring to the common Web Mercator zoom levels. The filter is JSON written in postfix notation, which is like a blast from the past for me because when I was a student at software engineering, the first thing that they made me do was a postfix notation or Ungarian notation, as we called it, expression evaluator,
like first thing that I programmed at the university. It was an exercise, of course. And then the symbolizer. OK, styling concepts. How do we express the various styling concepts in the various languages? Scale dependencies. Scale dependencies in web maps are key
because unlike a printed map, people can zoom in and zoom out. And we need to display different things at different scales. So in SLD, we have a min max scale denominators that control at which scale stuff appears or disappears. In CSS, we have the at as the variable scale denominator that you can then compare to a value.
And well, you can decide, like in this example, not to show the buildings, but when I'm zoomed in enough, then I'm going to show the buildings in the map. But it's not the only way to handle scale dependencies. Another one is to express your sizes in the map as a unit of measure.
So on the ground side. And I'm saying something like, OK, my stroke is going to be five meter thick on the ground. So it's going to shrink and grow as I zoom in and zoom out because it's like it's natural size. And well, the SLD version of the style is a bit strange because there is this long URI that I
need to use to specify meters. And in CSS, I just say five meters, which is more human friendly. I can also do transformation functions, functions by which I relate to the current scale denominator to a value, a color, a thickness, and so on.
So this is taken from OpenStreetMap, the OpenStreetMap style that GeoSolutions provides for free in its own GitHub repository. And I'm basically saying, OK, use a width of two for a scale denominator less than 400,000 and then switch to the other values
as we reach the values' breaking points. In CSS, it's still compact enough. In SLD, maybe a little bit less. This is exactly the same expression using the same values but not as readable. Well, because there is a lot of boilerplate and the numbers have to be expressed straight
without using suffixes like thousands or millions. Point styling. Point styling, we have already seen an example in the introduction. We typically point to a symbol which could be a static image and we control what gets rendered by filters.
The symbol might be a simple image but it can also be a scalable SVG that then we can stroke and fill and so changes color, changes outline. Like in this case, also coming from OpenStreetMap, I have an SVG which is black and white and then I can color it to generate a bank symbol.
We can do more interesting stuff like composing marks, like superimposing two circles. In CSS, it's done by separating the two items but by a comma. And maybe also do scale dependencies so that I have a simple symbol when I'm zoomed out
and I switch to a more complex symbol as I zoom in. GeoServer has a lot of options to do point symbology so I can use true type fonts just like Esri does. I just need to point to the right code in the font. I can do wind barbs. I can do random geometries specified as WKT and so on.
There is a pluggable extension point. If you are not satisfied with these options, you can literally roll up your Java class and do it whatever way you want. Fill in polygons. Well, fill in polygons is typically easy. You provide a color for fill and a color for the outline.
This is a comparison of the two. It can get a little bit more interesting like you might be superimposing different symbology. So in this case, I get a greenish solid background but if I know the type of religion that cemetery is dedicated to,
then I'm going to superimpose different types of cross and symbols to identify the religion visually. We can also do hatching, which is pretty common to have these diagonal lines for fills. It's actually implemented by repeating over and over a small symbol.
Like in this case, shape times, it's just a small cross but as I repeat it, I get a hedge fill as a result. When it comes to line symbology, I have a few examples. This one also comes from OpenStreetMap. So in this case, I'm just specifying the stroke and stroke opacity, so the color
and the opacity of the color. The interesting stuff is actually the selectors that activate different country borders or let's say different administrative borders as I zoom in and out. So I start seeing country borders and then province borders or region borders and so on and so on.
Sorry. Interesting enough, we can do dashing and symbol repetition to compose a complex symbology such as weather fronts or fault lines and the like which typically require to repeat symbology along the line and yeah, that can be done.
We can even synchronize multiple hashes, sorry, multiple dash arrays so that they, well, basically intersect with each other generating a more complex symbology. Labeling, labeling is always complicated. SLD and friends have little options to control it.
We came up with a ton of vendor options to control in detail how the labels are placed. We have a lot to, I don't know, repeat the labels, group labels coming from different road segments into one long line, auto-wrapping and so on.
I have a few examples here. So in this case, I have a polygon label in SLD. I'm saying, okay, pick the label from this property with this font, place it in the middle of the polygon and then auto-wrap it up to 100 pixels so to avoid the very long labels, it's gonna go on the next line.
I'm forcing max displacement of 200 so I can move the label a little bit and a goodness of fit of 90%, meaning 90% of the label has to sit inside of the polygon. Sometimes, I mean, it can get ugly if my label is 10 times bigger than the polygon strength label. So we typically have a 50% rule.
The label has to be 50% inside the polygon, it can overlap, but we can control it. Point labels are also interesting. The interesting bit, in my opinion, is actually the setting obstacles. So in point symbology, I could say that the point symbol is actually an obstacle for labels
so that labels will never overlap on my point symbology, which would make the map less readable. Line labels are typically also pretty complicated, especially when we try to label road networks. So we want to label along the lines, so curving. We might want to repeat them if the line is very long.
If we have multiple segments, we have to put them together and label the result and so on. So we have a number of vendor options to control that. In terms of raster styling, we can do, well, the classic digital elevation model or whatever raster surface you have,
temperature, concentration of whatever pollutant, and you assay colors to the various values, and you create a ramp of colors. You can do also shaded relief if you want. When it comes to satellite imagery, you have all these 16-bit images, you probably want to do contrast enhancement,
and we actually extended SLD so that we can control the levels of contrast enhancement, starting point, end point, so that all the tiles coming from that one image are constant-enhanced in the same way. Other assorted features, just so we can do color blending and alpha compositing, which can be used for masking
or for, I don't know, nice shaded relief integration in a map. We can do Z-ordering eventually across layers, so think about, this is a real world intersection in Germany with roads and rails,
and it requires like 20 Z-levels, it's like crazy. And we are, well, we have the Z-level in the database, and we are sorting it and painting stuff accordingly to get a real world representation of what's below and what's above. Rendering transformations are always a key care.
The idea is that we take our road data from a raster in this case, and we can apply some light processing like a contour extraction on the fly, and render the result without ever having to store the contours anywhere, which is pretty interesting if your contours are dynamic,
so controlled by the client. Another rendering transformation that we have is called GIFL, it's raster algebra, and so you can take something like Sentinel-2, which has 13 bands, and apply some math and come up with interesting indicators or indexes,
such as the NDVI, I never remember, the meaning, whatever, it's differential vegetation something. Right, and then use a color map to control the colors.
I've shown you so far only text, so the idea is that you are gonna type your language. I do it when I do it in CSS. I'm not very happy if I have to do it in SLD, but I do it anyways. There are also point and click editors.
Point and click editors, for example, you can start with QGIS and then do save as SLD and import the result into your server. Don't expect the true fidelity. QGIS has a set of rendering options which do not appear in SLD, so it's impossible to translate them. It has some limitation in what it can translate,
so SLD is fully attribute-driven, but QGIS cannot export properly the attribute-driven part, so if you say my line width comes from this attribute, you can do it in QGIS, but the SLD export fails, and it's gonna use I don't remember what, but not the attribute. But for simple styles, it's gonna work,
both raster and vector, and you can use it as a starting point for anti-tweaking later. There's Geostyler, which is an online style editor, which is, again, point and click, and it shows you the generated SLD as you go,
and coming from GeoSolutions, we have the Map Store Styler, which is if you are using GeoNode, you know that the Styler that you are using to make styles in GeoNode, and it also generates SLD, and then uses the GeoServer REST API to apply it to GeoServer. And with that said, this would be it.