Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL Rasterlite driver 4 : * Purpose: Implement GDAL Rasterlite support using OGR SQLite driver 5 : * Author: Even Rouault, <even dot rouault at spatialys.com> 6 : * 7 : ********************************************************************** 8 : * Copyright (c) 2009-2013, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "rasterlitedrivercore.h" 14 : 15 : /************************************************************************/ 16 : /* RasterliteDriverIdentify() */ 17 : /************************************************************************/ 18 : 19 52562 : int RasterliteDriverIdentify(GDALOpenInfo *poOpenInfo) 20 : 21 : { 22 : #ifdef ENABLE_SQL_SQLITE_FORMAT 23 52562 : if (poOpenInfo->pabyHeader && 24 4417 : STARTS_WITH((const char *)poOpenInfo->pabyHeader, "-- SQL RASTERLITE")) 25 : { 26 2 : return TRUE; 27 : } 28 : #endif 29 : 30 52560 : if (!EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "MBTILES") && 31 52383 : !EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "GPKG") && 32 50701 : poOpenInfo->nHeaderBytes >= 1024 && poOpenInfo->pabyHeader && 33 2034 : STARTS_WITH_CI((const char *)poOpenInfo->pabyHeader, 34 104943 : "SQLite Format 3") && 35 : // Do not match direct Amazon S3 signed URLs that contains .mbtiles in 36 : // the middle of the URL 37 72 : strstr(poOpenInfo->pszFilename, ".mbtiles") == nullptr) 38 : { 39 : // Could be a SQLite/Spatialite file as well 40 72 : return -1; 41 : } 42 52488 : else if (STARTS_WITH_CI(poOpenInfo->pszFilename, "RASTERLITE:")) 43 : { 44 37 : return TRUE; 45 : } 46 : 47 52451 : return FALSE; 48 : } 49 : 50 : /************************************************************************/ 51 : /* RasterliteDriverSetCommonMetadata() */ 52 : /************************************************************************/ 53 : 54 1293 : void RasterliteDriverSetCommonMetadata(GDALDriver *poDriver) 55 : { 56 1293 : poDriver->SetDescription(DRIVER_NAME); 57 1293 : poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES"); 58 1293 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Rasterlite"); 59 1293 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, 60 1293 : "drivers/raster/rasterlite.html"); 61 1293 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "sqlite"); 62 1293 : poDriver->SetMetadataItem(GDAL_DMD_SUBDATASETS, "YES"); 63 1293 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES, 64 : "Byte UInt16 Int16 UInt32 Int32 Float32 " 65 1293 : "Float64 CInt16 CInt32 CFloat32 CFloat64"); 66 1293 : poDriver->SetMetadataItem( 67 : GDAL_DMD_CREATIONOPTIONLIST, 68 : "<CreationOptionList>" 69 : " <Option name='WIPE' type='boolean' default='NO' description='Erase " 70 : "all preexisting data in the specified table'/>" 71 : " <Option name='TILED' type='boolean' default='YES' description='Use " 72 : "tiling'/>" 73 : " <Option name='BLOCKXSIZE' type='int' default='256' " 74 : "description='Tile Width'/>" 75 : " <Option name='BLOCKYSIZE' type='int' default='256' " 76 : "description='Tile Height'/>" 77 : " <Option name='DRIVER' type='string' description='GDAL driver to " 78 : "use for storing tiles' default='GTiff'/>" 79 : " <Option name='COMPRESS' type='string' description='(GTiff driver) " 80 : "Compression method' default='NONE'/>" 81 : " <Option name='QUALITY' type='int' description='(JPEG-compressed " 82 : "GTiff, JPEG and WEBP drivers) JPEG/WEBP Quality 1-100' default='75'/>" 83 : " <Option name='PHOTOMETRIC' type='string-select' " 84 : "description='(GTiff driver) Photometric interpretation'>" 85 : " <Value>MINISBLACK</Value>" 86 : " <Value>MINISWHITE</Value>" 87 : " <Value>PALETTE</Value>" 88 : " <Value>RGB</Value>" 89 : " <Value>CMYK</Value>" 90 : " <Value>YCBCR</Value>" 91 : " <Value>CIELAB</Value>" 92 : " <Value>ICCLAB</Value>" 93 : " <Value>ITULAB</Value>" 94 : " </Option>" 95 1293 : "</CreationOptionList>"); 96 1293 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 97 : 98 : #ifdef ENABLE_SQL_SQLITE_FORMAT 99 1293 : poDriver->SetMetadataItem("ENABLE_SQL_SQLITE_FORMAT", "YES"); 100 : #endif 101 : 102 1293 : poDriver->pfnIdentify = RasterliteDriverIdentify; 103 1293 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 104 1293 : poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES"); 105 1293 : } 106 : 107 : /************************************************************************/ 108 : /* DeclareDeferredRasterlitePlugin() */ 109 : /************************************************************************/ 110 : 111 : #ifdef PLUGIN_FILENAME 112 : void DeclareDeferredRasterlitePlugin() 113 : { 114 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 115 : { 116 : return; 117 : } 118 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 119 : #ifdef PLUGIN_INSTALLATION_MESSAGE 120 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 121 : PLUGIN_INSTALLATION_MESSAGE); 122 : #endif 123 : RasterliteDriverSetCommonMetadata(poDriver); 124 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 125 : } 126 : #endif