Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mapping in GeoServer with SLD and CSS

Similar presentations


Presentation on theme: "Mapping in GeoServer with SLD and CSS"— Presentation transcript:

1 Mapping in GeoServer with SLD and CSS
Ing. Andrea Aime GeoSolutions

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 FOSS4G 2015, Seoul 14th-19th September 2015

3 SLD vs CSS GeoCSS 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) Today I’m going to showcase some of the map styling abilities of GeoServer, comparing the SLD and CSS syntaxes for bothl FOSS4G 2015, Seoul 14th-19th September 2015

4 Point styling FOSS4G 2015, Seoul 14th-19th September 2015
Let’s start our dive into map styling with point styling FOSS4G 2015, Seoul 14th-19th September 2015

5 Simple symbol * { mark: symbol(triangle); } :mark { fill: maroon; }
This simple example uses the well known «triangle» mark to display a mountain peak. Notice the compactness of the CSS syntax. The one maybe weird bit is that to specifiy the color inside the mark, we need to create a special rule with the :mark selector, as using fill directly in the top level rule will make the renderer treat the points as polygons instead. FOSS4G 2015, Seoul 14th-19th September 2015

6 One symbol per point class (SLD)
We want a different symbol per landmark type 600 lines of XML for 6 different points types Too much repetition We can also render point maps with external graphisc, referring to an external image, could be a png, jpeg, svg and so on. Let’s also say we want to use six different symbols, and add labels to them. We then have to resort to add filters in rules, expressed in OGC filter syntax (XML). FOSS4G 2015, Seoul 14th-19th September 2015

7 One symbol per point class (css)
This is the same with CSS, in which the we can just setup the common rendering details for labels and marks, and then override the point symbol in more specific rules, using a filter expressed in CQL sytanx. This is much shorter, but still 70 lines of CSS. Still an excerpt But 70 lines total Power of cascading FOSS4G 2015, Seoul 14th-19th September 2015

8 Embedding attribute in url (css)
Moved the image name in the feature attributes Down to 15 lines The style is all here If we can push the name of the symbol to use as an attribute of our data called ‘IMAGE’, then we can redue it all to 15 lines of CSS, by expanding the attribute in the URL using the ${IMAGE]} syntax FOSS4G 2015, Seoul 14th-19th September 2015

9 Using TTF fonts as marks
The well known symbolis and graphics are not the only way to add symbols in GeoServer, the mark names are actually pluggable and extensible by everybody, for example, we have a special syntax to pull symbols out of fonts filled with graphic icons, such as Webdings, by specifying the font name and the symbol code, which you can get using the charmap application FOSS4G 2015, Seoul 14th-19th September 2015

10 Wind barbs mark WMO compliant wind barb mark
Accounts for speed and emisphere Examples: windbarbs://default(100)[kts] windbarbs://default(15)[m/s]emisphere=s Another example of custom marks is our ability to render wind barbs, just provide in the name the wind strenght, the unit of measure, and in case you need that, if the point is located in the northern or southern emisphere. I’m not going though all the possibilities, but there are more mark types, such as customizable arrows and the ability to specify the mark shape as a WKT geometry Full example available online in the GeoSolutions ND training material FOSS4G 2015, Seoul 14th-19th September 2015

11 Filling polygons FOSS4G-EU 2015, Como 14th-17th July 2015

12 Solid filling * { fill: lightgrey; stroke: black; stroke-width: 0.5; }
Simple solid filling is relatively simple in both CSS and SLD, although of course the lack of boilerplate and being able to use named colors is a great advantage. FOSS4G-EU 2015, Como 14th-17th July 2015

13 Filling with repeating images
A more interesting way of filling is by repeating the same image or symbol over and over. In SLD this is called using a graphic fill, in CSS you just pass a url to the target symbol in the fill property. FOSS4G-EU 2015, Como 14th-17th July 2015

14 Marks for Hatches shape://vertiline shape://horline shape://slash
shape://backslash We can also fill with marks, and there is a set that is designed for hatching, that is, a set of vertical, horizontal and diagonal lines that are filling the polygon, while still allowing you to see though it. shape://plus shape://times FOSS4G-EU 2015, Como 14th-17th July 2015

