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 "ogr_jsonfg.h" 14 : 15 : /************************************************************************/ 16 : /* OGRJSONFGMemLayer::OGRJSONFGMemLayer() */ 17 : /************************************************************************/ 18 : 19 50 : OGRJSONFGMemLayer::OGRJSONFGMemLayer(GDALDataset *poDS, const char *pszName, 20 : OGRSpatialReference *poSRS, 21 50 : OGRwkbGeometryType eGType) 22 50 : : OGRMemLayer(pszName, poSRS, eGType), m_poDS(poDS) 23 : { 24 50 : SetAdvertizeUTF8(true); 25 50 : SetUpdatable(false); 26 50 : } 27 : 28 : /************************************************************************/ 29 : /* OGRJSONFGMemLayer::~OGRJSONFGMemLayer() */ 30 : /************************************************************************/ 31 : 32 : OGRJSONFGMemLayer::~OGRJSONFGMemLayer() = default; 33 : 34 : /************************************************************************/ 35 : /* AddFeature */ 36 : /************************************************************************/ 37 : 38 52 : void OGRJSONFGMemLayer::AddFeature(std::unique_ptr<OGRFeature> poFeature) 39 : { 40 52 : GIntBig nFID = poFeature->GetFID(); 41 : 42 : // Detect potential FID duplicates and make sure they are eventually 43 : // unique. 44 52 : if (-1 == nFID) 45 : { 46 50 : nFID = GetFeatureCount(FALSE); 47 50 : OGRFeature *poTryFeature = nullptr; 48 50 : while ((poTryFeature = GetFeature(nFID)) != nullptr) 49 : { 50 0 : nFID++; 51 0 : delete poTryFeature; 52 : } 53 : } 54 : else 55 : { 56 2 : OGRFeature *poTryFeature = nullptr; 57 2 : if ((poTryFeature = GetFeature(nFID)) != nullptr) 58 : { 59 0 : if (!bOriginalIdModified_) 60 : { 61 0 : CPLError( 62 : CE_Warning, CPLE_AppDefined, 63 : "Several features with id = " CPL_FRMT_GIB " have been " 64 : "found. Altering it to be unique. This warning will not " 65 : "be emitted anymore for this layer", 66 : nFID); 67 0 : bOriginalIdModified_ = true; 68 : } 69 0 : delete poTryFeature; 70 0 : nFID = GetFeatureCount(FALSE); 71 0 : while ((poTryFeature = GetFeature(nFID)) != nullptr) 72 : { 73 0 : nFID++; 74 0 : delete poTryFeature; 75 : } 76 : } 77 : } 78 52 : poFeature->SetFID(nFID); 79 : 80 52 : if (!CPL_INT64_FITS_ON_INT32(nFID)) 81 0 : SetMetadataItem(OLMD_FID64, "YES"); 82 : 83 52 : const bool bIsUpdatable = IsUpdatable(); 84 52 : SetUpdatable(true); // Temporary toggle on updatable flag. 85 52 : CPL_IGNORE_RET_VAL(OGRMemLayer::SetFeature(poFeature.get())); 86 52 : SetUpdatable(bIsUpdatable); 87 52 : SetUpdated(false); 88 52 : } 89 : 90 : /************************************************************************/ 91 : /* TestCapability() */ 92 : /************************************************************************/ 93 : 94 100 : int OGRJSONFGMemLayer::TestCapability(const char *pszCap) 95 : 96 : { 97 100 : if (EQUAL(pszCap, OLCCurveGeometries)) 98 50 : return FALSE; 99 : 100 50 : else if (EQUAL(pszCap, OLCMeasuredGeometries)) 101 50 : return FALSE; 102 : 103 0 : return OGRMemLayer::TestCapability(pszCap); 104 : }