GeoServer– Categorise

Justin Doughty
Justin Doughty
  • Updated

by David Crowther

Geo Categorise 1.png

Question:

How do you use the Categorise option in GeoServer?

Answer:

As defined by the GeoServer help files, the option to Categorise

‘…. transforms a continuous-valued attribute into a set of discrete values. The function can be used within SLD styling parameters to convert the value of a feature attribute into specific values for a parameter such as colour, size, width, opacity, etc.

The categorization is defined by a list of alternating output values and data thresholds. The threshold values define the breaks between the input ranges. Inputs are converted into output values depending on which range they fall in.’

Here is an example of how I implemented it within the DynamicMaps webGIS – MapThat!

As a comparison I already have a GeoServer Style that creates a thematic map of the Lower Super Output Areas (LSOA’s) for Liverpool mapped using their Population value.

Geo Categorise 2.jpg

This original thematic uses multiple RULES within the SLD to define Literal Values to create RANGES…. e.g. between 0-1000 and then uses a Hex Colour to style the data that falls into each range.

Geo Categorise 3.jpg

In this example the SLD will need to have multiple RULES for each category which can be time consuming to create… and we currently aren’t considering the area of each LSOA boundary.

Geo Categorise 4.jpg

Now using the Categorise option we can make our analysis more accurate by also implementing an on-the-fly calculation dividing the Population by the Area of each LSOA to generate the Population Density!

Firstly, in GeoServer we will republish the Liverpool LSOA data as a layer called Liverpoollsoa_Categorise.

Geo Categorise 5.jpg

And then create a new STYLE (SLD) file called LSOA_CATEGORISE.

Geo Categorise 6.jpg

… using the Polygon Symbolizer example within the GeoServer help pages.

Geo Categorise 7.jpg

… we simply copy the text into our new SLD.

Geo Categorise 8.jpg

The highlighted values below are the numeric values to separate the data, and defines three ranges:

  • Anything less than 20
  • 20 to 100
  • And anything greater than 100

Geo Categorise 9.jpg

The highlighted values below are the colour hex values to style the data for the individual map features.

Geo Categorise 10.jpg

The Categorise in this example is using an on-the-fly calculation dividing the one field (PERSONS) by another field (LAND_KM) to create a Population density. The map will then style the LSOA’s by their density values.

So…. Firstly, we will need to edit our source data to ensure we have the correct fields.

In this example the source data is stored in a PostGIS database, so using PGAdmin let’s add a new area field.

Geo Categorise 11.jpg

And then open the LSOA layer into QGIS…

Geo Categorise 12.jpg

… where we see the new area field has blank values.

Geo Categorise 13.jpg

So, we will use the QGIS Field Calculator tool to extract the geometric AREA of each LSOA.

Geo Categorise 14.jpg

The values are however stored in Metres sq.…

Geo Categorise 15.jpg

So, again using the Field Calculator we can convert these to Kilometre Sq. by dividing by 1000000.

Geo Categorise 16.jpg

And we now have the area of each LSOA in Km sq.

Geo Categorise 17.jpg

If we take some example records we can then determine good breaks in the data e.g.  2500 / 5.44 = 450

Geo Categorise 18.jpg

Now back in GeoServer we can edit the Style file and make the following edits.

1 – change the field names to use the names of the fields in our Liverpool LSOA table.

Geo Categorise 19.jpg

2 – edit the break values to be representative of our population density data,.. and choose suitable hex values for the colours.

Geo Categorise 20.jpg

Once applied the new LSOA layer is now styled by categorising the map features using these 2 literal values, assigning a variation of the 3 colours dependant on which range the population density calculation falls within.

Geo Categorise 21.jpg

And shown in our webGIS – MapThat - the new LSOA WMS looks like the below… And now helps us to identify where there are high and low areas of population density!

Geo Categorise 22.jpg

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.