LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/jsonfg - ogrjsonfgmemlayer.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 27 39 69.2 %
Date: 2024-05-15 17:37:59 Functions: 3 3 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 "ogr_jsonfg.h"
      30             : 
      31             : /************************************************************************/
      32             : /*                OGRJSONFGMemLayer::OGRJSONFGMemLayer()                */
      33             : /************************************************************************/
      34             : 
      35          49 : OGRJSONFGMemLayer::OGRJSONFGMemLayer(GDALDataset *poDS, const char *pszName,
      36             :                                      OGRSpatialReference *poSRS,
      37          49 :                                      OGRwkbGeometryType eGType)
      38          49 :     : OGRMemLayer(pszName, poSRS, eGType), m_poDS(poDS)
      39             : {
      40          49 :     SetAdvertizeUTF8(true);
      41          49 :     SetUpdatable(false);
      42          49 : }
      43             : 
      44             : /************************************************************************/
      45             : /*                OGRJSONFGMemLayer::~OGRJSONFGMemLayer()               */
      46             : /************************************************************************/
      47             : 
      48             : OGRJSONFGMemLayer::~OGRJSONFGMemLayer() = default;
      49             : 
      50             : /************************************************************************/
      51             : /*                           AddFeature                                 */
      52             : /************************************************************************/
      53             : 
      54          51 : void OGRJSONFGMemLayer::AddFeature(std::unique_ptr<OGRFeature> poFeature)
      55             : {
      56          51 :     GIntBig nFID = poFeature->GetFID();
      57             : 
      58             :     // Detect potential FID duplicates and make sure they are eventually
      59             :     // unique.
      60          51 :     if (-1 == nFID)
      61             :     {
      62          50 :         nFID = GetFeatureCount(FALSE);
      63          50 :         OGRFeature *poTryFeature = nullptr;
      64          50 :         while ((poTryFeature = GetFeature(nFID)) != nullptr)
      65             :         {
      66           0 :             nFID++;
      67           0 :             delete poTryFeature;
      68             :         }
      69             :     }
      70             :     else
      71             :     {
      72           1 :         OGRFeature *poTryFeature = nullptr;
      73           1 :         if ((poTryFeature = GetFeature(nFID)) != nullptr)
      74             :         {
      75           0 :             if (!bOriginalIdModified_)
      76             :             {
      77           0 :                 CPLError(
      78             :                     CE_Warning, CPLE_AppDefined,
      79             :                     "Several features with id = " CPL_FRMT_GIB " have been "
      80             :                     "found. Altering it to be unique. This warning will not "
      81             :                     "be emitted anymore for this layer",
      82             :                     nFID);
      83           0 :                 bOriginalIdModified_ = true;
      84             :             }
      85           0 :             delete poTryFeature;
      86           0 :             nFID = GetFeatureCount(FALSE);
      87           0 :             while ((poTryFeature = GetFeature(nFID)) != nullptr)
      88             :             {
      89           0 :                 nFID++;
      90           0 :                 delete poTryFeature;
      91             :             }
      92             :         }
      93             :     }
      94          51 :     poFeature->SetFID(nFID);
      95             : 
      96          51 :     if (!CPL_INT64_FITS_ON_INT32(nFID))
      97           0 :         SetMetadataItem(OLMD_FID64, "YES");
      98             : 
      99          51 :     const bool bIsUpdatable = IsUpdatable();
     100          51 :     SetUpdatable(true);  // Temporary toggle on updatable flag.
     101          51 :     CPL_IGNORE_RET_VAL(OGRMemLayer::SetFeature(poFeature.get()));
     102          51 :     SetUpdatable(bIsUpdatable);
     103          51 :     SetUpdated(false);
     104          51 : }
     105             : 
     106             : /************************************************************************/
     107             : /*                           TestCapability()                           */
     108             : /************************************************************************/
     109             : 
     110          98 : int OGRJSONFGMemLayer::TestCapability(const char *pszCap)
     111             : 
     112             : {
     113          98 :     if (EQUAL(pszCap, OLCCurveGeometries))
     114          49 :         return FALSE;
     115             : 
     116          49 :     else if (EQUAL(pszCap, OLCMeasuredGeometries))
     117          49 :         return FALSE;
     118             : 
     119           0 :     return OGRMemLayer::TestCapability(pszCap);
     120             : }

Generated by: LCOV version 1.14