LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/jsonfg - ogrjsonfgdriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 54 55 98.2 %
Date: 2025-10-21 22:35:35 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  Implementation of OGC Features and Geometries JSON (JSON-FG)
       5             :  * Author:   Even Rouault <even.rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2023, Even Rouault <even.rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "gdal_priv.h"
      14             : #include "ogrsf_frmts.h"
      15             : 
      16             : #include "ogr_jsonfg.h"
      17             : #include "ogrgeojsonutils.h"
      18             : 
      19             : /************************************************************************/
      20             : /*                       OGRJSONFGDriverIdentify()                      */
      21             : /************************************************************************/
      22             : 
      23       50858 : static int OGRJSONFGDriverIdentify(GDALOpenInfo *poOpenInfo)
      24             : {
      25       50858 :     GeoJSONSourceType nSrcType = JSONFGDriverGetSourceType(poOpenInfo);
      26       50858 :     if (nSrcType == eGeoJSONSourceUnknown)
      27       50636 :         return FALSE;
      28         222 :     if (nSrcType == eGeoJSONSourceService)
      29             :     {
      30          18 :         if (poOpenInfo->IsSingleAllowedDriver("JSONFG"))
      31           1 :             return TRUE;
      32          17 :         if (!STARTS_WITH_CI(poOpenInfo->pszFilename, "JSONFG:"))
      33             :         {
      34          17 :             return -1;
      35             :         }
      36             :     }
      37         204 :     return TRUE;
      38             : }
      39             : 
      40             : /************************************************************************/
      41             : /*                           Open()                                     */
      42             : /************************************************************************/
      43             : 
      44         211 : static GDALDataset *OGRJSONFGDriverOpen(GDALOpenInfo *poOpenInfo)
      45             : {
      46         211 :     GeoJSONSourceType nSrcType = JSONFGDriverGetSourceType(poOpenInfo);
      47         211 :     if (nSrcType == eGeoJSONSourceUnknown)
      48           0 :         return nullptr;
      49         422 :     auto poDS = std::make_unique<OGRJSONFGDataset>();
      50         211 :     if (!poDS->Open(poOpenInfo, nSrcType))
      51           9 :         return nullptr;
      52         202 :     return poDS.release();
      53             : }
      54             : 
      55             : /************************************************************************/
      56             : /*                               Create()                               */
      57             : /************************************************************************/
      58             : 
      59         106 : static GDALDataset *OGRJSONFGDriverCreate(const char *pszName, int /* nBands */,
      60             :                                           int /* nXSize */, int /* nYSize */,
      61             :                                           GDALDataType /* eDT */,
      62             :                                           char **papszOptions)
      63             : {
      64         212 :     auto poDS = std::make_unique<OGRJSONFGDataset>();
      65         106 :     if (!poDS->Create(pszName, papszOptions))
      66             :     {
      67           1 :         return nullptr;
      68             :     }
      69         105 :     return poDS.release();
      70             : }
      71             : 
      72             : /************************************************************************/
      73             : /*                           RegisterOGRJSONFG()                        */
      74             : /************************************************************************/
      75             : 
      76        2038 : void RegisterOGRJSONFG()
      77             : {
      78        2038 :     if (GDALGetDriverByName("JSONFG") != nullptr)
      79         283 :         return;
      80             : 
      81        1755 :     GDALDriver *poDriver = new GDALDriver();
      82             : 
      83        1755 :     poDriver->SetDescription("JSONFG");
      84        1755 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
      85        1755 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES");
      86        1755 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES");
      87        1755 :     poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES");
      88        1755 :     poDriver->SetMetadataItem(GDAL_DCAP_MEASURED_GEOMETRIES, "YES");
      89        1755 :     poDriver->SetMetadataItem(GDAL_DCAP_CURVE_GEOMETRIES, "YES");
      90        1755 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME,
      91        1755 :                               "OGC Features and Geometries JSON");
      92        1755 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "json");
      93        1755 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/jsonfg.html");
      94             : 
      95        1755 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
      96             : 
      97        1755 :     poDriver->SetMetadataItem(
      98             :         GDAL_DMD_OPENOPTIONLIST,
      99             :         "<OpenOptionList>"
     100             :         "  <Option name='GEOMETRY_ELEMENT' type='string-select' "
     101             :         "description='Which JSON element to use to create geometry from'>"
     102             :         "    <Value>AUTO</Value>"
     103             :         "    <Value>PLACE</Value>"
     104             :         "    <Value>GEOMETRY</Value>"
     105             :         "  </Option>"
     106        1755 :         "</OpenOptionList>");
     107             : 
     108        1755 :     poDriver->SetMetadataItem(
     109             :         GDAL_DMD_CREATIONOPTIONLIST,
     110             :         "<CreationOptionList>"
     111             :         "  <Option name='SINGLE_LAYER' type='boolean' description='whether "
     112             :         "only one layer will be written' default='NO'/>"
     113        1755 :         "</CreationOptionList>");
     114             : 
     115        1755 :     poDriver->SetMetadataItem(
     116             :         GDAL_DS_LAYER_CREATIONOPTIONLIST,
     117             :         "<LayerCreationOptionList>"
     118             :         "  <Option name='COORDINATE_PRECISION_GEOMETRY' type='int' "
     119             :         "description='Number of decimal for coordinates in the geometry "
     120             :         "element'/>"
     121             :         "  <Option name='COORDINATE_PRECISION_PLACE' type='int' "
     122             :         "description='Number of decimal for coordinates in the place element'/>"
     123             :         "  <Option name='WRITE_GEOMETRY' type='boolean' "
     124             :         "description='Can be set to NO to avoid writing the geometry element "
     125             :         "when place is written' default='YES'/>"
     126             :         "  <Option name='SIGNIFICANT_FIGURES' type='int' description='Number "
     127             :         "of significant figures for floating-point values' default='17'/>"
     128             :         "  <Option name='ID_FIELD' type='string' description='Name of the "
     129             :         "source field that must be used as the id member of Feature features'/>"
     130             :         "  <Option name='ID_TYPE' type='string-select' description='Type of "
     131             :         "the id member of Feature features'>"
     132             :         "    <Value>AUTO</Value>"
     133             :         "    <Value>String</Value>"
     134             :         "    <Value>Integer</Value>"
     135             :         "  </Option>"
     136             :         "  <Option name='ID_GENERATE' type='boolean' "
     137             :         "description='Auto-generate feature ids' default='NO'/>"
     138             :         "  <Option name='MEASURE_UNIT' type='string' "
     139             :         "description='Unit of measures (M) values'/>"
     140             :         "  <Option name='MEASURE_DESCRIPTION' type='string' "
     141             :         "description='Description of measures (M) values'/>"
     142        1755 :         "</LayerCreationOptionList>");
     143             : 
     144        1755 :     poDriver->SetMetadataItem(
     145             :         GDAL_DMD_CREATIONFIELDDATATYPES,
     146             :         "Integer Integer64 Real String IntegerList "
     147        1755 :         "Integer64List RealList StringList Date DateTime");
     148        1755 :     poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATASUBTYPES, "Boolean");
     149        1755 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE");
     150        1755 :     poDriver->SetMetadataItem(GDAL_DCAP_FLUSHCACHE_CONSISTENT_STATE, "YES");
     151        1755 :     poDriver->SetMetadataItem(GDAL_DCAP_HONOR_GEOM_COORDINATE_PRECISION, "YES");
     152             : 
     153        1755 :     poDriver->pfnOpen = OGRJSONFGDriverOpen;
     154        1755 :     poDriver->pfnIdentify = OGRJSONFGDriverIdentify;
     155        1755 :     poDriver->pfnCreate = OGRJSONFGDriverCreate;
     156             : 
     157        1755 :     GetGDALDriverManager()->RegisterDriver(poDriver);
     158             : }

Generated by: LCOV version 1.14