15 Filling with hatch marks
This is one example in CSS and SLD, using the «times» mark to create a cross hatch fill. Notice how we use the :fill pseudo-selector in the second css rule to control the size and color of the cross hatch. FOSS4G-EU 2015, Como 14th-17th July 2015

16 Using TTF fonts as marks
8 8 Sometimes when filling with repeated symbols you need to add some space in between them, this can be done via the graphic marging vendor option. In SLD we have the special tag VendorOption for all the vendor options, in CSS they all start with the –gt prefix instead. FOSS4G-EU 2015, Como 14th-17th July 2015

17 Painting lines FOSS4G-EU 2015, Como 14th-17th July 2015

18 Solid lines * { stroke: darkOrange; stroke-width: 5; }
Switching to lines, we can see again a simple solid line, the advantanges of CSS are pretty much the same as with fills. FOSS4G-EU 2015, Como 14th-17th July 2015

19 Dashes FOSS4G-EU 2015, Como 14th-17th July 2015
The first variation we can do is to add a dasharray, which in this case specifies an alternation of 2px lines, 2px space, 2px line, and so on. In this example we can also see how scale denominator gets controlled, with tag in XML, with a filter on the the scale pseudo property in CSS FOSS4G-EU 2015, Como 14th-17th July 2015

20 Dashes with marks (SLD)
Using GraphicStroke with dash array to draw spaced circles, and then use dasharray with a dashoffset to interleave a line. FOSS4G-EU 2015, Como 14th-17th July 2015

