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