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: 2025-01-18 12:42:00 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 (!poOpenInfo->IsExtensionEqualToCI("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       45520 : static int OGRSXFDriverIdentify(GDALOpenInfo *poOpenInfo)
      53             : {
      54       45526 :     if (!poOpenInfo->IsExtensionEqualToCI("sxf") || !poOpenInfo->bStatOK ||
      55           6 :         poOpenInfo->bIsDirectory)
      56             :     {
      57       45514 :         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             :         const std::string osFile =
      95           0 :             CPLResetExtensionSafe(pszName, apszExtensions[iExt]);
      96           0 :         if (VSIStatL(osFile.c_str(), &sStatBuf) == 0)
      97           0 :             VSIUnlink(osFile.c_str());
      98             :     }
      99             : 
     100           0 :     return CE_None;
     101             : }
     102             : 
     103             : /************************************************************************/
     104             : /*                        RegisterOGRSXF()                       */
     105             : /************************************************************************/
     106        1682 : void RegisterOGRSXF()
     107             : {
     108        1682 :     if (GDALGetDriverByName("SXF") != nullptr)
     109         301 :         return;
     110             : 
     111        1381 :     GDALDriver *poDriver = new GDALDriver();
     112             : 
     113        1381 :     poDriver->SetDescription("SXF");
     114        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
     115        1381 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Storage and eXchange Format");
     116        1381 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/sxf.html");
     117        1381 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "sxf");
     118        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
     119        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES");
     120        1381 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE");
     121        1381 :     poDriver->SetMetadataItem(
     122             :         GDAL_DMD_OPENOPTIONLIST,
     123             :         "<OpenOptionList>"
     124             :         "  <Option name='SXF_LAYER_FULLNAME' type='string' description='Use "
     125             :         "long layer names' default='NO'/>"
     126             :         "  <Option name='SXF_RSC_FILENAME' type='string' description='RSC file "
     127             :         "name' default=''/>"
     128             :         "  <Option name='SXF_SET_VERTCS' type='string' description='Layers "
     129             :         "spatial reference will include vertical coordinate system description "
     130             :         "if exist' default='NO'/>"
     131        1381 :         "</OpenOptionList>");
     132             : 
     133        1381 :     poDriver->pfnOpen = OGRSXFDriverOpen;
     134        1381 :     poDriver->pfnDelete = OGRSXFDriverDelete;
     135        1381 :     poDriver->pfnIdentify = OGRSXFDriverIdentify;
     136             : 
     137        1381 :     GetGDALDriverManager()->RegisterDriver(poDriver);
     138             : }

Generated by: LCOV version 1.14