1

I have seen several posts regarding this issue so apologies but none of them have provided a solution. I cannot figure out why GeoServer is not caching the tiles requested using WMS. I am certain I have satisfied all the requirements as listed

https://docs.geoserver.org/latest/en/user/geowebcache/using.html. The data loads fine on the map but there is nothing being cached in the gwc folder. It caches fine when previewing the layer via the GeoWebCache demo page. I am also able to cache the layers beforehand and load them using the gwc endpoint using WMTS. However, caching the data in advance is not feasible, hence wishing to call WMS and allow that to cache on the fly.

Details:

  • I have an ImageMosaic layer where the workspace and the layer are both named AREA35. Caching is enabled for this layer. I only display the layer on the Openlayers map at scales 1:5000, 1:2500, 1:1000 and 1:500 scale (4 zoom levels).
  • Using EPSG:27700 projection. Created a grid set named EPSG:27700 that has the 4 zoom levels mentioned above and the Tile width in pixels and Tile height in pixels are both set to 256. However, I am trying to test caching just the top 2 zooms levels (1:5000 and 1:2500).
  • The layer is set to use tile size 256,256 that matches the grid set dimensions.
  • Tiled=true is passed.
  • I only request a single layer (AREA35:AREA35).
  • I request tiles of size height 256 and width 256.
  • I specify the CRS to be EPSG:27700.
  • WMS version set to 1.3.0.
  • Tile format image/png8. This matches the Raster Layers setting in Caching Defaults page.
  • Requirements: “The image requested lines up with the existing grid bounds” and “A parameter is included for which there is a corresponding Parameter Filter” – not sure how to check the first one, but I have explicitly set both coordinate systems to be EPSG:27700 in the layer and the caching grid set. Also not sure about the second requirement – I know I am not passing any of the supported parameters/filters as I have no need.

Front end code (OpenLayers 3):

let aerialLayer = new openLayers.layer.Tile({
    preload: Infinity,
    visible: true,
    title: 'AREA35:AREA35',
    source: new openLayers.source.TileWMS(({
        url: 'https://<server>/geoserver/wms',
        params: {
            'LAYERS': 'AREA35:AREA35', 'TILED': true, 'VERSION': '1.3.0',
            'FORMAT': 'image/png8', 'WIDTH': 256, 'HEIGHT': 256, 'CRS': 'EPSG:27700'
        },
        serverType: 'geoserver'
    })),
    extent: [345400, 185600, 357600, 191800] 
});
map.addLayer(aerialLayer);

The map projection is also EPSG:27700 and the bounds/extent is set to the official bounds taken from spatialreference.org for EPSG:27700: [1393.0196, 13494.9764, 671196.3657, 1230275.0454]. NOTE: The caching grid set has these bounds explicitly set too, but I do not know if able to explicitly set these bounds on the layer itself in the Coordinate Reference Systems section for the declared/native SRS values.

The following is a request taken from DEV tools:

https://ServerAddress/geoserver/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng8&TRANSPARENT=true&LAYERS=AREA35%3AAREA35&TILED=true&WIDTH=256&HEIGHT=256&CRS=EPSG%3A27700&STYLES=&BBOX=350741.98472304683%2C186387.06628232426%2C351336.11561611324%2C186981.19717539067

The following are screens taken from GeoServer / GeoWebCache:

enter image description here

enter image description here

Layer Settings:

enter image description here

enter image description here

UPDATE 1: Having checked DEV tool all requests made report:

MISS / no parameter filter exists for FORMAT_OPTIONS:

enter image description here

