index.rst 6.27 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
.. _qgis:

Generating SLD styles with QGIS 
===============================

QGIS includes a sophisticated style editor with many map rendering possibilities. Styles generated
with QGIS can then be exported (with limitations) to SLD for usage with GeoServer.

QGIS style exporting abilities have been evolving over time, as a reference:

* For vector data QGIS exports SLD 1.1 styles that can be read by GeoServer. In order to get
  the suitable results it's important to use QGIS 3.0 or newer, and GeoServer 2.13.x or newer.
13
14
* Raster data styling export is new in QGIS 3.4.5 (yet to be released at the time of writing).
  This new version exports SLD 1.0 styles with vendor extensions to support constrast streching that most recent GeoServer versions support properly. For older QGIS versions limited export functionality is available using the SLD4Raster plugin.
15

16
For the export it is advised to use the :guilabel:`Save As` functionality available in the style dialog,
17
18
19
20
21
22
23
24
25
26
27
28
29
30
as indicated below in this guide. Other plugins exist that streamline the export process, but they
may ruin the style trying to adapt it to older GeoServer versions (e.g., translating it
down to SLD 1.0 by simple text processing means), or rewrite it entirely.

.. warning:: Despite the progress in the last years, it is known that not all QGIS rendering 
   options are supported by SLD and/or by GeoServer (e.g. shapeburst symbology), 
   and that support for exporting some parts  is simply missing (e.g.. expression based symbology is
   supported in SLD, but QGIS won't export it). If you are interested, both projects would welcome 
   sponsoring to improve the situation.


Exporting vector symbology
--------------------------

31
This is a step by step guide to style a GeoServer demo layer, ``sfdem``.
32

33
34
35
36
#. Open :command:`QGIS` (minimum version 3.0)
#. Load the :file:`states.shp` dataset from the GeoServer data directory, :file:`<GEOSERVER_DATA_DIR>/data/shapefiles/states.shp`
#. Double click the layer to open the :guilabel:`Properties` dialog and switch to the :guilabel:`Symbology` page.
#. Choose a `Graduated` rendering, on the ``PERSONS`` column, and click on :guilabel:`Classify` button to generate `1.5` standard deviations, select the `spectral` color ramp, switch mode to `Quantile` and finally and click on the ":guilabel:`Classify` button to generate a 5 classes map, as shown in figure.
37

38
39
   .. figure:: images/qgis-vector-style.png
      :align: center
40

41
      QGIS vector styling
42

43
#. Switch to the :guilabel:`Labels` page, choose `Single labels``, label with the ``STATE NAME`` attribute and choose your preferred text rendering options, as shown in figure
44

45
46
   .. figure:: images/qgis-label-style.png
      :align: center
47

48
      QGIS labelling
49

50
#. The layer renders as follows:
51

52
53
   .. figure:: images/qgis-vector-render.png
      :align: center
54

55
      QGIS raster styling
56

57
#. Go back At the :guilabel:`Properties` dialog, from the bottom of the :guilabel:`Styles` page, choose :menuselection:`Style --> Save Style`.
58

59
60
   .. figure:: images/qgis-vector-saveas.png
      :align: center
61

62
      *Export using Save As...*
63

64
#. Choose export in the SLD format, placing the file in the desired location.
65

66
67
   .. figure:: images/qgis-choose-format.png
      :align: center
68

69
      Choosing export format...
70

71
#. Go in GeoServer, create a new style, use the :guilabel:`Upload a new style` dialog to choose the exported file, and click on `upload` link.
72

73
74
   .. figure:: images/gs-vector-upload.png
      :align: center
75

76
      Uploading style in GeoServer...
77

78
#. Click on guilabel:`Apply`. 
79

80
#. Change to the :guilabel:`Layer preview` tab, click on the :guilabel:`Preview on Layer` link to choose ``topp:states`` to verify  proper rendering.
81

82
83
   .. figure:: images/gs-vector-preview.png
      :align: center
84

85
      Previewing style in GeoServer...
86

87
#. Eventually switch to the :guilabel:`Publishing` tab, search for ``states``, and select :guilabel:`Default` or :guilabel:`Associated` checkbox to publish the layer to use the new style permanently.
88

89
90
   .. figure:: images/gs-vector-associate.png
      :align: center
91

92
      Associating style in GeoServer...
93
94
95
96

Exporting raster symbology
--------------------------

97
This is a step by step guide to style a GeoServer demo layer, ``sfdem``.
98

99
#. Open QGIS (minimum version 3.4.5)
100
101
102
#. Load the :file:`sfdem.tif` raster from the GeoServer data directory, :file:`<GEOSERVER_DATA_DIR>/data/sf/sfdem.tif`
#. Double click the layer to open the :guilabel:`Properties` dialog and switch to the :guilabel:`Symbology` page.
#. Choose a `Singleband pseudocolor` rendering, Generate :guilabel:`Min / Max Value Settings` using :guilabel:`Mean +/- standard deviation` with using ``1.5`` standard deviations. Generate a 5 classes :guilabel:`Linear` interpolated map, as shown in figure.
103

104
105
   .. figure:: images/qgis-raster-style.png
      :align: center
106

107
      QGIS raster styling
108

109
#. The layer renders as follows:
110

111
112
   .. figure:: images/qgis-raster-render.png
      :align: center
113

114
      QGIS raster styling
115

116
#. Return to the layer's :guilabel:`Properties` dialog :guilabel:`Symbology` page, at the bottom of the page  choose :menuselection:`Style --> Save Style`.
117

118
119
   .. figure:: images/qgis-raster-saveas.png
      :align: center
120

121
      Export using Save As...
122

123
#. Choose export in the SLD format, placing the file in the desired location
124

125
126
   .. figure:: images/qgis-choose-format.png
      :align: center
127

128
      Choosing export format...
129

130
#. Go in GeoServer, create a new style, use the :guilabel:`Upload a new style` dialog to choose the exported file, and click on `upload` link.
131

132
133
   .. figure:: images/gs-raster-upload.png
      :align: center
134

135
      Uploading style in GeoServer...
136

137
#. Click on guilabel:`Apply` then change to the :guilabel:`Layer preview` tab. Click on the :guilabel:`Preview on Layer` link to choose ``sfdem`` to verify  proper rendering.
138

139
140
   .. figure:: images/gs-raster-preview.png
      :align: center
141

142
      Previewing style in GeoServer...
143

144
#. Finally switch to the :guilabel:`Publishing` tab, search for ``sfdem`` layer, and select :guilabel:`Default` or :guilabel:`Associated` checkbox to publish ``sfdem`` with the new style.
145

146
147
   .. figure:: images/gs-raster-associate.png
      :align: center
148

149
      Associating style in GeoServer...