This is an article for advanced users
WMS often runs slowly. If there are a lot of WMS layers on the map, this can lead to frustration. How can this be remedied?
If the data is not fast-moving (e.g. an orthophoto map), you can (in some simplistic terms) download it into the System and display it as a local layer rather than a WMS layer.
In more technical terms: you can create a cache of this layer. How? The answer is presented below.
What is required to complete the task?
- The Geoserver add-on module
- A WMS address
How to create a WMS layer cache in Geoserver?
Some WMS services – especially those “rich” in data, such as an orthophoto map – run very slowly, making it almost impossible to use them comfortably. The solution to this problem is to choose a WMTS service. But what if it is not available? In a similar situation, we can reach for the so-called tile caching option. Although the name seems eccentric, the purpose is simple and clear – to reduce the time it takes for a layer to appear and to reduce the load on the server by cutting down on rendering calculations.
How does it work? Let’s imagine a certain area depicted on a map. Let’s mark its full extent with the value 0. We then divide it into four parts – this is the first level of zoom, so we can assign them the value 1 . We again divide each of the four tiles into four parts, this time obtaining as many as 16 elements. With the number of divisions, the number of elements increases, and with it the level of detail. Each tile has its own unique identifier, defined by the values X,Y and Z. The first two refer to the column and row, while the third indicates the scale level. This solution means that the client’s application itself determines which tiles to download for the visible area of the map, sending queries to each element separately. This makes downloading the information much faster.
All right, but how to achieve this effect in practice? What tools to use? You will need Geoserver and some sort of “heavy” layer for testing. A classic orthophoto map in the WMS version will be perfect for this. What’s next? Along with Geoserver, we get the GeoWebCache tool (we will continue to call it GWC), which is used to create the aforementioned tiles (interestingly, these tiles can be created for both raster and vector data). However, before we proceed to create tiles for the selected layer, we need to create a cartographic grid, on the basis of which the various zoom levels will be defined.
On the left side of the Geoserver main window is the options panel, and among them is the Tile Buffering category. Now, we move to the Cartographic Grids option.
In the next window, click on Create new cartographic grid:
We start by naming it – a good idea is to use the EPSG code of the system we want to use to create the new grid. In this case, it is the 1992 State Geodetic Coordinate System, coded 2180:
In addition to filling in the Name field, it is also necessary to indicate the reference layout. Geoserver has a built-in layout finder, which is opened by clicking on Find:
We enter the code of the layout we are looking for. The choice is made by clicking on the appropriate value in the code column:
The min/max values for the cartographic grid coverage are calculated by clicking on Calculate from maximum CRS coverage:
The size of the tile must also be defined, specifying its height and width in pixels:
Once all the necessary information has been completed (fields marked with a star), we proceed to the final step, i.e. adding zoom levels:
Each tile has a clearly defined size indicated in the units of the chosen coordinate system (for EPSG:2180 these are meters) and scale. As the zoom level increases, so does the scale, as well as the number of tiles to be generated (to be read in the tiles column). Once you have added the corresponding number of levels, save the changes by clicking on Save.
Now go back to the Tile Buffer settings and select Tile Layers:
Our aim is to create tiles for a layer with a classic orthophoto. So we select the layer of interest and click on Initial Data/Cleanup:
This launches the GeoWebCache application installed with Geoserver. In the Number of tasks to use field, we specify the number of parallel tile generation processes. In Type of operation, we choose between creating a full set of new tiles (Reseed option) or filling in the gaps (Seed). We also indicate the range of zoom levels for which tiles will be generated. Optionally, we can also specify the Bounding Box, or more precisely, the coordinates of the lower left and upper right vertices of the rectangle delimiting the extent of a specific area – in this example, the coordinates of the bounding box of the city-county of Poznań are used. To start the process, click on Submit:
We can follow the process in real time by monitoring the number of processed tiles and the time left until processing is complete (click on Refresh list to refresh the table view). For the sake of completeness, the processing here was completed in no time at all, due to the lightweight range of zoom levels 0-5. For higher zoom levels, expect much longer waiting times.
Let’s make sure that everything has gone according to plan. To do this, open the directory:
Geoserver\data_dir\gwc\name_of_layer and locate the folders containing the image files representing the tile sets for each zoom level:
Time for a test: as shown in the attached screenshot, the catalogue contains tiles from levels 3 to 12 (and thus to a maximum scale of approx. 1: 2665) created for the spatial extent of Poznań. To take advantage of the layer’s tiling capabilities, the WMS/WMTS service address must be formatted accordingly. It is also possible to refer directly to the workspace in the Geoserver where the layer is stored, e.g. (…)/geoserver/name_area/gwc/service/wmts. How do I check whether the whole thing is running faster? The easiest way is to load the service in question in QGIS and compare the rendering time of the layer without-(/geoserver/area_name/ows) and with tile service included.
Here is a comparison:
1 Without the tiles:
2. With the tiles: