LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/jsonfg - ogrjsonfgdriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 50 51 98.0 %
Date: 2024-05-14 23:54:21 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             :  * 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 "gdal_priv.h"
      30             : #include "ogrsf_frmts.h"
      31             : 
      32             : #include "ogr_jsonfg.h"
      33             : #include "ogrgeojsonutils.h"
      34             : 
      35             : /************************************************************************/
      36             : /*                       OGRJSONFGDriverIdentify()                      */
      37             : /************************************************************************/
      38             : 
      39       40413 : static int OGRJSONFGDriverIdentify(GDALOpenInfo *poOpenInfo)
      40             : {
      41       40413 :     GeoJSONSourceType nSrcType = JSONFGDriverGetSourceType(poOpenInfo);
      42       40413 :     if (nSrcType == eGeoJSONSourceUnknown)
      43       40267 :         return FALSE;
      44         146 :     if (nSrcType == eGeoJSONSourceService &&
      45           9 :         !STARTS_WITH_CI(poOpenInfo->pszFilename, "JSONFG:"))
      46             :     {
      47           9 :         return -1;
      48             :     }
      49         137 :     return TRUE;
      50             : }
      51             : 
      52             : /************************************************************************/
      53             : /*                           Open()                                     */
      54             : /************************************************************************/
      55             : 
      56         138 : static GDALDataset *OGRJSONFGDriverOpen(GDALOpenInfo *poOpenInfo)
      57             : {
      58         138 :     GeoJSONSourceType nSrcType = JSONFGDriverGetSourceType(poOpenInfo);
      59         138 :     if (nSrcType == eGeoJSONSourceUnknown)
      60           0 :         return nullptr;
      61         276 :     auto poDS = std::make_unique<OGRJSONFGDataset>();
      62         138 :     if (!poDS->Open(poOpenInfo, nSrcType))
      63           1 :         return nullptr;
      64         137 :     return poDS.release();
      65             : }
      66             : 
      67             : /************************************************************************/
      68             : /*                               Create()                               */
      69             : /************************************************************************/
      70             : 
      71          73 : static GDALDataset *OGRJSONFGDriverCreate(const char *pszName, int /* nBands */,
      72             :                                           int /* nXSize */, int /* nYSize */,
      73             :                                           GDALDataType /* eDT */,
      74             :                                           char **papszOptions)
      75             : {
      76         146 :     auto poDS = std::make_unique<OGRJSONFGDataset>();
      77          73 :     if (!poDS->Create(pszName, papszOptions))
      78             :     {
      79           1 :         return nullptr;
      80             :     }
      81          72 :     return poDS.release();
      82             : }
      83             : 
      84             : /************************************************************************/
      85             : /*                           RegisterOGRJSONFG()                        */
      86             : /************************************************************************/
      87             : 
      88        1522 : void RegisterOGRJSONFG()
      89             : {
      90        1522 :     if (GDALGetDriverByName("JSONFG") != nullptr)
      91         301 :         return;
      92             : 
      93        1221 :     GDALDriver *poDriver = new GDALDriver();
      94             : 
      95        1221 :     poDriver->SetDescription("JSONFG");
      96        1221 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
      97        1221 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES");
      98        1221 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES");
      99        1221 :     poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES");
     100        1221 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME,
     101        1221 :                               "OGC Features and Geometries JSON");
     102        1221 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "json");
     103        1221 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/jsonfg.html");
     104             : 
     105        1221 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
     106             : 
     107        1221 :     poDriver->SetMetadataItem(
     108             :         GDAL_DMD_OPENOPTIONLIST,
     109             :         "<OpenOptionList>"
     110             :         "  <Option name='GEOMETRY_ELEMENT' type='string-select' "
     111             :         "description='Which JSON element to use to create geometry from'>"
     112             :         "    <Value>AUTO</Value>"
     113             :         "    <Value>PLACE</Value>"
     114             :         "    <Value>GEOMETRY</Value>"
     115             :         "  </Option>"
     116        1221 :         "</OpenOptionList>");
     117             : 
     118        1221 :     poDriver->SetMetadataItem(
     119             :         GDAL_DMD_CREATIONOPTIONLIST,
     120             :         "<CreationOptionList>"
     121             :         "  <Option name='SINGLE_LAYER' type='boolean' description='whether "
     122             :         "only one layer will be written' default='NO'/>"
     123        1221 :         "</CreationOptionList>");
     124             : 
     125        1221 :     poDriver->SetMetadataItem(
     126             :         GDAL_DS_LAYER_CREATIONOPTIONLIST,
     127             :         "<LayerCreationOptionList>"
     128             :         "  <Option name='COORDINATE_PRECISION_GEOMETRY' type='int' "
     129             :         "description='Number of decimal for coordinates in the geometry "
     130             :         "element'/>"
     131             :         "  <Option name='COORDINATE_PRECISION_PLACE' type='int' "
     132             :         "description='Number of decimal for coordinates in the place element'/>"
     133             :         "  <Option name='WRITE_GEOMETRY' type='boolean' "
     134             :         "description='Can be set to NO to avoid writing the geometry element "
     135             :         "when place is written' default='YES'/>"
     136             :         "  <Option name='SIGNIFICANT_FIGURES' type='int' description='Number "
     137             :         "of significant figures for floating-point values' default='17'/>"
     138             :         "  <Option name='ID_FIELD' type='string' description='Name of the "
     139             :         "source field that must be used as the id member of Feature features'/>"
     140             :         "  <Option name='ID_TYPE' type='string-select' description='Type of "
     141             :         "the id member of Feature features'>"
     142             :         "    <Value>AUTO</Value>"
     143             :         "    <Value>String</Value>"
     144             :         "    <Value>Integer</Value>"
     145             :         "  </Option>"
     146             :         "  <Option name='ID_GENERATE' type='boolean' "
     147             :         "description='Auto-generate feature ids' default='NO'/>"
     148        1221 :         "</LayerCreationOptionList>");
     149             : 
     150        1221 :     poDriver->SetMetadataItem(
     151             :         GDAL_DMD_CREATIONFIELDDATATYPES,
     152             :         "Integer Integer64 Real String IntegerList "
     153        1221 :         "Integer64List RealList StringList Date DateTime");
     154        1221 :     poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATASUBTYPES, "Boolean");
     155        1221 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE");
     156        1221 :     poDriver->SetMetadataItem(GDAL_DCAP_FLUSHCACHE_CONSISTENT_STATE, "YES");
     157        1221 :     poDriver->SetMetadataItem(GDAL_DCAP_HONOR_GEOM_COORDINATE_PRECISION, "YES");
     158             : 
     159        1221 :     poDriver->pfnOpen = OGRJSONFGDriverOpen;
     160        1221 :     poDriver->pfnIdentify = OGRJSONFGDriverIdentify;
     161        1221 :     poDriver->pfnCreate = OGRJSONFGDriverCreate;
     162             : 
     163        1221 :     GetGDALDriverManager()->RegisterDriver(poDriver);
     164             : }

Generated by: LCOV version 1.14