GeoServer provides us with the functionality of styling our
layers to match our preferences. However, many are the times that many
GeoServer users face problems while publishing their layers. Styling in
GeoServer should be an easy task when doing web applications or publishing your
GIS layers via GeoServer.
 |
End expected Results |
Today, I will focus on how to apply same styles for layers
in GeoServer as in your QGIS project. Here are a few steps that can be followed
to achieve the expected results.
Load a PostGIS layer in the map canvas in QGIS using the Add PostGIS layers option in Manage Layers toolbar.
 |
Add PostGIS layer |
The Add PostGIS table
dialog box appears and it gives the option to add a connection to our PostGIS
tables
 |
Add PostGIS table |
Add connection
Fill in the form with various parameters that correspond to
the ones in the PostGIS database.
 |
Create a new PostGIS connection |
Click on connect
to load layers in the public schema.
The layers should be loaded as shown below.
 |
Add PostGIS Table loaded with layers |
Choose the layer of choice and click Add to load the layer into canvas.
 |
Africa Layer loaded in canvas |
I will now style my Africa layer in categories based on the
pop_dens_1 field.
Go to layer properties by double clicking on the layer in Layers section.
Select the Categorized
in Style section and choose pop_dens_1 as the column.
Leaving other settings default, click on classify and click Apply
 |
layer properties window |
 |
Africa layer with categorized styling |
Our Point
We want to use the style that we have applied to our layer
in GeoServer or in our Published layer. This means that we need to save this
style and use it in GeoServer. To do this, access the save style section in the layer properties window. Select SLD file
(GeoServer supports SLD files).
 |
Save Style section |
Select the location to save the style.
We are done with QGIS for now.
Access the styles
section on the left side of the page.
 |
Data section in GeoServer |
Go to Add
a new style (We are adding the style that we saved from QGIS)
Access the styles
section on the left side of the page. Go to Add
a new style (We are adding the style that we saved from QGIS)
 |
new style page |
Fill in the name and
workspace that the style will be
saved.
Then, at the bottom of the style page click on the Browse and choose the location of the
SLD file that you saved from QGIS and click open
.Click upload to load the style .
 |
Browse and upload section |
Click on validate. If
no validation errors click on submit and
the style will be saved under styles.
On the publish section
on layer in GeoServer choose africastyle to apply it in our layer .
Access the layer
preview and click on OpenLayers
against the Africa layer to load it.
 |
Layer preview in Geoserver |
The style on our layer should resemble that in our QGIS
project.
We’ve just done styling in GeoServer in few minutes and
everything is as we expected.
Repeat the process again to fully familiarize yourself with
this process.
For inquiries leave a comment below......