Therefore I added a FORMAT_OPTIONS filter to the layer for dpi values (NOTE: I checked the requests to see what value is being passed for dpi. It obviously differs depending on the browser screen/resolution - so do I need to specify all possible dpi's?). I added the following

FORMAT_OPTIONS and dpi values for the layer (I checked the value being passed in the request, plus the set the default to be 90 as specified in the GeoServer docs):

enter image description here

UPDATE 2: now I receive MISS / request does not align to grid(s) 'EPSG:27700'

Is this due to one of the following:

  1. I have specified the FORMAT_OPTIONS incorrectly (including the dpi values/setting)
  2. The fact the grid set I created for caching (EPSG:27700) uses bounds that I explicitly set from official spatialreference.org website whereas the (default) EPSG:27700 SRS that the layer uses has bounds that are not the same as the caching grid set bounds? I do not know how to change the bounds of the SRS used by the layer.
4
  • why not just use the WMTS or TMS endpoint? OpenLayers and GWC support them out of the box and it will just work as designed.
    – Ian Turton
    Jul 10, 2019 at 12:40
  • @IanTurton - Hi. If I am not mistaken then does WMTS and TMS not require an endpoint to the GWC (i.e. ServerAddress/geoserver/gwc/service/wmts...). and therefore expects data to be already cached? I have used this successfully when loading data that is pre-cached using GeoWebCache. I would like to cache the data after the first call to the WMS (or any other service that suits) as I am unable to cache the data beforehand. Thanks
    – Aamiliah
    Jul 10, 2019 at 13:06
  • You are indeed mistaken, GWC will always create the tile if it is not in the cache.
    – Ian Turton
    Jul 10, 2019 at 14:03
  • Thanks again @IanTurton - using WMTS has sorted it (see my post). How can I give give you the credit for this, as I am unable to accept your comment?
    – Aamiliah
    Jul 10, 2019 at 14:42

2 Answers 2

1

FYI - I found a solution to your problem here in a similar question:

Setting height and width to TileWMS layer in OpenLayers 3

This person (and I had the same result) added to the map options when creating the map:

    pixelRatio: 1,  // this makes the tiles consitent size - makes caching work better

Before I added this to the options, using an OpenLayers layer source of type ol.source.TileWMS was including, in the requests sent to my Geoserver, a FORMAT_OPTIONS setting the dpi value, and the height and width specified were not always 256x256. So the tiles were being dynamically generated as the requests were not matching the cached tiles.

After I added this to the options, all tile requests were consistent with the cached tiles, 256x256 with no FORMAT_OPTIONS in the geoserver requests anymore. So while you've solved the issue by no longer using the WMS / GeoWebCache integration feature of Geoserver, if you ever wish to do so successfully with OpenLayers in the future, this is the solution to your issue.

0

Managed to sort it thanks to Ian Turton. I opted to call the cache using WMTS. If the tiles are not in the cache then GeoWebCache generates them on the fly and saves them to the cache. I had initially thought only calls to WMS with Direct Integration enabled would generate tiles on the fly hence why I was originally using WMS and not WMTS). The following is my call using WMTS:

let aerialLayer = new openLayers.layer.Tile({
    preload: Infinity,
    visible: true,
    title: 'AREA35',
    source: new openLayers.source.WMTS({
        url: 'https://ServerAddress/geoserver/gwc/service/wmts',
        layer: 'AREA35:AREA35',
        matrixSet: 'EPSG:27700', // Grid set used in GeoServer
        format: 'image/png8',
        projection: 'EPSG:27700',
        tileGrid: new openLayers.tilegrid.WMTS({
            origin: openLayers.extent.getTopLeft([1393.0196, 13494.9764, 671196.3657, 1230275.0454]), // Official bounds for EPSG:27700 from SpatialReference.org (also bounds used for map and grid set)
            resolutions: [ // Resolution for each cached zoom level for the GeoServer grid set
                1.4,
                0.7,
                0.28,
                0.14
            ],
            matrixIds: [ // Names given to each zoom level in GeoServer grid set
                'EPSG:27700:0',
                'EPSG:27700:1',
                'EPSG:27700:2',
                'EPSG:27700:3'
            ],
        })
    }), 
    extent: [345400, 185600, 357600, 191800] // Bounds of the Image Mosaic layer
});

map.addLayer(aerialLayer);

There was no need for me to create a parameter filter for the layer (I was unsure about this in my original post).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.