LCOV - code coverage report
Current view: top level - frmts/zarr - zarrdrivercore.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 35 35 100.0 %
Date: 2025-01-18 12:42:00 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  Zarr driver
       5             :  * Author:   Even Rouault <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2021, Even Rouault <even dot rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "zarrdrivercore.h"
      14             : 
      15             : /************************************************************************/
      16             : /*                    CheckExistenceOfOneZarrFile()                     */
      17             : /************************************************************************/
      18             : 
      19        1411 : static bool CheckExistenceOfOneZarrFile(const char *pszFilename)
      20             : {
      21             : 
      22             :     CPLString osMDFilename =
      23        2822 :         CPLFormFilenameSafe(pszFilename, ".zarray", nullptr);
      24             : 
      25             :     VSIStatBufL sStat;
      26        1411 :     if (VSIStatL(osMDFilename, &sStat) == 0)
      27         470 :         return true;
      28             : 
      29         941 :     osMDFilename = CPLFormFilenameSafe(pszFilename, ".zgroup", nullptr);
      30         941 :     if (VSIStatL(osMDFilename, &sStat) == 0)
      31         434 :         return true;
      32             : 
      33             :     // Zarr V3
      34         507 :     osMDFilename = CPLFormFilenameSafe(pszFilename, "zarr.json", nullptr);
      35         507 :     if (VSIStatL(osMDFilename, &sStat) == 0)
      36         410 :         return true;
      37             : 
      38          97 :     return false;
      39             : }
      40             : 
      41             : /************************************************************************/
      42             : /*                     ZARRDriverIdentify()                             */
      43             : /************************************************************************/
      44             : 
      45       50201 : int ZARRDriverIdentify(GDALOpenInfo *poOpenInfo)
      46             : 
      47             : {
      48       50201 :     if (STARTS_WITH(poOpenInfo->pszFilename, "ZARR:"))
      49             :     {
      50          46 :         return TRUE;
      51             :     }
      52             : 
      53       50155 :     if (!poOpenInfo->bIsDirectory)
      54             :     {
      55       48724 :         return FALSE;
      56             :     }
      57             : 
      58        1431 :     return CheckExistenceOfOneZarrFile(poOpenInfo->pszFilename);
      59             : }
      60             : 
      61             : /************************************************************************/
      62             : /*                     ZARRDriverSetCommonMetadata()                    */
      63             : /************************************************************************/
      64             : 
      65        1381 : void ZARRDriverSetCommonMetadata(GDALDriver *poDriver)
      66             : {
      67        1381 :     poDriver->SetDescription(DRIVER_NAME);
      68        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES");
      69        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_MULTIDIM_RASTER, "YES");
      70        1381 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Zarr");
      71        1381 :     poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES,
      72             :                               "Byte Int16 UInt16 Int32 UInt32 Int64 UInt64 "
      73        1381 :                               "Float32 Float64 CFloat32 CFloat64");
      74        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
      75        1381 :     poDriver->SetMetadataItem(GDAL_DMD_SUBDATASETS, "YES");
      76             : 
      77        1381 :     poDriver->SetMetadataItem(
      78             :         GDAL_DMD_OPENOPTIONLIST,
      79             :         "<OpenOptionList>"
      80             :         "   <Option name='USE_ZMETADATA' type='boolean' description='Whether "
      81             :         "to use consolidated metadata from .zmetadata' default='YES'/>"
      82             :         "   <Option name='CACHE_TILE_PRESENCE' type='boolean' "
      83             :         "description='Whether to establish an initial listing of present "
      84             :         "tiles' default='NO'/>"
      85             :         "   <Option name='MULTIBAND' type='boolean' default='YES' "
      86             :         "description='Whether to expose >= 3D arrays as GDAL multiband "
      87             :         "datasets "
      88             :         "(when using the classic 2D API)'/>"
      89             :         "   <Option name='DIM_X' type='string' description="
      90             :         "'Name or index of the X dimension (only used when MULTIBAND=YES)'/>"
      91             :         "   <Option name='DIM_Y' type='string' description="
      92             :         "'Name or index of the Y dimension (only used when MULTIBAND=YES)'/>"
      93             :         "   <Option name='LOAD_EXTRA_DIM_METADATA_DELAY' type='string' "
      94             :         "description="
      95             :         "'Maximum delay in seconds allowed to set the DIM_{dimname}_VALUE band "
      96             :         "metadata items'/>"
      97        1381 :         "</OpenOptionList>");
      98             : 
      99        1381 :     poDriver->SetMetadataItem(
     100             :         GDAL_DMD_MULTIDIM_DATASET_CREATIONOPTIONLIST,
     101             :         "<MultiDimDatasetCreationOptionList>"
     102             :         "   <Option name='FORMAT' type='string-select' default='ZARR_V2'>"
     103             :         "     <Value>ZARR_V2</Value>"
     104             :         "     <Value>ZARR_V3</Value>"
     105             :         "   </Option>"
     106             :         "   <Option name='CREATE_ZMETADATA' type='boolean' "
     107             :         "description='Whether to create consolidated metadata into .zmetadata "
     108             :         "(Zarr V2 only)' default='YES'/>"
     109        1381 :         "</MultiDimDatasetCreationOptionList>");
     110             : 
     111        1381 :     poDriver->pfnIdentify = ZARRDriverIdentify;
     112        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
     113        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE, "YES");
     114        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_MULTIDIMENSIONAL, "YES");
     115        1381 : }
     116             : 
     117             : /************************************************************************/
     118             : /*                    DeclareDeferredZarrPlugin()                       */
     119             : /************************************************************************/
     120             : 
     121             : #ifdef PLUGIN_FILENAME
     122             : void DeclareDeferredZarrPlugin()
     123             : {
     124             :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
     125             :     {
     126             :         return;
     127             :     }
     128             :     auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME);
     129             : #ifdef PLUGIN_INSTALLATION_MESSAGE
     130             :     poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE,
     131             :                               PLUGIN_INSTALLATION_MESSAGE);
     132             : #endif
     133             :     ZARRDriverSetCommonMetadata(poDriver);
     134             :     GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
     135             : }
     136             : #endif

Generated by: LCOV version 1.14