21 Dashes with marks (CSS)
* { stroke: darkRed, symbol('circle'); stroke-dasharray: 10 14, 6 18; stroke-dashoffset: 14, 0; } :stroke { fill: darkRed; size: 6; In CSS if one wants to apply twice the same type of symbolzer, it’s possible to just add a second value to the property, by separating them with a comma FOSS4G-EU 2015, Como 14th-17th July 2015

22 Labeling FOSS4G-EU 2015, Como 14th-17th July 2015

23 Vendor options Priority labelling, static or attribute based
16 other vendor options to control in detail labelling: group labelAllGroup spaceAround followLine maxDisplacement repeat maxAngleDelta maxAngleDelta autoWrap forceLeftToRight conflictResolution goodnessOfFit polygonAlign graphic-resize graphic-margin partial Labelling is a rather complex topic, let me just show the vendor options that allow GeoServer to produce better labelling. FOSS4G-EU 2015, Como 14th-17th July 2015

24 Point labels FOSS4G-EU 2015, Como 14th-17th July 2015
When labelling points, we often want to add the auto-wrap option to make sure the labels do not get too long FOSS4G-EU 2015, Como 14th-17th July 2015

25 Line labels FOSS4G-EU 2015, Como 14th-17th July 2015
Labelling a road network normally requires a small halo to increase readability, but also a number of GeoServer extensions to make it look good: Followline to get curved labels Repeat to get the long lines labelled multiple times Group to form a single line out of small separated segments of the same road maxDisplacement to allow the labeller to search for better positions in case a candidate one is busy FOSS4G-EU 2015, Como 14th-17th July 2015

26 Polygon labels FOSS4G-EU 2015, Como 14th-17th July 2015
Anchor point to center horizontally High priority to make them stand on top (default priority is 1000) Autowrap long labels Make sure 90% of the label is inside the polygon, allow for some search around the centroid FOSS4G-EU 2015, Como 14th-17th July 2015

27 Label Obstacles FOSS4G-EU 2015, Como 14th-17th July 2015
Make a point symbolizer into a label obstacle, so that it cannot be covered with a label FOSS4G-EU 2015, Como 14th-17th July 2015

28 Support for pre-laid-out labels
IGN has custom engine to lay out labels at all zoom levels Need to disable GeoServer own one Two new vendorOptions: conflictResolution=false partials=true Finally, if you have an engine or a human that pre-laid out the labels to achive maximum quality, you can add these two vendor options to make GeoServer stop deciding where to put the labels. These examples are courtesy of the national french geographic agency, which uses GeoServer for all the mapping purposes, but has a separate algorithm to lay out the labels once and for all for all the zoom levels they are publishing, at high quality, producing a map quality rivalling the one of printed atlases. FOSS4G-EU 2015, Como 14th-17th July 2015

29 Raster styling FOSS4G 2015, Seoul 14th-19th September 2015

30 A DEM and a color map SRTM from USGS Standard color map
No-data natively transparent in 2.8.x thanks to JAI-EXT Raster styling is almost always required when mapping raster surfaces of some kind, this one is a digital elevation model, but it could be also concentration of a pollutant, ambient noise in urban environment, and so on: in all cases we’ll want to associate colors to specific values of the phenomenon, and have GeoServer linearly interpolate between them. CSS: FOSS4G 2015, Seoul 14th-19th September 2015

31 Expressions in ColorMap
Standard ColorMapEntry accepts only static values Not anymore (GS 2.8.0) Useful with env function, picking values from the GetMap As you can remember when the zoom level we see a DEM. The DEM is based on the SRTM data set, and depcited with a elevation color map that excludes the nodata values setting their opacity to 0. As you can see it’s a bit dull, we miss hillshade &ENV=low:10;medium:100;high:500 FOSS4G 2015, Seoul 14th-19th September 2015

32 Hillshading incoming The only part of SLD 1.0 we have never had support for In the works, scheduled for GeoServer (might be backported sooner) raster-channels: auto; raster-color-map: color-map-entry(darkBlue, 0) color-map-entry(darkGreen, 1) color-map-entry(green, 300) color-map-entry(yellow, 1800) color-map-entry(maroon, 4000) color-map-entry(white, 5000); raster-relief-factor: 20; raster-relief-brightness-only: false; We are currently working on supporting hillshading, aka shaded relief, the one SLD 1.0 feature that we were still missing. Here is an example of its application on Korea, using the CSS syntax. FOSS4G 2015, Seoul 14th-19th September 2015

33 Contrast enhancement <sld:RasterSymbolizer>
<sld:ContrastEnhancement> <sld:Normalize> <sld:VendorOption name="algorithm"> StretchToMinimumMaximum </sld:VendorOption> <sld:VendorOption name="minValue">50</sld:VendorOption> <sld:VendorOption name="maxValue">800</sld:VendorOption> </sld:Normalize> </sld:ContrastEnhancement> </sld:RasterSymbolizer> We recently also updated the constrast stretching code, adding support for controlling which algorithm is used, and the range of data on which it operates. This is an example using the SLD syntad FOSS4G 2015, Seoul 14th-19th September 2015

34 Transformations FOSS4G-EU 2015, Como 14th-17th July 2015

35 Geometry transformations
Dropping a shadow by offseting the building outline a bit using a «geometry transformation», that is, calling a filter function that takes the geometry and transforms it. This is applied on the single feature geometry, and its available both via SLD and CSS FOSS4G-EU 2015, Como 14th-17th July 2015

36 Rendering transformations
CSS WPS + WMS + rendering optimizations In this slide, on the fly contour extraction Extract on the fly contour lines from the DEM calling a process using the custom «Transformation» element, which operates at the layer level. There is still no equivalent functionality in CSS The raster is tranformed into a set of lines with an elevation attribute which is then styled as vector FOSS4G-EU 2015, Como 14th-17th July 2015

37 RT: from raster to wind barbs
Two banded raster, U and V, extracted as a set of points with two attributes (subsampling possible) In this one we extract the actual values of each cell as a set of points, controlling subsampling so that only a subset of the pixel values are extracted, and then assuming this is a two band wind raster map, we can build windbarbs out of it. CSS FOSS4G-EU 2015, Como 14th-17th July 2015

38 Color blending and compositing
FOSS4G-EU 2015, Como 14th-17th July 2015

39 Color blending and compositing
Support for alpha blending and compositing between Layer/FeatureTypeStyle Alpha compositing: copy destination source-over destination-over source-in destination-in source-out destination-out source-atop destination-atop xor Color blending multiply screen overlay darken lighten color-dodge color-burn hard-light soft-light difference exclusion Color blending and compositing is a new feature in GeoServer 2.7, which allows for taking two layers in your map, and either masking them, with alpha compositing, or mix their colors, with color blending. This is controlled by a vendor option at the FeatureTypeStyle level in SLD, composite: multiply, 0.5; FOSS4G-EU 2015, Como 14th-17th July 2015

40 Alpha compositing examples
Source Destination When using compositing and color blending we always have two layers, what was already drawn so far, called the «destination», and what we want to add now, called the source. So for example, destination-in preserves the destination only if it’s inside the non transparent part of the source, source atop adds the source only on non transparent parts of the destination, and so on. As you can see, this can be used for various types of layer masking. destination-in source-atop destination-atop FOSS4G-EU 2015, Como 14th-17th July 2015

41 Masking via alpha compositing
destination-in Here is an example of alpha compositing that’s using a mask to generate a «line only on the inside of the polygon» effect FOSS4G-EU 2015, Como 14th-17th July 2015

42 Color blending examples
Source Destination Color blending instead takes the color of both source and destination, and mixes the two with different rules. Multiply is a rather common way to mix in digital elevation models in a vector map for example multiply color-burn difference FOSS4G-EU 2015, Como 14th-17th July 2015

43 Z-ordering FOSS4G-EU 2015, Como 14th-17th July 2015

44 Z ordering Added a new sortBy vendor option in SLD (sort-by in CSS), e.g.: <VendorOption name=«sortBy»>z_order</VendorOption> Allows to sort features before painting them In a _single_ FeatureTypeStyle What if one needs to do road casing, or sort across two different layers? As long as the FeatureTypeStyles involved are side by side, label them with the same sortByGroup property to sort them as one Finally, a quick tip about z-ordering, a new feature in GeoServer 2.8. With z-ordering one can control, using the sortBy property, in which order the features are drawn, either in a single layer, or across layers. Let’s see an example. FOSS4G-EU 2015, Como 14th-17th July 2015

45 CSS example [class = 'motorways'] { stroke: #990000; stroke-width: 8; z-index: 0; } [class = 'railways'] { stroke: #333333; stroke-width: 3; z-index: 2; stroke: #ffffff; stroke-width: 1.5; stroke-dasharray: 5, 5; z-index: 3; stroke: #ff6666; stroke-width: 6; stroke-linecap: round; * { sort-by: "z_order"; sort-by-group: "roadsGroup"; This is a rather complicated set of intersecting rails and roads somewhere in germany. The layer has a z_order property, and we are creating road casing effects using the z-index property, which controls the creation of featuretypestyles. The catch all rule at the bottom makes sure the features are ordered along the z-order property, and that all the feature type styles created by the z-index property are part of the same group. FOSS4G-EU 2015, Como 14th-17th July 2015

46 Questions? That’s all folks! info@geo-solutions.it
FOSS4G-EU 2015, Como 14th-17th July 2015

47 Hidden bonus section ;-)
FOSS4G-EU 2015, Como 14th-17th July 2015

48 Dynamic arrow mark Custom WellKnownMark
Arrow symbol with customizable proportions (a Mark size is controlled by the Size element) extshape://arrow?hr=[hrValue]&t=[tValue]&ab=[abValue] t: thickness (0-1) hr: height/width ratio (0-1) ab: arrow base ratio The idea of dynamic elements work with marks too, we have custom marks taking parameters, like this arrow where the proportions of height, head size, and thickness, can be controlled. The parameters can of course be coming from attributes, here too. FOSS4G 2015, Seoul 14th-19th September 2015

49 Plates (SLD) FOSS4G-EU 2015, Como 14th-17th July 2015
Using GraphicStropke with dash array to draw spaced circles, and then use dasharray with a dashoffset to interleave a line. While nothing in this SLD is out of the standard there is no mention of this approach in the standard itself, it is believed only GeoServer supports this way of building complex strokes out of dashed symbols FOSS4G-EU 2015, Como 14th-17th July 2015

50 Plates (CSS) FOSS4G-EU 2015, Como 14th-17th July 2015
TODO: put all plate related stuff close toghether! Using CSS we can see the usage of the shield better, notice how the reside and margin vendor options are used to stretch the otherwise square symbol to fit the label, with a bit of margin FOSS4G-EU 2015, Como 14th-17th July 2015


Download ppt "Mapping in GeoServer with SLD and CSS"

Similar presentations


Ads by Google