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 : * Permission is hereby granted, free of charge, to any person obtaining a 11 : * copy of this software and associated documentation files (the "Software"), 12 : * to deal in the Software without restriction, including without limitation 13 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, 14 : * and/or sell copies of the Software, and to permit persons to whom the 15 : * Software is furnished to do so, subject to the following conditions: 16 : * 17 : * The above copyright notice and this permission notice shall be included 18 : * in all copies or substantial portions of the Software. 19 : * 20 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 : * DEALINGS IN THE SOFTWARE. 27 : ****************************************************************************/ 28 : 29 : #include "zarrdrivercore.h" 30 : 31 : /************************************************************************/ 32 : /* CheckExistenceOfOneZarrFile() */ 33 : /************************************************************************/ 34 : 35 1396 : static bool CheckExistenceOfOneZarrFile(const char *pszFilename) 36 : { 37 : 38 2792 : CPLString osMDFilename = CPLFormFilename(pszFilename, ".zarray", nullptr); 39 : 40 : VSIStatBufL sStat; 41 1396 : if (VSIStatL(osMDFilename, &sStat) == 0) 42 464 : return true; 43 : 44 932 : osMDFilename = CPLFormFilename(pszFilename, ".zgroup", nullptr); 45 932 : if (VSIStatL(osMDFilename, &sStat) == 0) 46 434 : return true; 47 : 48 : // Zarr V3 49 498 : osMDFilename = CPLFormFilename(pszFilename, "zarr.json", nullptr); 50 498 : if (VSIStatL(osMDFilename, &sStat) == 0) 51 410 : return true; 52 : 53 88 : return false; 54 : } 55 : 56 : /************************************************************************/ 57 : /* ZARRDriverIdentify() */ 58 : /************************************************************************/ 59 : 60 47124 : int ZARRDriverIdentify(GDALOpenInfo *poOpenInfo) 61 : 62 : { 63 47124 : if (STARTS_WITH(poOpenInfo->pszFilename, "ZARR:")) 64 : { 65 46 : return TRUE; 66 : } 67 : 68 47078 : if (!poOpenInfo->bIsDirectory) 69 : { 70 45657 : return FALSE; 71 : } 72 : 73 1421 : return CheckExistenceOfOneZarrFile(poOpenInfo->pszFilename); 74 : } 75 : 76 : /************************************************************************/ 77 : /* ZARRDriverSetCommonMetadata() */ 78 : /************************************************************************/ 79 : 80 1221 : void ZARRDriverSetCommonMetadata(GDALDriver *poDriver) 81 : { 82 1221 : poDriver->SetDescription(DRIVER_NAME); 83 1221 : poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES"); 84 1221 : poDriver->SetMetadataItem(GDAL_DCAP_MULTIDIM_RASTER, "YES"); 85 1221 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Zarr"); 86 1221 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES, 87 : "Byte Int16 UInt16 Int32 UInt32 Int64 UInt64 " 88 1221 : "Float32 Float64 CFloat32 CFloat64"); 89 1221 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 90 1221 : poDriver->SetMetadataItem(GDAL_DMD_SUBDATASETS, "YES"); 91 : 92 1221 : poDriver->SetMetadataItem( 93 : GDAL_DMD_OPENOPTIONLIST, 94 : "<OpenOptionList>" 95 : " <Option name='USE_ZMETADATA' type='boolean' description='Whether " 96 : "to use consolidated metadata from .zmetadata' default='YES'/>" 97 : " <Option name='CACHE_TILE_PRESENCE' type='boolean' " 98 : "description='Whether to establish an initial listing of present " 99 : "tiles' default='NO'/>" 100 : " <Option name='MULTIBAND' type='boolean' default='YES' " 101 : "description='Whether to expose >= 3D arrays as GDAL multiband " 102 : "datasets " 103 : "(when using the classic 2D API)'/>" 104 : " <Option name='DIM_X' type='string' description=" 105 : "'Name or index of the X dimension (only used when MULTIBAND=YES)'/>" 106 : " <Option name='DIM_Y' type='string' description=" 107 : "'Name or index of the Y dimension (only used when MULTIBAND=YES)'/>" 108 : " <Option name='LOAD_EXTRA_DIM_METADATA_DELAY' type='string' " 109 : "description=" 110 : "'Maximum delay in seconds allowed to set the DIM_{dimname}_VALUE band " 111 : "metadata items'/>" 112 1221 : "</OpenOptionList>"); 113 : 114 1221 : poDriver->SetMetadataItem( 115 : GDAL_DMD_MULTIDIM_DATASET_CREATIONOPTIONLIST, 116 : "<MultiDimDatasetCreationOptionList>" 117 : " <Option name='FORMAT' type='string-select' default='ZARR_V2'>" 118 : " <Value>ZARR_V2</Value>" 119 : " <Value>ZARR_V3</Value>" 120 : " </Option>" 121 : " <Option name='CREATE_ZMETADATA' type='boolean' " 122 : "description='Whether to create consolidated metadata into .zmetadata " 123 : "(Zarr V2 only)' default='YES'/>" 124 1221 : "</MultiDimDatasetCreationOptionList>"); 125 : 126 1221 : poDriver->pfnIdentify = ZARRDriverIdentify; 127 1221 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 128 1221 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE, "YES"); 129 1221 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_MULTIDIMENSIONAL, "YES"); 130 1221 : } 131 : 132 : /************************************************************************/ 133 : /* DeclareDeferredZarrPlugin() */ 134 : /************************************************************************/ 135 : 136 : #ifdef PLUGIN_FILENAME 137 : void DeclareDeferredZarrPlugin() 138 : { 139 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 140 : { 141 : return; 142 : } 143 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 144 : #ifdef PLUGIN_INSTALLATION_MESSAGE 145 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 146 : PLUGIN_INSTALLATION_MESSAGE); 147 : #endif 148 : ZARRDriverSetCommonMetadata(poDriver); 149 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 150 : } 151 : #endif