LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/sxf - ogrsxfdriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 35 47 74.5 %
Date: 2024-11-21 22:18:42 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  SXF Translator
       4             :  * Purpose:  Definition of classes for OGR SXF driver.
       5             :  * Author:   Ben Ahmed Daho Ali, bidandou(at)yahoo(dot)fr
       6             :  *           Dmitry Baryshnikov, polimax@mail.ru
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2011, Ben Ahmed Daho Ali
      10             :  * Copyright (c) 2013, NextGIS
      11             :  * Copyright (c) 2014, Even Rouault <even dot rouault at spatialys.com>
      12             :  *
      13             :  * SPDX-License-Identifier: MIT
      14             :  ****************************************************************************/
      15             : 
      16             : #include "cpl_conv.h"
      17             : #include "ogr_sxf.h"
      18             : 
      19             : /************************************************************************/
      20             : /*                                Open()                                */
      21             : /************************************************************************/
      22             : 
      23           6 : static GDALDataset *OGRSXFDriverOpen(GDALOpenInfo *poOpenInfo)
      24             : 
      25             : {
      26             :     /* -------------------------------------------------------------------- */
      27             :     /*      Determine what sort of object this is.                          */
      28             :     /* -------------------------------------------------------------------- */
      29             : 
      30             :     VSIStatBufL sStatBuf;
      31           6 :     if (!EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "sxf") ||
      32          12 :         VSIStatL(poOpenInfo->pszFilename, &sStatBuf) != 0 ||
      33           6 :         !VSI_ISREG(sStatBuf.st_mode))
      34           0 :         return nullptr;
      35             : 
      36           6 :     OGRSXFDataSource *poDS = new OGRSXFDataSource();
      37             : 
      38           6 :     if (!poDS->Open(poOpenInfo->pszFilename, poOpenInfo->eAccess == GA_Update,
      39           6 :                     poOpenInfo->papszOpenOptions))
      40             :     {
      41           1 :         delete poDS;
      42           1 :         poDS = nullptr;
      43             :     }
      44             : 
      45           6 :     return poDS;
      46             : }
      47             : 
      48             : /************************************************************************/
      49             : /*                              Identify()                              */
      50             : /************************************************************************/
      51             : 
      52       45060 : static int OGRSXFDriverIdentify(GDALOpenInfo *poOpenInfo)
      53             : {
      54       45060 :     if (!EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "sxf") ||
      55       45060 :         !poOpenInfo->bStatOK || poOpenInfo->bIsDirectory)
      56             :     {
      57       45054 :         return GDAL_IDENTIFY_FALSE;
      58             :     }
      59             : 
      60           6 :     if (poOpenInfo->nHeaderBytes < 4)
      61             :     {
      62           0 :         return GDAL_IDENTIFY_UNKNOWN;
      63             :     }
      64             : 
      65           6 :     if (0 != memcmp(poOpenInfo->pabyHeader, "SXF", 3))
      66             :     {
      67           0 :         return GDAL_IDENTIFY_FALSE;
      68             :     }
      69             : 
      70           6 :     return GDAL_IDENTIFY_TRUE;
      71             : }
      72             : 
      73             : /************************************************************************/
      74             : /*                          GRSXFDriverDelete()                         */
      75             : /************************************************************************/
      76             : 
      77           0 : static CPLErr OGRSXFDriverDelete(const char *pszName)
      78             : {
      79             :     // TODO: add more extensions if aplicable
      80             :     static const char *const apszExtensions[] = {"szf", "rsc", "SZF", "RSC",
      81             :                                                  nullptr};
      82             : 
      83             :     VSIStatBufL sStatBuf;
      84           0 :     if (VSIStatL(pszName, &sStatBuf) != 0)
      85             :     {
      86           0 :         CPLError(CE_Failure, CPLE_AppDefined,
      87             :                  "%s does not appear to be a valid sxf file.", pszName);
      88             : 
      89           0 :         return CE_Failure;
      90             :     }
      91             : 
      92           0 :     for (int iExt = 0; apszExtensions[iExt] != nullptr; iExt++)
      93             :     {
      94           0 :         const char *pszFile = CPLResetExtension(pszName, apszExtensions[iExt]);
      95           0 :         if (VSIStatL(pszFile, &sStatBuf) == 0)
      96           0 :             VSIUnlink(pszFile);
      97             :     }
      98             : 
      99           0 :     return CE_None;
     100             : }
     101             : 
     102             : /************************************************************************/
     103             : /*                        RegisterOGRSXF()                       */
     104             : /************************************************************************/
     105        1595 : void RegisterOGRSXF()
     106             : {
     107        1595 :     if (GDALGetDriverByName("SXF") != nullptr)
     108         302 :         return;
     109             : 
     110        1293 :     GDALDriver *poDriver = new GDALDriver();
     111             : 
     112        1293 :     poDriver->SetDescription("SXF");
     113        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
     114        1293 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Storage and eXchange Format");
     115        1293 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/sxf.html");
     116        1293 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "sxf");
     117        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
     118        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES");
     119        1293 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE");
     120        1293 :     poDriver->SetMetadataItem(
     121             :         GDAL_DMD_OPENOPTIONLIST,
     122             :         "<OpenOptionList>"
     123             :         "  <Option name='SXF_LAYER_FULLNAME' type='string' description='Use "
     124             :         "long layer names' default='NO'/>"
     125             :         "  <Option name='SXF_RSC_FILENAME' type='string' description='RSC file "
     126             :         "name' default=''/>"
     127             :         "  <Option name='SXF_SET_VERTCS' type='string' description='Layers "
     128             :         "spatial reference will include vertical coordinate system description "
     129             :         "if exist' default='NO'/>"
     130        1293 :         "</OpenOptionList>");
     131             : 
     132        1293 :     poDriver->pfnOpen = OGRSXFDriverOpen;
     133        1293 :     poDriver->pfnDelete = OGRSXFDriverDelete;
     134        1293 :     poDriver->pfnIdentify = OGRSXFDriverIdentify;
     135             : 
     136        1293 :     GetGDALDriverManager()->RegisterDriver(poDriver);
     137             : }

Generated by: LCOV version 1.14