Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL TileDB Driver 4 : * Purpose: Implement GDAL TileDB Support based on https://www.tiledb.io 5 : * Author: TileDB, Inc 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2023, TileDB, Inc 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #define INCLUDE_ONLY_TILEDB_VERSION 14 : #include "include_tiledb.h" 15 : 16 : #include "tiledbdrivercore.h" 17 : 18 : /************************************************************************/ 19 : /* TileDBDriverIdentifySimplified() */ 20 : /************************************************************************/ 21 : 22 62596 : int TileDBDriverIdentifySimplified(GDALOpenInfo *poOpenInfo) 23 : 24 : { 25 62596 : if (STARTS_WITH_CI(poOpenInfo->pszFilename, "TILEDB:")) 26 : { 27 4 : return TRUE; 28 : } 29 : 30 62592 : if (poOpenInfo->IsSingleAllowedDriver("TileDB")) 31 : { 32 107 : return TRUE; 33 : } 34 : 35 : const char *pszConfig = 36 62465 : CSLFetchNameValue(poOpenInfo->papszOpenOptions, "TILEDB_CONFIG"); 37 : 38 62477 : if (pszConfig != nullptr) 39 : { 40 0 : return TRUE; 41 : } 42 : 43 62477 : if (!poOpenInfo->bIsDirectory) 44 : { 45 60464 : return false; 46 : } 47 : 48 4016 : const bool bIsS3OrGS = STARTS_WITH_CI(poOpenInfo->pszFilename, "/VSIS3/") || 49 2003 : STARTS_WITH_CI(poOpenInfo->pszFilename, "/VSIGS/"); 50 : // If this is a /vsi virtual file systems, bail out, except if it is S3 or GS. 51 2013 : if (!bIsS3OrGS && STARTS_WITH(poOpenInfo->pszFilename, "/vsi")) 52 : { 53 932 : return false; 54 : } 55 : 56 1081 : return GDAL_IDENTIFY_UNKNOWN; 57 : } 58 : 59 : /************************************************************************/ 60 : /* TileDBDriverSetCommonMetadata() */ 61 : /************************************************************************/ 62 : 63 : #define XSTRINGIFY(X) #X 64 : #define STRINGIFY(X) XSTRINGIFY(X) 65 : 66 1314 : void TileDBDriverSetCommonMetadata(GDALDriver *poDriver) 67 : { 68 1314 : poDriver->SetDescription(DRIVER_NAME); 69 1314 : poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES"); 70 1314 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 71 1314 : poDriver->SetMetadataItem(GDAL_DCAP_SUBCREATECOPY, "YES"); 72 1314 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "TileDB"); 73 1314 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/tiledb.html"); 74 1314 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES, 75 : "Byte UInt16 Int16 UInt32 Int32 Float32 " 76 1314 : "Float64 CInt16 CInt32 CFloat32 CFloat64"); 77 1314 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 78 1314 : poDriver->SetMetadataItem(GDAL_DCAP_MEASURED_GEOMETRIES, "YES"); 79 1314 : poDriver->SetMetadataItem(GDAL_DCAP_CURVE_GEOMETRIES, "YES"); 80 1314 : poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); 81 1314 : poDriver->SetMetadataItem(GDAL_DMD_SUBDATASETS, "YES"); 82 : 83 1314 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); 84 1314 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES"); 85 1314 : poDriver->SetMetadataItem( 86 : GDAL_DMD_CREATIONFIELDDATATYPES, 87 : "Integer Integer64 Real String Date Time DateTime " 88 1314 : "IntegerList Integer64List RealList Binary"); 89 1314 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATASUBTYPES, 90 1314 : "Boolean Int16 Float32"); 91 1314 : poDriver->SetMetadataItem( 92 : GDAL_DMD_CREATIONOPTIONLIST, 93 : "<CreationOptionList>\n" 94 : " <Option name='COMPRESSION' scope='raster' type='string-select' " 95 : "description='image " 96 : "compression to use' default='NONE'>\n" 97 : " <Value>NONE</Value>\n" 98 : " <Value>GZIP</Value>\n" 99 : " <Value>ZSTD</Value>\n" 100 : " <Value>LZ4</Value>\n" 101 : " <Value>RLE</Value>\n" 102 : " <Value>BZIP2</Value>\n" 103 : " <Value>DOUBLE-DELTA</Value>\n" 104 : " <Value>POSITIVE-DELTA</Value>\n" 105 : " </Option>\n" 106 : " <Option name='COMPRESSION_LEVEL' scope='raster' type='int' " 107 : "description='Compression level'/>\n" 108 : " <Option name='BLOCKXSIZE' scope='raster' type='int' " 109 : "description='Tile Width'/>" 110 : " <Option name='BLOCKYSIZE' scope='raster' type='int' " 111 : "description='Tile Height'/>" 112 : " <Option name='STATS' scope='raster' type='boolean' default='false' " 113 : "description='Dump TileDB stats'/>" 114 : " <Option name='TILEDB_CONFIG' type='string' " 115 : "description='location " 116 : "of configuration file for TileDB'/>" 117 : " <Option name='TILEDB_ATTRIBUTE' scope='raster' type='string' " 118 : "description='co-registered file to add as TileDB attributes, only " 119 : "applicable for interleave types of band or pixel'/>" 120 : " <Option name='INTERLEAVE' scope='raster' type='string-select' " 121 : "description='Indexing order' default='BAND'>\n" 122 : " <Value>BAND</Value>\n" 123 : " <Value>PIXEL</Value>\n" 124 : " <Value>ATTRIBUTES</Value>\n" 125 : " </Option>\n" 126 : " <Option name='TILEDB_TIMESTAMP' scope='raster' type='int' " 127 : "description='Create " 128 : "array at this timestamp, the timestamp should be > 0'/>\n" 129 : " <Option name='CREATE_GROUP' type='boolean' " 130 : "description='Whether to create a group for multiple vector layer " 131 : "support (defaults to NO), or raster with overviews " 132 : "(defaults to YES)'/>" 133 1314 : "</CreationOptionList>\n"); 134 : 135 : // clang-format off 136 1314 : poDriver->SetMetadataItem( 137 : GDAL_DMD_OPENOPTIONLIST, 138 : "<OpenOptionList>" 139 : " <Option name='STATS' scope='raster' type='boolean' default='false' " 140 : "description='Dump TileDB stats'/>" 141 : " <Option name='TILEDB_ATTRIBUTE' scope='raster' type='string' " 142 : "description='Attribute to read from each band'/>" 143 : " <Option name='TILEDB_CONFIG' type='string' description='location " 144 : "of configuration file for TileDB'/>" 145 : " <Option name='TILEDB_TIMESTAMP' type='int' description='Open array " 146 : "at this timestamp, the timestamp should be > 0'/>" 147 : " <Option name='BATCH_SIZE' scope='vector' type='int' default='" 148 : STRINGIFY(DEFAULT_BATCH_SIZE) "' " 149 : "description='Number of features to fetch/write at once'/>" 150 : " <Option name='DIM_X' type='string' scope='vector' default='_X' " 151 : "description='Name of the X dimension.'/>" 152 : " <Option name='DIM_Y' type='string' scope='vector' default='_Y' " 153 : "description='Name of the Y dimension.'/>" 154 : " <Option name='DIM_Z' type='string' scope='vector' default='_Z' " 155 : "description='Name of the Z dimension.'/>" 156 1314 : "</OpenOptionList>"); 157 : // clang-format on 158 : 159 : // clang-format off 160 1314 : poDriver->SetMetadataItem( 161 : GDAL_DS_LAYER_CREATIONOPTIONLIST, 162 : "<LayerCreationOptionList>" 163 : " <Option name='COMPRESSION' type='string-select' description='" 164 : "Compression to use' default='NONE'>\n" 165 : " <Value>NONE</Value>\n" 166 : " <Value>GZIP</Value>\n" 167 : " <Value>ZSTD</Value>\n" 168 : " <Value>LZ4</Value>\n" 169 : " <Value>RLE</Value>\n" 170 : " <Value>BZIP2</Value>\n" 171 : " <Value>DOUBLE-DELTA</Value>\n" 172 : " <Value>POSITIVE-DELTA</Value>\n" 173 : " </Option>\n" 174 : " <Option name='COMPRESSION_LEVEL' type='int' " 175 : "description='Compression level'/>\n" 176 : " <Option name='BATCH_SIZE' type='int' default='" 177 : STRINGIFY(DEFAULT_BATCH_SIZE) "' " 178 : "description='Number of features to write at once'/>" 179 : " <Option name='TILE_CAPACITY' type='int' default='" 180 : STRINGIFY(DEFAULT_TILE_CAPACITY) "' " 181 : "description='Number of non-empty cells stored in a data tile'/>" 182 : " <Option name='BOUNDS' type='string' description='Specify " 183 : "bounds for sparse array, minx, miny, [minz,] maxx, maxy [, maxz]'/>\n" 184 : " <Option name='TILE_EXTENT' type='float' description='Specify " 185 : "square X/Y tile extents for a sparse array'/>\n" 186 : " <Option name='TILE_Z_EXTENT' type='float' description='Specify " 187 : "Z tile extents for a sparse array'/>\n" 188 : " <Option name='ADD_Z_DIM' type='string-select' description='" 189 : "Whether to add a Z dimension' default='AUTO'>" 190 : " <Value>AUTO</Value>" 191 : " <Value>YES</Value>" 192 : " <Value>NO</Value>" 193 : " </Option>" 194 : " <Option name='FID' type='string' description='Feature id column " 195 : "name. Set to empty to disable its creation.' default='FID'/>" 196 : " <Option name='GEOMETRY_NAME' type='string' description='Name " 197 : "of the geometry column that will receive WKB encoded geometries. " 198 : "Set to empty to disable its creation (only for point).' " 199 : "default='wkb_geometry'/>" 200 : " <Option name='TILEDB_TIMESTAMP' type='int' description='Create " 201 : "array at this timestamp, the timestamp should be > 0'/>" 202 : " <Option name='TILEDB_STRING_TYPE' type='string-select' " 203 : "description='Which TileDB type to create string attributes' " 204 : "default='UTF8'" 205 : ">" 206 : " <Value>UTF8</Value>" 207 : " <Value>ASCII</Value>" 208 : " </Option>" 209 : " <Option name='STATS' type='boolean' default='false' " 210 : "description='Dump TileDB stats'/>" 211 1314 : "</LayerCreationOptionList>"); 212 : // clang-format on 213 : 214 1314 : poDriver->SetMetadataItem(GDAL_DCAP_MULTIDIM_RASTER, "YES"); 215 1314 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_MULTIDIMENSIONAL, "YES"); 216 : 217 1314 : poDriver->SetMetadataItem( 218 : GDAL_DMD_MULTIDIM_DATASET_CREATIONOPTIONLIST, 219 : "<MultiDimDatasetCreationOptionList>" 220 : " <Option name='TILEDB_CONFIG' type='string' description='location " 221 : "of configuration file for TileDB'/>" 222 : " <Option name='TILEDB_TIMESTAMP' type='int' description='Create " 223 : "arrays at this timestamp, the timestamp should be > 0'/>" 224 : " <Option name='STATS' type='boolean' default='false' " 225 : "description='Dump TileDB stats'/>" 226 1314 : "</MultiDimDatasetCreationOptionList>"); 227 : 228 1314 : poDriver->SetMetadataItem( 229 : GDAL_DMD_MULTIDIM_ARRAY_OPENOPTIONLIST, 230 : "<MultiDimArrayOpenOptionList>" 231 : " <Option name='TILEDB_TIMESTAMP' type='int' description='Open " 232 : "array at this timestamp, the timestamp should be > 0'/>" 233 1314 : "</MultiDimArrayOpenOptionList>"); 234 : 235 1314 : poDriver->SetMetadataItem( 236 : GDAL_DMD_MULTIDIM_ARRAY_CREATIONOPTIONLIST, 237 : "<MultiDimArrayCreationOptionList>" 238 : " <Option name='TILEDB_TIMESTAMP' type='int' description='Create " 239 : "array at this timestamp, the timestamp should be > 0'/>" 240 : " <Option name='BLOCKSIZE' type='int' description='Block size in " 241 : "pixels'/>" 242 : " <Option name='COMPRESSION' type='string-select' description='" 243 : "Compression to use' default='NONE'>\n" 244 : " <Value>NONE</Value>\n" 245 : " <Value>GZIP</Value>\n" 246 : " <Value>ZSTD</Value>\n" 247 : " <Value>LZ4</Value>\n" 248 : " <Value>RLE</Value>\n" 249 : " <Value>BZIP2</Value>\n" 250 : " <Value>DOUBLE-DELTA</Value>\n" 251 : " <Value>POSITIVE-DELTA</Value>\n" 252 : " </Option>\n" 253 : " <Option name='COMPRESSION_LEVEL' type='int' " 254 : "description='Compression level'/>\n" 255 : " <Option name='STATS' type='boolean' default='false' " 256 : "description='Dump TileDB stats'/>" 257 : " <Option name='IN_MEMORY' type='boolean' default='false' " 258 : "description='Whether the array should be only in-memory. Useful to " 259 : "create an indexing variable that is serialized as a dimension label'/>" 260 1314 : "</MultiDimArrayCreationOptionList>"); 261 : 262 1314 : poDriver->pfnIdentify = TileDBDriverIdentifySimplified; 263 1314 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 264 1314 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE, "YES"); 265 1314 : poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES"); 266 : 267 1314 : poDriver->SetMetadataItem( 268 : "TILEDB_VERSION", 269 : STRINGIFY(TILEDB_VERSION_MAJOR) "." STRINGIFY( 270 1314 : TILEDB_VERSION_MINOR) "." STRINGIFY(TILEDB_VERSION_PATCH)); 271 1314 : } 272 : 273 : /************************************************************************/ 274 : /* DeclareDeferredTileDBPlugin() */ 275 : /************************************************************************/ 276 : 277 : #ifdef PLUGIN_FILENAME 278 1595 : void DeclareDeferredTileDBPlugin() 279 : { 280 1595 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 281 : { 282 302 : return; 283 : } 284 1293 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 285 : #ifdef PLUGIN_INSTALLATION_MESSAGE 286 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 287 : PLUGIN_INSTALLATION_MESSAGE); 288 : #endif 289 1293 : TileDBDriverSetCommonMetadata(poDriver); 290 1293 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 291 : } 292 : #endif