by David Crowther
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.
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.
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.
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.
And then create a new STYLE (SLD) file called LSOA_CATEGORISE.
… using the Polygon Symbolizer example within the GeoServer help pages.
… we simply copy the text into our new SLD.
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
The highlighted values below are the colour hex values to style the data for the individual map features.
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.
And then open the LSOA layer into QGIS…
… where we see the new area field has blank values.
So, we will use the QGIS Field Calculator tool to extract the geometric AREA of each LSOA.
The values are however stored in Metres sq.…
So, again using the Field Calculator we can convert these to Kilometre Sq. by dividing by 1000000.
And we now have the area of each LSOA in Km sq.
If we take some example records we can then determine good breaks in the data e.g. 2500 / 5.44 = 450
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.
2 – edit the break values to be representative of our population density data,.. and choose suitable hex values for the colours.
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.
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!
Comments (0 comments)