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