<div dir="ltr">Hi,<br>I have two sample WMTS servers.<br>The first is a Polish geoportal:<br><a href="https://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500">https://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500</a><br>and the second is German:<br><a href="https://basemap.de/dienste/wmts_capabilities_web_raster.xml">https://basemap.de/dienste/wmts_capabilities_web_raster.xml</a><br>Both work well in QGIS.<br>I use C API for creating bitmaps in my area of interest.<br>I use GDALDatasetRasterIO function directly with WMTS dataset and appropriate arguments.<br>The first Polish server works smoothly for different extents, different widths and heights of my output image. Unfortunately, the second one (German) lasts forever.<br>During debugging I concluded the thesis that every GDALDatasetRasterIO in my loop over raster lines, GDAL do not use cache but redownload the same tiles.<br><br>Below is a fragment from GDAL log for well-working Polish server:<br><i>[Fri Jun 28 13:06:16 2024].5430, 66.7590: HTTP: Requesting [1/3] <a href="http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500?service=WMTS&request=GetTile&version=1.0.0&layer=G2_MOBILE_500&style=default&format=image/png&TileMatrixSet=EPSG:2180&TileMatrix=EPSG:2180:4&TileRow=2&TileCol=0">http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500?service=WMTS&request=GetTile&version=1.0.0&layer=G2_MOBILE_500&style=default&format=image/png&TileMatrixSet=EPSG:2180&TileMatrix=EPSG:2180:4&TileRow=2&TileCol=0</a><br>[Fri Jun 28 13:06:16 2024].5430, 66.7590: HTTP: Requesting [2/3] <a href="http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500?service=WMTS&request=GetTile&version=1.0.0&layer=G2_MOBILE_500&style=default&format=image/png&TileMatrixSet=EPSG:2180&TileMatrix=EPSG:2180:4&TileRow=2&TileCol=1">http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500?service=WMTS&request=GetTile&version=1.0.0&layer=G2_MOBILE_500&style=default&format=image/png&TileMatrixSet=EPSG:2180&TileMatrix=EPSG:2180:4&TileRow=2&TileCol=1</a><br>[Fri Jun 28 13:06:16 2024].6670, 66.8830: HTTP: Requesting [3/3] <a href="http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500?service=WMTS&request=GetTile&version=1.0.0&layer=G2_MOBILE_500&style=default&format=image/png&TileMatrixSet=EPSG:2180&TileMatrix=EPSG:2180:4&TileRow=2&TileCol=2">http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500?service=WMTS&request=GetTile&version=1.0.0&layer=G2_MOBILE_500&style=default&format=image/png&TileMatrixSet=EPSG:2180&TileMatrix=EPSG:2180:4&TileRow=2&TileCol=2</a><br>[Fri Jun 28 13:06:16 2024].8230, 67.0390: HTTP: Request [0] <a href="http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500?service=WMTS&request=GetTile&version=1.0.0&layer=G2_MOBILE_500&style=default&format=image/png&TileMatrixSet=EPSG:2180&TileMatrix=EPSG:2180:4&TileRow=2&TileCol=0">http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500?service=WMTS&request=GetTile&version=1.0.0&layer=G2_MOBILE_500&style=default&format=image/png&TileMatrixSet=EPSG:2180&TileMatrix=EPSG:2180:4&TileRow=2&TileCol=0</a> : status = 200, type = image/png, error = (null)<br>[Fri Jun 28 13:06:16 2024].8230, 67.0390: HTTP: Request [1] <a href="http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500?service=WMTS&request=GetTile&version=1.0.0&layer=G2_MOBILE_500&style=default&format=image/png&TileMatrixSet=EPSG:2180&TileMatrix=EPSG:2180:4&TileRow=2&TileCol=1">http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500?service=WMTS&request=GetTile&version=1.0.0&layer=G2_MOBILE_500&style=default&format=image/png&TileMatrixSet=EPSG:2180&TileMatrix=EPSG:2180:4&TileRow=2&TileCol=1</a> : status = 200, type = image/png, error = (null)<br>[Fri Jun 28 13:06:16 2024].8230, 67.0390: HTTP: Request [2] <a href="http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500?service=WMTS&request=GetTile&version=1.0.0&layer=G2_MOBILE_500&style=default&format=image/png&TileMatrixSet=EPSG:2180&TileMatrix=EPSG:2180:4&TileRow=2&TileCol=2">http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/G2_MOBILE_500?service=WMTS&request=GetTile&version=1.0.0&layer=G2_MOBILE_500&style=default&format=image/png&TileMatrixSet=EPSG:2180&TileMatrix=EPSG:2180:4&TileRow=2&TileCol=2</a> : status = 200, type = image/png, error = (null)<br>[Fri Jun 28 13:06:16 2024].8240, 67.0400: GDAL: GDALOpen(/vsimem/wms/0000022663367550/wmsresult.dat, this=000002266059B0E0) succeeds as PNG.<br>[Fri Jun 28 13:06:16 2024].8260, 67.0420: GDAL: GDALClose(/vsimem/wms/0000022663367550/wmsresult.dat, this=000002266059B0E0)<br>[Fri Jun 28 13:06:16 2024].8270, 67.0430: GDAL: GDALOpen(/vsimem/wms/00000226632272D0/wmsresult.dat, this=000002266059B0E0) succeeds as PNG.<br>[Fri Jun 28 13:06:16 2024].8300, 67.0460: GDAL: GDALClose(/vsimem/wms/00000226632272D0/wmsresult.dat, this=000002266059B0E0)<br>[Fri Jun 28 13:06:16 2024].8300, 67.0460: GDAL: GDALOpen(/vsimem/wms/0000022661BEC8D0/wmsresult.dat, this=000002266059B0E0) succeeds as PNG.<br>[Fri Jun 28 13:06:16 2024].8330, 67.0490: GDAL: GDALClose(/vsimem/wms/0000022661BEC8D0/wmsresult.dat, this=000002266059B0E0) <br></i><br>And here is log snippet for German server:<br><i>[Fri Jun 28 13:16:02 2024].0840, 652.3000: HTTP: Requesting [1/5] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/0.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/0.png</a><br>[Fri Jun 28 13:16:02 2024].0840, 652.3000: HTTP: Requesting [2/5] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/1.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/1.png</a><br>[Fri Jun 28 13:16:02 2024].2690, 652.4850: HTTP: Requesting [3/5] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/2.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/2.png</a><br>[Fri Jun 28 13:16:02 2024].2870, 652.5030: HTTP: Requesting [4/5] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/3.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/3.png</a><br>[Fri Jun 28 13:16:02 2024].3140, 652.5300: HTTP: Requesting [5/5] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/4.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/4.png</a><br>[Fri Jun 28 13:16:02 2024].5970, 652.8130: HTTP: Request [0] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/0.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/0.png</a> : status = 200, type = image/png, error = (null)<br>[Fri Jun 28 13:16:02 2024].5970, 652.8130: HTTP: Request [1] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/1.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/1.png</a> : status = 200, type = image/png, error = (null)<br>[Fri Jun 28 13:16:02 2024].5970, 652.8130: HTTP: Request [2] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/2.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/2.png</a> : status = 200, type = image/png, error = (null)<br>[Fri Jun 28 13:16:02 2024].5970, 652.8130: HTTP: Request [3] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/3.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/3.png</a> : status = 200, type = image/png, error = (null)<br>[Fri Jun 28 13:16:02 2024].5970, 652.8130: HTTP: Request [4] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/4.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/4.png</a> : status = 0, type = (null), error = (null)<br>[Fri Jun 28 13:16:02 2024].5970, 652.8130: GDAL: GDALOpen(/vsimem/wms/0000022661D59690/wmsresult.dat, this=000002266059B0E0) succeeds as PNG.<br>[Fri Jun 28 13:16:02 2024].5990, 652.8150: GDAL: GDALClose(/vsimem/wms/0000022661D59690/wmsresult.dat, this=000002266059B0E0)<br>[Fri Jun 28 13:16:02 2024].6190, 652.8350: WMS: Clean cache<br>[Fri Jun 28 13:16:02 2024].6190, 652.8350: GDAL: GDALOpen(/vsimem/wms/000002266237A190/wmsresult.dat, this=000002266059B0E0) succeeds as PNG.<br>[Fri Jun 28 13:16:02 2024].6200, 652.8360: GDAL: GDALClose(/vsimem/wms/000002266237A190/wmsresult.dat, this=000002266059B0E0)<br>[Fri Jun 28 13:16:02 2024].6340, 652.8500: GDAL: GDALOpen(/vsimem/wms/0000022662340E00/wmsresult.dat, this=000002266059B0E0) succeeds as PNG.<br>[Fri Jun 28 13:16:02 2024].6340, 652.8500: GDAL: GDALClose(/vsimem/wms/0000022662340E00/wmsresult.dat, this=000002266059B0E0)<br>[Fri Jun 28 13:16:02 2024].6350, 652.8510: GDAL: GDALOpen(/vsimem/wms/00000226605A35B0/wmsresult.dat, this=000002266059B0E0) succeeds as PNG.<br>[Fri Jun 28 13:16:02 2024].6360, 652.8520: GDAL: GDALClose(/vsimem/wms/00000226605A35B0/wmsresult.dat, this=000002266059B0E0)<br>[Fri Jun 28 13:16:02 2024].6360, 652.8520: WMS: ReadBlockFromCache<br>[Fri Jun 28 13:16:02 2024].6370, 652.8530: CPLError: ./gdalwmscache\76ac5c8f3010af4e1a17a26a53e6ac32/0/b/0bab9c0d45a96010ec0092c98e78a52d: No such file or directory<br>ERROR 4: ./gdalwmscache\76ac5c8f3010af4e1a17a26a53e6ac32/0/b/0bab9c0d45a96010ec0092c98e78a52d: No such file or directory<br>[Fri Jun 28 13:16:02 2024].6370, 652.8530: CPLError: GDALWMS: Unable to open downloaded block.<br>ERROR 1: GDALWMS: Unable to open downloaded block.<br>[Fri Jun 28 13:16:02 2024].6370, 652.8530: WMS: After ReadBlockFromCache<br>[Fri Jun 28 13:16:02 2024].6370, 652.8530: CPLError: GDALWMS: Unable to download block 4, 0.<br>URL: <br>  HTTP status code: 0, error: (null).<br>Add the HTTP status code to <ZeroBlockHttpCodes> to ignore this error (see <a href="http://www.gdal.org/frmt_wms.html">http://www.gdal.org/frmt_wms.html</a>).<br>ERROR 1: GDALWMS: Unable to download block 4, 0.<br>URL: <br>  HTTP status code: 0, error: (null).<br>Add the HTTP status code to <ZeroBlockHttpCodes> to ignore this error (see <a href="http://www.gdal.org/frmt_wms.html">http://www.gdal.org/frmt_wms.html</a>).<br>[Fri Jun 28 13:16:02 2024].6370, 652.8530: CPLError: GDAL_WMS>, band 3: IReadBlock failed at X offset 0, Y offset 0: GDALWMS: Unable to download block 4, 0.<br>URL: <br>  HTTP status code: 0, error: (null).<br>Add the HTTP status code to <ZeroBlockHttpCodes> to ignore this error (see <a href="http://www.gdal.org/frmt_wms.html">http://www.gdal.org/frmt_wms.html</a>).<br>ERROR 1: GDAL_WMS>, band 3: IReadBlock failed at X offset 0, Y offset 0: GDALWMS: Unable to download block 4, 0.<br>URL: <br>  HTTP status code: 0, error: (null).<br>Add the HTTP status code to <ZeroBlockHttpCodes> to ignore this error (see <a href="http://www.gdal.org/frmt_wms.html">http://www.gdal.org/frmt_wms.html</a>).<br>[Fri Jun 28 13:16:02 2024].6380, 652.8540: GDAL: GDALOpen(./gdalwmscache\76ac5c8f3010af4e1a17a26a53e6ac32/1/5/15b3159bb18ea6f97264bd4d0bac680e, this=000002266059B0E0) succeeds as PNG.<br>[Fri Jun 28 13:16:02 2024].6380, 652.8540: GDAL: GDALClose(./gdalwmscache\76ac5c8f3010af4e1a17a26a53e6ac32/1/5/15b3159bb18ea6f97264bd4d0bac680e, this=000002266059B0E0)<br>[Fri Jun 28 13:16:02 2024].6390, 652.8550: HTTP: Requesting [1/1] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/4.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/4.png</a><br>[Fri Jun 28 13:16:02 2024].8540, 653.0700: HTTP: Request [0] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/4.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/4.png</a> : status = 0, type = (null), error = (null)<br>[Fri Jun 28 13:16:02 2024].8540, 653.0700: WMS: ReadBlockFromCache<br>[Fri Jun 28 13:16:02 2024].8550, 653.0710: CPLError: ./gdalwmscache\76ac5c8f3010af4e1a17a26a53e6ac32/0/b/0bab9c0d45a96010ec0092c98e78a52d: No such file or directory<br>ERROR 4: ./gdalwmscache\76ac5c8f3010af4e1a17a26a53e6ac32/0/b/0bab9c0d45a96010ec0092c98e78a52d: No such file or directory<br>[Fri Jun 28 13:16:02 2024].8550, 653.0710: CPLError: GDALWMS: Unable to open downloaded block.<br>ERROR 1: GDALWMS: Unable to open downloaded block.<br>[Fri Jun 28 13:16:02 2024].8550, 653.0710: WMS: After ReadBlockFromCache<br>[Fri Jun 28 13:16:02 2024].8550, 653.0710: CPLError: GDALWMS: Unable to download block 4, 0.<br>URL: <br>  HTTP status code: 0, error: (null).<br>Add the HTTP status code to <ZeroBlockHttpCodes> to ignore this error (see <a href="http://www.gdal.org/frmt_wms.html">http://www.gdal.org/frmt_wms.html</a>).<br>ERROR 1: GDALWMS: Unable to download block 4, 0.<br>URL: <br>  HTTP status code: 0, error: (null).<br>Add the HTTP status code to <ZeroBlockHttpCodes> to ignore this error (see <a href="http://www.gdal.org/frmt_wms.html">http://www.gdal.org/frmt_wms.html</a>).<br>[Fri Jun 28 13:16:02 2024].8550, 653.0710: CPLError: GDAL_WMS>, band 3: IReadBlock failed at X offset 0, Y offset 0: GDALWMS: Unable to download block 4, 0.<br>URL: <br>  HTTP status code: 0, error: (null).<br>Add the HTTP status code to <ZeroBlockHttpCodes> to ignore this error (see <a href="http://www.gdal.org/frmt_wms.html">http://www.gdal.org/frmt_wms.html</a>).<br>ERROR 1: GDAL_WMS>, band 3: IReadBlock failed at X offset 0, Y offset 0: GDALWMS: Unable to download block 4, 0.<br>URL: <br>  HTTP status code: 0, error: (null).<br>Add the HTTP status code to <ZeroBlockHttpCodes> to ignore this error (see <a href="http://www.gdal.org/frmt_wms.html">http://www.gdal.org/frmt_wms.html</a>).<br>[Fri Jun 28 13:16:02 2024].8560, 653.0720: GDAL: GDALOpen(./gdalwmscache\76ac5c8f3010af4e1a17a26a53e6ac32/1/5/15b3159bb18ea6f97264bd4d0bac680e, this=000002266059B0E0) succeeds as PNG.<br>[Fri Jun 28 13:16:02 2024].8560, 653.0720: GDAL: GDALClose(./gdalwmscache\76ac5c8f3010af4e1a17a26a53e6ac32/1/5/15b3159bb18ea6f97264bd4d0bac680e, this=000002266059B0E0)<br>[Fri Jun 28 13:16:02 2024].8570, 653.0730: HTTP: Requesting [1/1] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/4.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/4.png</a><br>[Fri Jun 28 13:16:03 2024].0760, 653.2920: HTTP: Request [0] <a href="https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/4.png">https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/DE_EPSG_25832_ADV/02/0/4.png</a> : status = 0, type = (null), error = (null)<br>[Fri Jun 28 13:16:03 2024].0760, 653.2920: WMS: ReadBlockFromCache<br>[Fri Jun 28 13:16:03 2024].0760, 653.2920: CPLError: ./gdalwmscache\76ac5c8f3010af4e1a17a26a53e6ac32/0/b/0bab9c0d45a96010ec0092c98e78a52d: No such file or directory<br>ERROR 4: ./gdalwmscache\76ac5c8f3010af4e1a17a26a53e6ac32/0/b/0bab9c0d45a96010ec0092c98e78a52d: No such file or directory<br>[Fri Jun 28 13:16:03 2024].0760, 653.2920: CPLError: GDALWMS: Unable to open downloaded block.<br>ERROR 1: GDALWMS: Unable to open downloaded block.<br>[Fri Jun 28 13:16:03 2024].0760, 653.2920: WMS: After ReadBlockFromCache<br>[Fri Jun 28 13:16:03 2024].0760, 653.2920: CPLError: GDALWMS: Unable to download block 4, 0.<br>URL: <br>  HTTP status code: 0, error: (null).<br>Add the HTTP status code to <ZeroBlockHttpCodes> to ignore this error (see <a href="http://www.gdal.org/frmt_wms.html">http://www.gdal.org/frmt_wms.html</a>).<br>ERROR 1: GDALWMS: Unable to download block 4, 0.<br>URL: <br>  HTTP status code: 0, error: (null).<br>Add the HTTP status code to <ZeroBlockHttpCodes> to ignore this error (see <a href="http://www.gdal.org/frmt_wms.html">http://www.gdal.org/frmt_wms.html</a>).<br>[Fri Jun 28 13:16:03 2024].0760, 653.2920: CPLError: GDAL_WMS>, band 3: IReadBlock failed at X offset 0, Y offset 0: GDALWMS: Unable to download block 4, 0.<br>URL: <br>  HTTP status code: 0, error: (null).<br>Add the HTTP status code to <ZeroBlockHttpCodes> to ignore this error (see <a href="http://www.gdal.org/frmt_wms.html">http://www.gdal.org/frmt_wms.html</a>).<br>ERROR 1: GDAL_WMS>, band 3: IReadBlock failed at X offset 0, Y offset 0: GDALWMS: Unable to download block 4, 0.<br>URL: <br>  HTTP status code: 0, error: (null).<br>Add the HTTP status code to <ZeroBlockHttpCodes> to ignore this error (see <a href="http://www.gdal.org/frmt_wms.html">http://www.gdal.org/frmt_wms.html</a>).</i><br><br>How you see, GDAL tries to open cache that does not exist.<br>But in fact, it exist. I found all necessary tile for full extent map request in gdalwmscache folder.<br><div>I can not send it in this email because of message size limits.</div><div><br></div><div>Regards,</div><div>Michał</div></div>