LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/gmt - ogrgmtdriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 35 36 97.2 %
Date: 2024-11-21 22:18:42 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  Implements OGRGmtDriver class.
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2007, Frank Warmerdam <warmerdam@pobox.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "ogr_gmt.h"
      14             : #include "cpl_conv.h"
      15             : #include "cpl_string.h"
      16             : 
      17             : /************************************************************************/
      18             : /*                    OGRGMTDriverIdentify()                            */
      19             : /************************************************************************/
      20             : 
      21       47372 : static int OGRGMTDriverIdentify(GDALOpenInfo *poOpenInfo)
      22             : 
      23             : {
      24       47372 :     const char *pszHeader =
      25             :         reinterpret_cast<const char *>(poOpenInfo->pabyHeader);
      26       47372 :     if (poOpenInfo->nHeaderBytes && strstr(pszHeader, "@VGMT") != nullptr)
      27          72 :         return true;
      28             : 
      29       47300 :     if (EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "GMT"))
      30         108 :         return true;
      31             : 
      32       47192 :     return false;
      33             : }
      34             : 
      35             : /************************************************************************/
      36             : /*                           OGRGMTDriverOpen()                         */
      37             : /************************************************************************/
      38             : 
      39          72 : static GDALDataset *OGRGMTDriverOpen(GDALOpenInfo *poOpenInfo)
      40             : 
      41             : {
      42          72 :     if (!OGRGMTDriverIdentify(poOpenInfo))
      43           0 :         return nullptr;
      44             : 
      45          72 :     OGRGmtDataSource *poDS = new OGRGmtDataSource();
      46             : 
      47          72 :     if (!poDS->Open(poOpenInfo->pszFilename, nullptr, nullptr,
      48          72 :                     poOpenInfo->eAccess == GA_Update))
      49             :     {
      50          35 :         delete poDS;
      51          35 :         return nullptr;
      52             :     }
      53             : 
      54          37 :     return poDS;
      55             : }
      56             : 
      57             : /************************************************************************/
      58             : /*                         OGRGMTDriverCreate()                         */
      59             : /************************************************************************/
      60             : 
      61          36 : static GDALDataset *OGRGMTDriverCreate(const char *, CPL_UNUSED int nBands,
      62             :                                        CPL_UNUSED int nXSize,
      63             :                                        CPL_UNUSED int nYSize,
      64             :                                        CPL_UNUSED GDALDataType eDT, char **)
      65             : {
      66          36 :     return new OGRGmtDataSource();
      67             : }
      68             : 
      69             : /************************************************************************/
      70             : /*                           RegisterOGRGMT()                           */
      71             : /************************************************************************/
      72             : 
      73        1595 : void RegisterOGRGMT()
      74             : 
      75             : {
      76        1595 :     if (GDALGetDriverByName("OGR_GMT") != nullptr)
      77         302 :         return;
      78             : 
      79        1293 :     GDALDriver *poDriver = new GDALDriver();
      80        1293 :     poDriver->SetDescription("OGR_GMT");
      81        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
      82        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES");
      83        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES");
      84        1293 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "GMT ASCII Vectors (.gmt)");
      85        1293 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "gmt");
      86        1293 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/gmt.html");
      87        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
      88        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES");
      89        1293 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE");
      90             : 
      91        1293 :     poDriver->pfnOpen = OGRGMTDriverOpen;
      92        1293 :     poDriver->pfnIdentify = OGRGMTDriverIdentify;
      93        1293 :     poDriver->pfnCreate = OGRGMTDriverCreate;
      94             : 
      95        1293 :     GetGDALDriverManager()->RegisterDriver(poDriver);
      96             : }

Generated by: LCOV version 1.14