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 : * Permission is hereby granted, free of charge, to any person 11 : * obtaining a copy of this software and associated documentation 12 : * files (the "Software"), to deal in the Software without 13 : * restriction, including without limitation the rights to use, copy, 14 : * modify, merge, publish, distribute, sublicense, and/or sell copies 15 : * of the Software, and to permit persons to whom the Software is 16 : * furnished to do so, subject to the following conditions: 17 : * 18 : * The above copyright notice and this permission notice shall be 19 : * included in all copies or substantial portions of the Software. 20 : * 21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 : * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 : * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 : * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 : * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 : * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 : * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 : * SOFTWARE. 29 : ****************************************************************************/ 30 : 31 : #include "ogrsf_frmts.h" 32 : 33 : #include "ogrvfkdrivercore.h" 34 : 35 : /************************************************************************/ 36 : /* OGRVFKDriverIdentify() */ 37 : /************************************************************************/ 38 : 39 42460 : int OGRVFKDriverIdentify(GDALOpenInfo *poOpenInfo) 40 : 41 : { 42 42460 : if (poOpenInfo->fpL == nullptr) 43 40172 : return FALSE; 44 : 45 2288 : if (poOpenInfo->nHeaderBytes >= 2 && 46 2226 : STARTS_WITH((const char *)poOpenInfo->pabyHeader, "&H")) 47 30 : return TRUE; 48 : 49 : /* valid datasource can be also SQLite DB previously created by 50 : VFK driver, the real check is done by VFKReaderSQLite */ 51 6534 : if (poOpenInfo->nHeaderBytes >= 100 && 52 2264 : STARTS_WITH((const char *)poOpenInfo->pabyHeader, "SQLite format 3") && 53 6 : !EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "gpkg")) 54 : { 55 : // The driver is not ready for virtual file systems 56 6 : if (STARTS_WITH(poOpenInfo->pszFilename, "/vsi")) 57 6 : return FALSE; 58 : 59 : VSIStatBufL sStat; 60 10 : if (VSIStatL(poOpenInfo->pszFilename, &sStat) == 0 && 61 5 : VSI_ISREG(sStat.st_mode)) 62 : { 63 5 : return GDAL_IDENTIFY_UNKNOWN; 64 : } 65 : } 66 : 67 2252 : return FALSE; 68 : } 69 : 70 : /************************************************************************/ 71 : /* OGRVFKDriverSetCommonMetadata() */ 72 : /************************************************************************/ 73 : 74 1227 : void OGRVFKDriverSetCommonMetadata(GDALDriver *poDriver) 75 : { 76 1227 : poDriver->SetDescription(DRIVER_NAME); 77 1227 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 78 1227 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, 79 1227 : "Czech Cadastral Exchange Data Format"); 80 1227 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "vfk"); 81 1227 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/vfk.html"); 82 1227 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE"); 83 : 84 1227 : poDriver->SetMetadataItem( 85 : GDAL_DMD_OPENOPTIONLIST, 86 : "<OpenOptionList>" 87 : " <Option name='SUPPRESS_GEOMETRY' type='boolean' " 88 : "description='whether to suppress geometry' default='NO'/>" 89 : " <Option name='FILE_FIELD' type='boolean' description='whether to " 90 : "include VFK filename field' default='NO'/>" 91 1227 : "</OpenOptionList>"); 92 : 93 1227 : poDriver->pfnIdentify = OGRVFKDriverIdentify; 94 1227 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 95 1227 : } 96 : 97 : /************************************************************************/ 98 : /* DeclareDeferredOGRVFKPlugin() */ 99 : /************************************************************************/ 100 : 101 : #ifdef PLUGIN_FILENAME 102 1520 : void DeclareDeferredOGRVFKPlugin() 103 : { 104 1520 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 105 : { 106 301 : return; 107 : } 108 1219 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 109 : #ifdef PLUGIN_INSTALLATION_MESSAGE 110 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 111 : PLUGIN_INSTALLATION_MESSAGE); 112 : #endif 113 1219 : OGRVFKDriverSetCommonMetadata(poDriver); 114 1219 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 115 : } 116 : #endif