LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/geojson - ogrtopojsondriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 30 32 93.8 %
Date: 2024-05-03 15:49:35 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  TopoJSON driver
       5             :  * Author:   Even Rouault, <even.rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2017, Even Rouault, <even.rouault at spatialys.com>
       9             :  *
      10             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : #include "cpl_port.h"
      30             : #include "ogr_geojson.h"
      31             : 
      32             : #include <stdlib.h>
      33             : #include <string.h>
      34             : 
      35             : #include "cpl_conv.h"
      36             : #include "cpl_error.h"
      37             : #include "gdal.h"
      38             : #include "gdal_priv.h"
      39             : #include "ogrgeojsonutils.h"
      40             : #include "ogrsf_frmts.h"
      41             : 
      42             : /************************************************************************/
      43             : /*                       OGRTopoJSONDriverIdentify()                    */
      44             : /************************************************************************/
      45             : 
      46       44264 : static int OGRTopoJSONDriverIdentify(GDALOpenInfo *poOpenInfo)
      47             : {
      48       44264 :     GeoJSONSourceType nSrcType = TopoJSONDriverGetSourceType(poOpenInfo);
      49       44263 :     if (nSrcType == eGeoJSONSourceUnknown)
      50       44251 :         return FALSE;
      51          12 :     if (nSrcType == eGeoJSONSourceService &&
      52           9 :         !STARTS_WITH_CI(poOpenInfo->pszFilename, "TopoJSON:"))
      53             :     {
      54           9 :         return -1;
      55             :     }
      56           3 :     return TRUE;
      57             : }
      58             : 
      59             : /************************************************************************/
      60             : /*                           Open()                                     */
      61             : /************************************************************************/
      62             : 
      63           4 : static GDALDataset *OGRTopoJSONDriverOpen(GDALOpenInfo *poOpenInfo)
      64             : {
      65           4 :     GeoJSONSourceType nSrcType = TopoJSONDriverGetSourceType(poOpenInfo);
      66           4 :     if (nSrcType == eGeoJSONSourceUnknown)
      67           0 :         return nullptr;
      68           4 :     return OGRGeoJSONDriverOpenInternal(poOpenInfo, nSrcType, "TopoJSON");
      69             : }
      70             : 
      71             : /************************************************************************/
      72             : /*                          RegisterOGRTopoJSON()                       */
      73             : /************************************************************************/
      74             : 
      75        1511 : void RegisterOGRTopoJSON()
      76             : {
      77        1511 :     if (!GDAL_CHECK_VERSION("OGR/TopoJSON driver"))
      78           0 :         return;
      79             : 
      80        1511 :     if (GDALGetDriverByName("TopoJSON") != nullptr)
      81         295 :         return;
      82             : 
      83        1216 :     GDALDriver *poDriver = new GDALDriver();
      84             : 
      85        1216 :     poDriver->SetDescription("TopoJSON");
      86        1216 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
      87        1216 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "TopoJSON");
      88        1216 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "json topojson");
      89        1216 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC,
      90        1216 :                               "drivers/vector/topojson.html");
      91             : 
      92        1216 :     poDriver->SetMetadataItem(GDAL_DMD_OPENOPTIONLIST, "<OpenOptionList/>");
      93             : 
      94        1216 :     poDriver->SetMetadataItem(GDAL_DMD_CREATIONOPTIONLIST,
      95        1216 :                               "<CreationOptionList/>");
      96             : 
      97        1216 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
      98             : 
      99        1216 :     poDriver->pfnOpen = OGRTopoJSONDriverOpen;
     100        1216 :     poDriver->pfnIdentify = OGRTopoJSONDriverIdentify;
     101             : 
     102        1216 :     GetGDALDriverManager()->RegisterDriver(poDriver);
     103             : }

Generated by: LCOV version 1.14