Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OpenGIS Simple Features Reference Implementation 4 : * Purpose: Implements OGRVFKDriver class. 5 : * Author: Martin Landa, landa.martin gmail.com 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2009-2018, Martin Landa <landa.martin gmail.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "ogrsf_frmts.h" 14 : 15 : #include "ogrvfkdrivercore.h" 16 : 17 : /************************************************************************/ 18 : /* OGRVFKDriverIdentify() */ 19 : /************************************************************************/ 20 : 21 45944 : int OGRVFKDriverIdentify(GDALOpenInfo *poOpenInfo) 22 : 23 : { 24 45944 : if (poOpenInfo->fpL == nullptr) 25 43317 : return FALSE; 26 : 27 2627 : if (poOpenInfo->nHeaderBytes >= 2 && 28 2558 : STARTS_WITH((const char *)poOpenInfo->pabyHeader, "&H")) 29 30 : return TRUE; 30 : 31 : /* valid datasource can be also SQLite DB previously created by 32 : VFK driver, the real check is done by VFKReaderSQLite */ 33 7506 : if (poOpenInfo->nHeaderBytes >= 100 && 34 2634 : STARTS_WITH((const char *)poOpenInfo->pabyHeader, "SQLite format 3") && 35 37 : !poOpenInfo->IsExtensionEqualToCI("gpkg")) 36 : { 37 : // The driver is not ready for virtual file systems 38 6 : if (STARTS_WITH(poOpenInfo->pszFilename, "/vsi")) 39 6 : return FALSE; 40 : 41 : VSIStatBufL sStat; 42 10 : if (VSIStatL(poOpenInfo->pszFilename, &sStat) == 0 && 43 5 : VSI_ISREG(sStat.st_mode)) 44 : { 45 5 : return GDAL_IDENTIFY_UNKNOWN; 46 : } 47 : } 48 : 49 2591 : return FALSE; 50 : } 51 : 52 : /************************************************************************/ 53 : /* OGRVFKDriverSetCommonMetadata() */ 54 : /************************************************************************/ 55 : 56 1391 : void OGRVFKDriverSetCommonMetadata(GDALDriver *poDriver) 57 : { 58 1391 : poDriver->SetDescription(DRIVER_NAME); 59 1391 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 60 1391 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, 61 1391 : "Czech Cadastral Exchange Data Format"); 62 1391 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "vfk"); 63 1391 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/vfk.html"); 64 1391 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE"); 65 : 66 1391 : poDriver->SetMetadataItem( 67 : GDAL_DMD_OPENOPTIONLIST, 68 : "<OpenOptionList>" 69 : " <Option name='SUPPRESS_GEOMETRY' type='boolean' " 70 : "description='whether to suppress geometry' default='NO'/>" 71 : " <Option name='FILE_FIELD' type='boolean' description='whether to " 72 : "include VFK filename field' default='NO'/>" 73 1391 : "</OpenOptionList>"); 74 : 75 1391 : poDriver->pfnIdentify = OGRVFKDriverIdentify; 76 1391 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 77 1391 : } 78 : 79 : /************************************************************************/ 80 : /* DeclareDeferredOGRVFKPlugin() */ 81 : /************************************************************************/ 82 : 83 : #ifdef PLUGIN_FILENAME 84 1682 : void DeclareDeferredOGRVFKPlugin() 85 : { 86 1682 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 87 : { 88 301 : return; 89 : } 90 1381 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 91 : #ifdef PLUGIN_INSTALLATION_MESSAGE 92 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 93 : PLUGIN_INSTALLATION_MESSAGE); 94 : #endif 95 1381 : OGRVFKDriverSetCommonMetadata(poDriver); 96 1381 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 97 : } 98 : #endif