LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/vfk - ogrvfkdrivercore.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 34 34 100.0 %
Date: 2024-11-21 22:18:42 Functions: 5 5 100.0 %

          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       45484 : int OGRVFKDriverIdentify(GDALOpenInfo *poOpenInfo)
      22             : 
      23             : {
      24       45484 :     if (poOpenInfo->fpL == nullptr)
      25       42858 :         return FALSE;
      26             : 
      27        2626 :     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        7504 :     if (poOpenInfo->nHeaderBytes >= 100 &&
      34        2633 :         STARTS_WITH((const char *)poOpenInfo->pabyHeader, "SQLite format 3") &&
      35          37 :         !EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "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        2590 :     return FALSE;
      50             : }
      51             : 
      52             : /************************************************************************/
      53             : /*                  OGRVFKDriverSetCommonMetadata()                  */
      54             : /************************************************************************/
      55             : 
      56        1303 : void OGRVFKDriverSetCommonMetadata(GDALDriver *poDriver)
      57             : {
      58        1303 :     poDriver->SetDescription(DRIVER_NAME);
      59        1303 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
      60        1303 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME,
      61        1303 :                               "Czech Cadastral Exchange Data Format");
      62        1303 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "vfk");
      63        1303 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/vfk.html");
      64        1303 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE");
      65             : 
      66        1303 :     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        1303 :         "</OpenOptionList>");
      74             : 
      75        1303 :     poDriver->pfnIdentify = OGRVFKDriverIdentify;
      76        1303 :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
      77        1303 : }
      78             : 
      79             : /************************************************************************/
      80             : /*                   DeclareDeferredOGRVFKPlugin()                      */
      81             : /************************************************************************/
      82             : 
      83             : #ifdef PLUGIN_FILENAME
      84        1595 : void DeclareDeferredOGRVFKPlugin()
      85             : {
      86        1595 :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
      87             :     {
      88         302 :         return;
      89             :     }
      90        1293 :     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        1293 :     OGRVFKDriverSetCommonMetadata(poDriver);
      96        1293 :     GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
      97             : }
      98             : #endif

Generated by: LCOV version 1.14