LCOV - code coverage report
Current view: top level - frmts/wmts - wmtsdrivercore.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 35 36 97.2 %
Date: 2025-10-19 15:46:27 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL WMTS driver
       4             :  * Purpose:  Implement GDAL WMTS support
       5             :  * Author:   Even Rouault, <even dot rouault at spatialys dot com>
       6             :  * Funded by Land Information New Zealand (LINZ)
       7             :  *
       8             :  **********************************************************************
       9             :  * Copyright (c) 2015, Even Rouault <even dot rouault at spatialys dot com>
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #include "wmtsdrivercore.h"
      15             : #include "gdal_frmts.h"
      16             : #include "gdalplugindriverproxy.h"
      17             : 
      18             : /************************************************************************/
      19             : /*                     WMTSDriverIdentify()                             */
      20             : /************************************************************************/
      21             : 
      22       59854 : int WMTSDriverIdentify(GDALOpenInfo *poOpenInfo)
      23             : 
      24             : {
      25       59854 :     if (STARTS_WITH_CI(poOpenInfo->pszFilename, "WMTS:"))
      26         112 :         return TRUE;
      27             : 
      28       59742 :     if (STARTS_WITH_CI(poOpenInfo->pszFilename, "<GDAL_WMTS"))
      29           8 :         return TRUE;
      30             : 
      31       59734 :     const bool bIsSingleDriver = poOpenInfo->IsSingleAllowedDriver("WMTS");
      32       59732 :     if (bIsSingleDriver && (STARTS_WITH(poOpenInfo->pszFilename, "http://") ||
      33          25 :                             STARTS_WITH(poOpenInfo->pszFilename, "https://")))
      34             :     {
      35           3 :         return true;
      36             :     }
      37             : 
      38       59729 :     if (poOpenInfo->nHeaderBytes == 0)
      39       55322 :         return FALSE;
      40             : 
      41        4407 :     const char *pszHeader =
      42             :         reinterpret_cast<const char *>(poOpenInfo->pabyHeader);
      43        4407 :     if (strstr(pszHeader, "<GDAL_WMTS") ||
      44        4398 :         ((strstr(pszHeader, "<Capabilities") ||
      45        4392 :           strstr(pszHeader, "<wmts:Capabilities")) &&
      46           6 :          strstr(pszHeader, "http://www.opengis.net/wmts/1.0")))
      47             :     {
      48          16 :         return TRUE;
      49             :     }
      50             : 
      51        4391 :     if (bIsSingleDriver)
      52             :     {
      53           3 :         while (*pszHeader != 0 &&
      54           4 :                std::isspace(static_cast<unsigned char>(*pszHeader)))
      55           0 :             ++pszHeader;
      56           3 :         return *pszHeader == '<';
      57             :     }
      58             : 
      59        4388 :     return FALSE;
      60             : }
      61             : 
      62             : /************************************************************************/
      63             : /*                      WMTSDriverSetCommonMetadata()                   */
      64             : /************************************************************************/
      65             : 
      66        1750 : void WMTSDriverSetCommonMetadata(GDALDriver *poDriver)
      67             : {
      68        1750 :     poDriver->SetDescription(DRIVER_NAME);
      69        1750 :     poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES");
      70        1750 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "OGC Web Map Tile Service");
      71        1750 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/wmts.html");
      72             : 
      73        1750 :     poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, "WMTS:");
      74             : 
      75        1750 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
      76             : 
      77        1750 :     poDriver->SetMetadataItem(
      78             :         GDAL_DMD_OPENOPTIONLIST,
      79             :         "<OpenOptionList>"
      80             :         "  <Option name='URL' type='string' description='URL that points to "
      81             :         "GetCapabilities response' required='YES'/>"
      82             :         "  <Option name='LAYER' type='string' description='Layer identifier'/>"
      83             :         "  <Option name='TILEMATRIXSET' alias='TMS' type='string' "
      84             :         "description='Tile matrix set identifier'/>"
      85             :         "  <Option name='TILEMATRIX' type='string' description='Tile matrix "
      86             :         "identifier of maximum zoom level. Exclusive with ZOOM_LEVEL.'/>"
      87             :         "  <Option name='ZOOM_LEVEL' alias='ZOOMLEVEL' type='int' "
      88             :         "description='Maximum zoom level. Exclusive with TILEMATRIX.'/>"
      89             :         "  <Option name='STYLE' type='string' description='Style identifier'/>"
      90             :         "  <Option name='EXTENDBEYONDDATELINE' type='boolean' "
      91             :         "description='Whether to enable extend-beyond-dateline behaviour' "
      92             :         "default='NO'/>"
      93             :         "  <Option name='EXTENT_METHOD' type='string-select' description='How "
      94             :         "the raster extent is computed' default='AUTO'>"
      95             :         "       <Value>AUTO</Value>"
      96             :         "       <Value>LAYER_BBOX</Value>"
      97             :         "       <Value>TILE_MATRIX_SET</Value>"
      98             :         "       <Value>MOST_PRECISE_TILE_MATRIX</Value>"
      99             :         "  </Option>"
     100             :         "  <Option name='CLIP_EXTENT_WITH_MOST_PRECISE_TILE_MATRIX' "
     101             :         "type='boolean' description='Whether to use the implied bounds of the "
     102             :         "most precise tile matrix to clip the layer extent (defaults to NO if "
     103             :         "layer bounding box is used, YES otherwise)'/>"
     104             :         "  <Option name='CLIP_EXTENT_WITH_MOST_PRECISE_TILE_MATRIX_LIMITS' "
     105             :         "type='boolean' description='Whether to use the implied bounds of the "
     106             :         "most precise tile matrix limits to clip the layer extent (defaults to "
     107             :         "NO if layer bounding box is used, YES otherwise)'/>"
     108        1750 :         "</OpenOptionList>");
     109             : 
     110        1750 :     poDriver->pfnIdentify = WMTSDriverIdentify;
     111        1750 :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
     112        1750 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES");
     113        1750 : }
     114             : 
     115             : /************************************************************************/
     116             : /*                     DeclareDeferredWMTSPlugin()                      */
     117             : /************************************************************************/
     118             : 
     119             : #ifdef PLUGIN_FILENAME
     120             : void DeclareDeferredWMTSPlugin()
     121             : {
     122             :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
     123             :     {
     124             :         return;
     125             :     }
     126             :     auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME);
     127             : #ifdef PLUGIN_INSTALLATION_MESSAGE
     128             :     poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE,
     129             :                               PLUGIN_INSTALLATION_MESSAGE);
     130             : #endif
     131             :     WMTSDriverSetCommonMetadata(poDriver);
     132             :     GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
     133             : }
     134             : #endif

Generated by: LCOV version 1.14