Geospatial CMS


How to use QGis for great looking symbols in Cartaro

Since Cartaro does support the easy creation of user defined content types and OGC compliant services it is only logical to advance a step further and provide the ability for user defined styles as well. Custom layer styles are therefore available now for rendering directly in the browser for WFS layers and on the server for WMS services. Both layer types are served by Cartaro with the help of OpenLayers and GeoServer.

To get started a SLD 1.0 file is required. The file works for WFS and WMS layers but there is no need to use both layer types. The layers' styles are defined in the SLD file and allow to control the whole styling of the layer. The attributes of your features can be used to modify the appearance, too.

This tutorial will walk you through customizing layers styles for both WFS and WMS layers in order to get nice looking maps of gauges. First of all a content type needs to be defined in Cartaro to store the layer's data. In addition to the usual fields as introduced in Cartaro's Getting Started guide, a field for the features purpose (type) will be added and holds whether a line is a gauge on ground or over a bridge. Usually one would predefine the types by using a drop-down field and add more custom fields but a text field should suffice for the sake of the tutorial. Note that the field names are arbitrary.

Defining a CMS content type in Cartaro with a spatial data
Defining a CMS content type in Cartaro with a spatial data. The fields shape and type will store the features and their purpose respectively.

Now add some sample data by tracing over a background layer using OpenLayers Editor or import existing data. When tracing another feature it is advisable to enable snapping to existing features. Create at least one feature and classify it as gauge and one that is a bridge to have something to play with when defining styles.

Drawing features in Cartaro with optional snapping.
Drawing features in Cartaro with snapping

It is now time to inform GeoServer about the desired style for the data. To do so navigate to StructureGeoServerStyles and click Add in Cartaro's administrative view to create a new style for use with GeoServer. Choose a name of your liking and provide a description about the style for other users/colleagues. Enter the SLD source code in the text field provided and click Save.
You can write the SLD by hand but it is usually more favourable to make use of tool support. QGIS is used in this article but other style editors should be fine as well.

Open up QGIS and click LayerAdd WFS Layer…, then add a connection to Cartaro's GeoServer and add the layer to your project. You should now see some lines on the screen and Cartaro's layer in the layer list if everything goes smoothly. The layer's properties dialogue provides a good style editor and styles can be applied without closing the dialogue which allows to design styles quickly. When the style is ready it can be exported either using Adrian Weber's Save as SLD plugin or the native SLD export that got added to QGIS recently.

Using QGIS to define styles for import into Cartaro
Using QGIS to define styles for import into Cartaro where a content type's fields serve for distinguishable style.

We used the following SLD to achieve a styling similar to what is usually found on maps when drawing train gauges: <?xml version="1.0" encoding="UTF-8"?> <StyledLayerDescriptor version="1.0.0" xsi:schemaLocation=" StyledLayerDescriptor.xsd" xmlns="" xmlns:ogc="" xmlns:xlink="" xmlns:xsi=""> <NamedLayer> <Name>trainsample</Name> <UserStyle> <Name>trainsample</Name> <FeatureTypeStyle> <Rule> <Name>Bridges</Name> <ogc:Filter> <ogc:PropertyIsEqualTo> <ogc:PropertyName>field_type_value</ogc:PropertyName> <ogc:Literal>bridge</ogc:Literal> </ogc:PropertyIsEqualTo> </ogc:Filter> <LineSymbolizer> <Stroke> <CssParameter name="stroke">#ff0000</CssParameter> <CssParameter name="stroke-width">3</CssParameter> <CssParameter name="stroke-linejoin">bevel</CssParameter> <CssParameter name="stroke-linecap">square</CssParameter> </Stroke> </LineSymbolizer> </Rule> <Rule> <Name>zug</Name> <ogc:Filter> <ogc:Literal>1</ogc:Literal> </ogc:Filter> <LineSymbolizer> <Stroke> <CssParameter name="stroke">#ffffff</CssParameter> <CssParameter name="stroke-width">1.26</CssParameter> <CssParameter name="stroke-linejoin">bevel</CssParameter> <CssParameter name="stroke-linecap">square</CssParameter> <CssParameter name="stroke-dasharray">5 2</CssParameter> </Stroke> </LineSymbolizer> <LineSymbolizer> <Stroke> <CssParameter name="stroke">#000000</CssParameter> <CssParameter name="stroke-width">1.26</CssParameter> <CssParameter name="stroke-linejoin">bevel</CssParameter> <CssParameter name="stroke-linecap">butt</CssParameter> <CssParameter name="stroke-dasharray">5 5</CssParameter> </Stroke> </LineSymbolizer> </Rule> </FeatureTypeStyle> </UserStyle> </NamedLayer> </StyledLayerDescriptor>

To style a WFS layer directly in the client and serve the underlying data as vectors opt to provide a WFS layer when creating a layer in Cartaro's GeoServer section under Structure. Then navigate to the OpenLayers module and edit the WFS layer just created. You can simply paste the same SLD source that was used for GeoServer or use a different style.

Finished map with features style as defined in SLD
Finished map with features styled as defined in SLD and served by GeoServer as WMS.

The SLD export in combination with GeoServer's SLD support being pretty recent and changing does have its issues. It seems QGIS is not sending credentials when it is querying GeoServer for the list of WFS layers which results in the inability to use access restricted WFS layers in QGIS.
There is also the problem of different SLD support in QGIS, GeoServer and OpenLayers. Whilst recent versions of QGIS should support SLD 1.1, GeoServer and OpenLayers are only supporting SLD 1.0. This means that SLD files as produced by QGIS can't simply be used in Cartaro without adjustments. However due to the similarity of SLD 1.0 and SLD 1.1 the amendments are usually a matter of stripping namespaces and renaming tags starting with Svg so that they read Css. Alternatively, one could use one of the QGIS plugins that are available to produce SLD 1.0 which can simply be imported without any further changes.
We've seen the native SLD support in QGIS working only on some of the computers tried and the same is true for the plugins which at times only state that they don't implement certain symbolizers. It's best to evaluate yourself which route to go and which process works best for you.

Cartaro is there to help setting up services that combine spatial data with common content management features.

« Back to Blog index