On the road to improve QGIS SLD export

qgis-gs

Dear reader,

today we would like to introduce some recent work we have done in QGIS to improve SLD export. Our GeoServer Technical Lead Andrea Aime, has been working along with others at the FOSS4G 2016 code sprint to fix some of the SLD 1.1 export issues, improving the compatibility of GeoServer to reproduce the style in the process.

The first fix regarded rotations, gaps and alpha values, which used to be expressed using a <ogc:Filter> instead of a normal OGC “expression”, or plain value. This broke standard compatibility and made GeoServer unable to interpret the corresponding values, for reference, here is a before/after comparison

Before After
<se:Rotation>
  <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
    <ogc:Literal>45</ogc:Literal>
  </ogc:Filter>
</se:Rotation>
<se:Rotation>
  <ogc:Literal>45</ogc:Literal>
</se:Rotation> 

The second issue fixed was about units of measures. QGIS allows to use different units of measure for the various sizes/widths/height values, however, the default one is “on screen mm”, and was exporting the values un-modified, with a non standard attribute at the very top reporting the unit being in millimiters. The SE specification on the other hand only supports “on screen pixel”, “on ground meter”, “on ground feet”. The change here was to remove the extraneous attribute, and rescale all values to from on screen mm to on screen pixels, e.g., a value of “10” mm would translate to 36 pixels and results in visual size preservation in SLD based tools.

Before After
 size-before size-after

One subsequent fix modified the SLD export to account for scale base visibility not only in rule based symbols, but in all common types. After all, nobody wants the server to display millions of points or roads at very small scales.
Subsequently, we noticed that GeoTools/GeoServer could not handle the way font based symbols were exported by QGIS, and this time, since QGIS export was indeed valid, we implemented support for the index based mark syntax in GeoServer.

Style Snippet

<se:Graphic>
  <se:Mark>
    <se:OnlineResource xlink:type="simple" xlink:href="ttf://Webdings"/>
    <se:Format>ttf</se:Format>
    <se:MarkIndex>109</se:MarkIndex>
    <se:Fill>
      <se:SvgParameter name="fill">#231c36</se:SvgParameter>
    </se:Fill>
  </se:Mark>
  <se:Size>36</se:Size>
</se:Graphic>

Map in GeoServer

selezione_080

Moreover, we noticed that QGIS exports a number of “well known” marks that are not actually well known. In the interest of maximizing the ability to see symbol on the other side, Jonathan Moules implemented several of the missing symbols on the GeoServer end:

Style Snippet

<se:Graphic>
  <se:Mark>
    <se:WellKnownName>pentagon</se:WellKnownName>
    <se:Fill>
      <se:SvgParameter name="fill">#dcd883</se:SvgParameter>
    </se:Fill>
    <se:Stroke>
      <se:SvgParameter name="stroke">#000000</se:SvgParameter>
    </se:Stroke>
  </se:Mark>
  <se:Size>36</se:Size>
</se:Graphic>

Map In GeoServer

selezione_081

Currently still in progress we have parametric SVG support, that allows QGIS to change some aspects of a SVG file on the fly (fill, stroke, stroke widths and opacity levels) as well as a minimal implementation of text symbolizer export (currently completely missing). Here is a show comparing plain and parametric SVG display based on the same QGIS :

Plain, no parameters With parameters
<Graphic>
  <ExternalGraphic>
    <OnlineResource xlink:type="simple" xlink:href="firestation.svg" />
    <Format>image/svg</Format>
  </ExternalGraphic>
  <size>256</size>
</Graphic>
<Graphic>
  <ExternalGraphic>
    <OnlineResource xlink:type="simple" xlink:href="firestation.svg?fill=#FF0000&amp;fill-opacity=0.5&amp;outline=#FFFF00&amp;outline-opacity=0.5&amp;outline-width=30" />
    <Format>image/svg</Format>
  </ExternalGraphic>
  <size>256</size>
</Graphic>
firestationnoparams2 firestationallparams

In terms of availability for you to try out:

  • Most of the QGIS changes are already available on the 2.16.3 release
  • The parametric SVG export one is still in the work, as well as the basic text symbolizer one
  • The external mark fixes will be available in GeoServer 2.9.2 (to be released)
  • The extra marks support will likely land in time for GeoServer 2.9.3 and GeoServer 2.10 RC1

We would like to thank the entire team involved in the changes:

  • Andrea Aime, for the QGIS SLD export changes as well as some  of the GeoTools/GeoServer
  • Alessandro Pasotti and Matthias Kuhn for reviewing and merging the pull requests against QGIS
  • Richard Duivenvoorde for the networking and support (as well as Jody Garnett for some personal introductions)
  • Jonathan Moules for adding support for several QGIS extra symbols into GeoTools
  • Last but not least, to René-Luc D’Hont for backporting the QGIS changes onto the 2.16.x series (available in 2.16.3) and 2.14.x series too (available in 2.14.7)

It is eventually worth to point out that more work will be needed to fully support the seamless integration between GeoServer and QGIS. We are going to invest on this ourselves but if you are interested in funding this effort, stay tuned since we will launch some sort or crowdfunding initiative to support this effort.

If you are interested in learning about how we can help you achieving your goals with our open source products GeoServerMapstore and GeoNetwork as well as throw our Enterprise Support Services and GeoServer Deployment Warranty offerings, feel free to contact us!
The GeoSolutions team,
 

6 comments

 
  1. # Andrea Aime

    Awesome, I’ve upgrade the post accordingly!

  2. # JOSE CONTRERAS

    Thanks,
    I´m working in aplication QGIS at Hydrographic

  3. # Henrik Schuller

    Just airing a problem when it comes to sld:

    I am working with creating sld’s containing svg and the plan is to make an online registry of svg’s.

    The problem is that it works perfect when you “xlink:href” to a location on your own computer or the standard pathing in the QGIS folder, but when you try to use ExternalGraphics with an actualt online resource(as in an svg located on a website) QGIS crashes.

    Henrik

    1. # simone giannecchini

      Ciao Henrik,
      sorry for the late answer, anyway this is a problem you need to bring to the QGIS Users list.

      Cheers,
      Simone.

  4. # Xhevair Llakaj

    Thanks, we are working on implementation of Inspire Directive.

    Regards,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>