Debian Codegraph @

ogr/ogrsf_frmts/geojson/ogrgeojsonlayer.cpp

raw symbols SCIP
1 /******************************************************************************
2 *
3 * Project: OpenGIS Simple Features Reference Implementation
4 * Purpose: Implementation of OGRGeoJSONLayer class (OGR GeoJSON Driver).
5 * Author: Mateusz Loskot, [email protected]
6 *
7 ******************************************************************************
8 * Copyright (c) 2007, Mateusz Loskot
9 * Copyright (c) 2010-2013, Even Rouault <even dot rouault at spatialys.com>
10 *
11 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14 #include <algorithm>
15
16 #if !DEBUG_JSON
17 #ifdef __clang__cxx . . $ `<built-in>:3:9`!
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wunknown-pragmas"
20 #pragma clang diagnostic ignored "-Wdocumentation"
21 #pragma clang diagnostic ignored "-Wold-style-cast"
22 #endif
23 #endif // !DEBUG_VERBOSE
24
25 #include <json.h>
26
27 #if !DEBUG_JSON
28 #ifdef __clang
29 #pragma clang diagnostic pop
30 #endif
31 #endif // !DEBUG_VERBOSE
32
33 #include "ogr_geojson.h"cxx . . $ `<file>/ogr/ogrsf_frmts/geojson/ogr_geojson.h`/
34 #include "ogrgeojsonreader.h"cxx . . $ `<file>/ogr/ogrsf_frmts/geojson/ogrgeojsonreader.h`/
35
36 /************************************************************************/
37 /* STATIC MEMBERS DEFINITION */
38 /************************************************************************/
39
40 const char *const OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::DefaultNamecxx . . $ OGRGeoJSONLayer#DefaultName. = "OGRGeoJSON";
41 const OGRwkbGeometryType OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::DefaultGeometryTypecxx . . $ OGRGeoJSONLayer#DefaultGeometryType. = wkbUnknown;
42
43 /************************************************************************/
44 /* OGRGeoJSONLayer */
45 /************************************************************************/
46
47 OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#OGRGeoJSONLayer(5a43c814ebabef37).(const char *pszName,
48 OGRSpatialReferencecxx . . $ OGRSpatialReference# *poSRSIn,
49 OGRwkbGeometryType eGType,
50 OGRGeoJSONDataSourcecxx . . $ OGRGeoJSONDataSource# *poDS,
51 OGRGeoJSONReadercxx . . $ OGRGeoJSONReader# *poReader)
52 : OGRMemLayercxx . . $ OGRMemLayer#OGRMemLayer(d19689c4c43be45a).(pszName, poSRSIn, eGType), poDS_cxx . . $ OGRGeoJSONLayer#poDS_.(poDS), poReader_cxx . . $ OGRGeoJSONLayer#poReader_.(poReader),
53 bHasAppendedFeatures_cxx . . $ OGRGeoJSONLayer#bHasAppendedFeatures_.(false), bOriginalIdModified_cxx . . $ OGRGeoJSONLayer#bOriginalIdModified_.(false),
54 nTotalFeatureCount_cxx . . $ OGRGeoJSONLayer#nTotalFeatureCount_.(0)
55 {
56 SetAdvertizeUTF8cxx . . $ OGRMemLayer#SetAdvertizeUTF8(b45ddcbc8423892c).(true);
57 SetUpdatablecxx . . $ OGRMemLayer#SetUpdatable(b45ddcbc8423892c).(poDS->IsUpdatablecxx . . $ OGRGeoJSONDataSource#IsUpdatable(50ce9a9e25b4a850).());
58 }
59
60 /************************************************************************/
61 /* ~OGRGeoJSONLayer */
62 /************************************************************************/
63
64 OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::~cxx . . $ OGRGeoJSONLayer#`~OGRGeoJSONLayer`(ced63f7c635d850d).OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#()
65 {
66 TerminateAppendSessioncxx . . $ OGRGeoJSONLayer#TerminateAppendSession(49f6e7a06ebc5aa8).();
67 delete poReader_cxx . . $ OGRGeoJSONLayer#poReader_.;
68 }
69
70 /************************************************************************/
71 /* TerminateAppendSession() */
72 /************************************************************************/
73
74 void OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::TerminateAppendSessioncxx . . $ OGRGeoJSONLayer#TerminateAppendSession(49f6e7a06ebc5aa8).()
75 {
76 if (bHasAppendedFeatures_cxx . . $ OGRGeoJSONLayer#bHasAppendedFeatures_.)
77 {
78 #if defined(__GNUC__cxx . . $ `<built-in>:8:9`!)
79 #pragma GCC diagnostic push
80 #pragma GCC diagnostic ignored "-Wnull-dereference"
81 #endif
82 VSILFILE *fp = poReader_cxx . . $ OGRGeoJSONLayer#poReader_.->GetFPcxx . . $ OGRGeoJSONReader#GetFP(c5a74e05fa14bf1).();
83 #if defined(__GNUC__cxx . . $ `<built-in>:8:9`!)
84 #pragma GCC diagnostic pop
85 #endif
86 VSIFPrintfL(fp, "\n]\n}\n");
87 VSIFFlushL(fp);
88 bHasAppendedFeatures_cxx . . $ OGRGeoJSONLayer#bHasAppendedFeatures_. = false;
89 }
90 }
91
92 /************************************************************************/
93 /* GetFIDColumn */
94 /************************************************************************/
95
96 const char *OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::GetFIDColumncxx . . $ OGRGeoJSONLayer#GetFIDColumn(a9f41ea0e82d88cf).() const
97 {
98 return sFIDColumn_cxx . . $ OGRGeoJSONLayer#sFIDColumn_..c_str();
99 }
100
101 /************************************************************************/
102 /* SetFIDColumn */
103 /************************************************************************/
104
105 void OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::SetFIDColumncxx . . $ OGRGeoJSONLayer#SetFIDColumn(85c52e162fed56f9).(const char *pszFIDColumn)
106 {
107 sFIDColumn_cxx . . $ OGRGeoJSONLayer#sFIDColumn_. = pszFIDColumn;
108 }
109
110 /************************************************************************/
111 /* ResetReading() */
112 /************************************************************************/
113
114 void OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::ResetReadingcxx . . $ OGRGeoJSONLayer#ResetReading(49f6e7a06ebc5aa8).()
115 {
116 nFeatureReadSinceReset_cxx . . $ OGRGeoJSONLayer#nFeatureReadSinceReset_. = 0;
117 if (poReader_cxx . . $ OGRGeoJSONLayer#poReader_.)
118 {
119 TerminateAppendSessioncxx . . $ OGRGeoJSONLayer#TerminateAppendSession(49f6e7a06ebc5aa8).();
120 poReader_cxx . . $ OGRGeoJSONLayer#poReader_.->ResetReadingcxx . . $ OGRGeoJSONReader#ResetReading(49f6e7a06ebc5aa8).();
121 }
122 else
123 OGRMemLayercxx . . $ OGRMemLayer#::ResetReadingcxx . . $ OGRMemLayer#ResetReading(49f6e7a06ebc5aa8).();
124 }
125
126 /************************************************************************/
127 /* GetNextFeature() */
128 /************************************************************************/
129
130 OGRFeaturecxx . . $ OGRFeature# *OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::GetNextFeaturecxx . . $ OGRGeoJSONLayer#GetNextFeature(ec9eceddec1d9563).()
131 {
132 if (poReader_cxx . . $ OGRGeoJSONLayer#poReader_.)
133 {
134 if (bHasAppendedFeatures_cxx . . $ OGRGeoJSONLayer#bHasAppendedFeatures_.)
135 {
136 ResetReadingcxx . . $ OGRGeoJSONLayer#ResetReading(49f6e7a06ebc5aa8).();
137 }
138 while (true)
139 {
140 OGRFeaturecxx . . $ OGRFeature# *poFeature = poReader_cxx . . $ OGRGeoJSONLayer#poReader_.->GetNextFeaturecxx . . $ OGRGeoJSONReader#GetNextFeature(50546ee0789381a3).(this);
141 if (poFeature == nullptr)
142 return nullptr;
143 if ((m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. == nullptr ||
144 FilterGeometrycxx . . $ OGRLayer#FilterGeometry(fed901b2566802ff).(
145 poFeature->GetGeomFieldRefcxx . . $ OGRFeature#GetGeomFieldRef(ea443ccec24c6360).(m_iGeomFieldFiltercxx . . $ OGRLayer#m_iGeomFieldFilter.))) &&
146 (m_poAttrQuerycxx . . $ OGRLayer#m_poAttrQuery. == nullptr ||
147 m_poAttrQuerycxx . . $ OGRLayer#m_poAttrQuery.->Evaluatecxx . . $ OGRFeatureQuery#Evaluate(2048609adab03aab).(poFeature)))
148 {
149 nFeatureReadSinceReset_cxx . . $ OGRGeoJSONLayer#nFeatureReadSinceReset_.++;
150 return poFeature;
151 }
152 delete poFeature;
153 }
154 }
155 else
156 {
157 auto ret = OGRMemLayercxx . . $ OGRMemLayer#::GetNextFeaturecxx . . $ OGRMemLayer#GetNextFeature(ec9eceddec1d9563).();
158 if (ret)
159 {
160 nFeatureReadSinceReset_cxx . . $ OGRGeoJSONLayer#nFeatureReadSinceReset_.++;
161 }
162 return ret;
163 }
164 }
165
166 /************************************************************************/
167 /* GetFeatureCount() */
168 /************************************************************************/
169
170 GIntBigcxx . . $ GIntBig# OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::GetFeatureCountcxx . . $ OGRGeoJSONLayer#GetFeatureCount(9ccc33c3ebad048d).(int bForce)
171 {
172 if (poReader_cxx . . $ OGRGeoJSONLayer#poReader_.)
173 {
174 if (m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. == nullptr && m_poAttrQuerycxx . . $ OGRLayer#m_poAttrQuery. == nullptr &&
175 nTotalFeatureCount_cxx . . $ OGRGeoJSONLayer#nTotalFeatureCount_. >= 0)
176 {
177 return nTotalFeatureCount_cxx . . $ OGRGeoJSONLayer#nTotalFeatureCount_.;
178 }
179 return OGRLayercxx . . $ OGRLayer#::GetFeatureCountcxx . . $ OGRLayer#GetFeatureCount(9ccc33c3ebad048d).(bForce);
180 }
181 else
182 {
183 return OGRMemLayercxx . . $ OGRMemLayer#::GetFeatureCountcxx . . $ OGRMemLayer#GetFeatureCount(9ccc33c3ebad048d).(bForce);
184 }
185 }
186
187 /************************************************************************/
188 /* GetFeature() */
189 /************************************************************************/
190
191 OGRFeaturecxx . . $ OGRFeature# *OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::GetFeaturecxx . . $ OGRGeoJSONLayer#GetFeature(86ac52c37891ada7).(GIntBigcxx . . $ GIntBig# nFID)
192 {
193 if (poReader_cxx . . $ OGRGeoJSONLayer#poReader_.)
194 {
195 if (!IsUpdatablecxx . . $ OGRMemLayer#IsUpdatable(50ce9a9e25b4a850).())
196 {
197 return poReader_cxx . . $ OGRGeoJSONLayer#poReader_.->GetFeaturecxx . . $ OGRGeoJSONReader#GetFeature(755f264185d2adb6).(this, nFID);
198 }
199 return OGRLayercxx . . $ OGRLayer#::GetFeaturecxx . . $ OGRLayer#GetFeature(86ac52c37891ada7).(nFID);
200 }
201 else
202 {
203 return OGRMemLayercxx . . $ OGRMemLayer#::GetFeaturecxx . . $ OGRMemLayer#GetFeature(86ac52c37891ada7).(nFID);
204 }
205 }
206
207 /************************************************************************/
208 /* IngestAll() */
209 /************************************************************************/
210
211 bool OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::IngestAllcxx . . $ OGRGeoJSONLayer#IngestAll(c9857a73d68e59ba).()
212 {
213 if (poReader_cxx . . $ OGRGeoJSONLayer#poReader_.)
214 {
215 TerminateAppendSessioncxx . . $ OGRGeoJSONLayer#TerminateAppendSession(49f6e7a06ebc5aa8).();
216
217 OGRGeoJSONReadercxx . . $ OGRGeoJSONReader# *poReader = poReader_cxx . . $ OGRGeoJSONLayer#poReader_.;
218 poReader_cxx . . $ OGRGeoJSONLayer#poReader_. = nullptr;
219
220 nTotalFeatureCount_cxx . . $ OGRGeoJSONLayer#nTotalFeatureCount_. = -1;
221 bool bRet = poReader->IngestAllcxx . . $ OGRGeoJSONReader#IngestAll(a6e9460a5f4071a4).(this);
222 delete poReader;
223 return bRet;
224 }
225 else
226 {
227 return true;
228 }
229 }
230
231 /************************************************************************/
232 /* SetOrUpdateFeaturePreparation() */
233 /************************************************************************/
234
235 bool OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::SetOrUpdateFeaturePreparationcxx . . $ OGRGeoJSONLayer#SetOrUpdateFeaturePreparation(c9857a73d68e59ba).()
236 {
237 if (!IsUpdatablecxx . . $ OGRMemLayer#IsUpdatable(50ce9a9e25b4a850).())
238 return false;
239 if (poReader_cxx . . $ OGRGeoJSONLayer#poReader_.)
240 {
241 auto nNextIndex = nFeatureReadSinceReset_cxx . . $ OGRGeoJSONLayer#nFeatureReadSinceReset_.;
242 if (!IngestAllcxx . . $ OGRGeoJSONLayer#IngestAll(c9857a73d68e59ba).())
243 return false;
244 SetNextByIndexcxx . . $ OGRMemLayer#SetNextByIndex(a070d6d14e988596).(nNextIndex);
245 }
246 return true;
247 }
248
249 /************************************************************************/
250 /* ISetFeature() */
251 /************************************************************************/
252
253 OGRErr OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::ISetFeaturecxx . . $ OGRGeoJSONLayer#ISetFeature(2048609adab03aab).(OGRFeaturecxx . . $ OGRFeature# *poFeature)
254 {
255 if (!SetOrUpdateFeaturePreparationcxx . . $ OGRGeoJSONLayer#SetOrUpdateFeaturePreparation(c9857a73d68e59ba).())
256 return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!;
257 return OGRMemLayercxx . . $ OGRMemLayer#::ISetFeaturecxx . . $ OGRMemLayer#ISetFeature(2048609adab03aab).(poFeature);
258 }
259
260 /************************************************************************/
261 /* IUpdateFeature() */
262 /************************************************************************/
263
264 OGRErr OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::IUpdateFeaturecxx . . $ OGRGeoJSONLayer#IUpdateFeature(81c9b962c9c18011).(OGRFeaturecxx . . $ OGRFeature# *poFeature,
265 int nUpdatedFieldsCount,
266 const int *panUpdatedFieldsIdx,
267 int nUpdatedGeomFieldsCount,
268 const int *panUpdatedGeomFieldsIdx,
269 bool bUpdateStyleString)
270 {
271 if (!SetOrUpdateFeaturePreparationcxx . . $ OGRGeoJSONLayer#SetOrUpdateFeaturePreparation(c9857a73d68e59ba).())
272 return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!;
273 return OGRMemLayercxx . . $ OGRMemLayer#::IUpdateFeaturecxx . . $ OGRMemLayer#IUpdateFeature(81c9b962c9c18011).(
274 poFeature, nUpdatedFieldsCount, panUpdatedFieldsIdx,
275 nUpdatedGeomFieldsCount, panUpdatedGeomFieldsIdx, bUpdateStyleString);
276 }
277
278 /************************************************************************/
279 /* ICreateFeature() */
280 /************************************************************************/
281
282 OGRErr OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::ICreateFeaturecxx . . $ OGRGeoJSONLayer#ICreateFeature(2048609adab03aab).(OGRFeaturecxx . . $ OGRFeature# *poFeature)
283 {
284 if (!IsUpdatablecxx . . $ OGRMemLayer#IsUpdatable(50ce9a9e25b4a850).())
285 return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!;
286 if (poReader_cxx . . $ OGRGeoJSONLayer#poReader_.)
287 {
288 bool bTryEasyAppend = true;
289 while (true)
290 {
291 // We can trivially append to end of existing file, provided the
292 // following conditions are met:
293 // * the "features" array member is the last one of the main
294 // object (poReader_->CanEasilyAppend())
295 // * there is no "bbox" at feature collection level (could possibly
296 // be supported)
297 // * the features have no explicit FID field, so it is trivial to
298 // derive the FID of newly created features without collision
299 // * we know the total number of existing features
300 if (bTryEasyAppend && poReader_cxx . . $ OGRGeoJSONLayer#poReader_.->CanEasilyAppendcxx . . $ OGRGeoJSONReader#CanEasilyAppend(50ce9a9e25b4a850).() &&
301 !poReader_cxx . . $ OGRGeoJSONLayer#poReader_.->FCHasBBOXcxx . . $ OGRGeoJSONReader#FCHasBBOX(50ce9a9e25b4a850).() && sFIDColumn_cxx . . $ OGRGeoJSONLayer#sFIDColumn_..empty() &&
302 GetLayerDefncxx . . $ OGRLayer#GetLayerDefn(407fccde18759965).()->GetFieldIndexcxx . . $ OGRFeatureDefn#GetFieldIndex(78f035161ffa9fe2).("id") < 0 &&
303 nTotalFeatureCount_cxx . . $ OGRGeoJSONLayer#nTotalFeatureCount_. >= 0)
304 {
305 VSILFILE *fp = poReader_cxx . . $ OGRGeoJSONLayer#poReader_.->GetFPcxx . . $ OGRGeoJSONReader#GetFP(c5a74e05fa14bf1).();
306 if (!bHasAppendedFeatures_cxx . . $ OGRGeoJSONLayer#bHasAppendedFeatures_.)
307 {
308 // Locate "} ] }" (or "[ ] }") pattern at end of file
309 VSIFSeekLcxx . . $ VSIFSeekL(7b147a47904bd6c7).(fp, 0, SEEK_ENDcxx . . $ `<external>/232824719582829767/stdio.h:116:9`!);
310 vsi_l_offset nOffset = VSIFTellL(fp);
311 nOffset -= 10;
312 VSIFSeekL(fp, nOffset, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:114:9`!);
313 char szBuffer[11];
314 VSIFReadL(szBuffer, 10, 1, fp);
315 szBuffer[10] = 0;
316 int i = 9;
317 // Locate final }
318 while (isspace(static_cast<unsigned char>(szBuffer[i])) &&
319 i > 0)
320 i--;
321 if (szBuffer[i] != '}')
322 {
323 bTryEasyAppend = false;
324 continue;
325 }
326 if (i > 0)
327 i--;
328 // Locate ']' ending features array
329 while (isspace(static_cast<unsigned char>(szBuffer[i])) &&
330 i > 0)
331 i--;
332 if (szBuffer[i] != ']')
333 {
334 bTryEasyAppend = false;
335 continue;
336 }
337 if (i > 0)
338 i--;
339 while (isspace(static_cast<unsigned char>(szBuffer[i])) &&
340 i > 0)
341 i--;
342 // Locate '}' ending last feature, or '[' starting features
343 // array
344 if (szBuffer[i] != '}' && szBuffer[i] != '[')
345 {
346 bTryEasyAppend = false;
347 continue;
348 }
349 bool bExistingFeature = szBuffer[i] == '}';
350 nOffset += i + 1;
351 VSIFSeekL(fp, nOffset, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:114:9`!);
352 if (bExistingFeature)
353 {
354 VSIFPrintfL(fp, ",");
355 }
356 VSIFPrintfL(fp, "\n");
357 bHasAppendedFeatures_cxx . . $ OGRGeoJSONLayer#bHasAppendedFeatures_. = true;
358 }
359 else
360 {
361 VSIFPrintfL(fp, ",\n");
362 }
363 json_object *poObj =
364 OGRGeoJSONWriteFeaturecxx . . $ OGRGeoJSONWriteFeature(631f140fdd136df6).(poFeature, oWriteOptions_cxx . . $ OGRGeoJSONLayer#oWriteOptions_.);
365
366 const char *pszJson = json_object_to_json_string_ext(
367 poObj, JSON_C_TO_STRING_PLAINcxx . . $ `<external>/5475662611906901010/json_object.h:43:9`!
368 #ifdef JSON_C_TO_STRING_NOSLASHESCAPEcxx . . $ `<external>/5475662611906901010/json_object.h:75:9`!
369 | JSON_C_TO_STRING_NOSLASHESCAPEcxx . . $ `<external>/5475662611906901010/json_object.h:75:9`!
370 #endif
371 );
372
373 VSIFPrintfL(fp, "%s", pszJson);
374 json_object_put(poObj);
375
376 if (poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).() == OGRNullFIDcxx . . $ `ogr/ogr_core.h:848:9`!)
377 {
378 poFeature->SetFIDcxx . . $ OGRFeature#SetFID(a070d6d14e988596).(nTotalFeatureCount_cxx . . $ OGRGeoJSONLayer#nTotalFeatureCount_.);
379 }
380 nTotalFeatureCount_cxx . . $ OGRGeoJSONLayer#nTotalFeatureCount_.++;
381
382 return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!;
383 }
384 else if (IngestAllcxx . . $ OGRGeoJSONLayer#IngestAll(c9857a73d68e59ba).())
385 {
386 break;
387 }
388 else
389 {
390 return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!;
391 }
392 }
393 }
394 return OGRMemLayercxx . . $ OGRMemLayer#::ICreateFeaturecxx . . $ OGRMemLayer#ICreateFeature(2048609adab03aab).(poFeature);
395 }
396
397 /************************************************************************/
398 /* DeleteFeature() */
399 /************************************************************************/
400
401 OGRErr OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::DeleteFeaturecxx . . $ OGRGeoJSONLayer#DeleteFeature(a070d6d14e988596).(GIntBigcxx . . $ GIntBig# nFID)
402 {
403 if (!IsUpdatablecxx . . $ OGRMemLayer#IsUpdatable(50ce9a9e25b4a850).() || !IngestAllcxx . . $ OGRGeoJSONLayer#IngestAll(c9857a73d68e59ba).())
404 return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!;
405 return OGRMemLayercxx . . $ OGRMemLayer#::DeleteFeaturecxx . . $ OGRMemLayer#DeleteFeature(a070d6d14e988596).(nFID);
406 }
407
408 /************************************************************************/
409 /* CreateField() */
410 /************************************************************************/
411
412 OGRErr OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::CreateFieldcxx . . $ OGRGeoJSONLayer#CreateField(2cf5282e6e90de1e).(const OGRFieldDefncxx . . $ OGRFieldDefn# *poField, int bApproxOK)
413 {
414 if (!IsUpdatablecxx . . $ OGRMemLayer#IsUpdatable(50ce9a9e25b4a850).() || !IngestAllcxx . . $ OGRGeoJSONLayer#IngestAll(c9857a73d68e59ba).())
415 return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!;
416 return OGRMemLayercxx . . $ OGRMemLayer#::CreateFieldcxx . . $ OGRMemLayer#CreateField(2cf5282e6e90de1e).(poField, bApproxOK);
417 }
418
419 /************************************************************************/
420 /* DeleteField() */
421 /************************************************************************/
422
423 OGRErr OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::DeleteFieldcxx . . $ OGRGeoJSONLayer#DeleteField(7864480464b09eea).(int iField)
424 {
425 if (!IsUpdatablecxx . . $ OGRMemLayer#IsUpdatable(50ce9a9e25b4a850).() || !IngestAllcxx . . $ OGRGeoJSONLayer#IngestAll(c9857a73d68e59ba).())
426 return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!;
427 return OGRMemLayercxx . . $ OGRMemLayer#::DeleteFieldcxx . . $ OGRMemLayer#DeleteField(7864480464b09eea).(iField);
428 }
429
430 /************************************************************************/
431 /* ReorderFields() */
432 /************************************************************************/
433
434 OGRErr OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::ReorderFieldscxx . . $ OGRGeoJSONLayer#ReorderFields(a5f7824ee4986326).(int *panMap)
435 {
436 if (!IsUpdatablecxx . . $ OGRMemLayer#IsUpdatable(50ce9a9e25b4a850).() || !IngestAllcxx . . $ OGRGeoJSONLayer#IngestAll(c9857a73d68e59ba).())
437 return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!;
438 return OGRMemLayercxx . . $ OGRMemLayer#::ReorderFieldscxx . . $ OGRMemLayer#ReorderFields(a5f7824ee4986326).(panMap);
439 }
440
441 /************************************************************************/
442 /* AlterFieldDefn() */
443 /************************************************************************/
444
445 OGRErr OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::AlterFieldDefncxx . . $ OGRGeoJSONLayer#AlterFieldDefn(a8f2b8f690332f80).(int iField, OGRFieldDefncxx . . $ OGRFieldDefn# *poNewFieldDefn,
446 int nFlagsIn)
447 {
448 if (!IsUpdatablecxx . . $ OGRMemLayer#IsUpdatable(50ce9a9e25b4a850).() || !IngestAllcxx . . $ OGRGeoJSONLayer#IngestAll(c9857a73d68e59ba).())
449 return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!;
450 return OGRMemLayercxx . . $ OGRMemLayer#::AlterFieldDefncxx . . $ OGRMemLayer#AlterFieldDefn(a8f2b8f690332f80).(iField, poNewFieldDefn, nFlagsIn);
451 }
452
453 /************************************************************************/
454 /* CreateGeomField() */
455 /************************************************************************/
456
457 OGRErr OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::CreateGeomFieldcxx . . $ OGRGeoJSONLayer#CreateGeomField(6dac0ba981f896cd).(const OGRGeomFieldDefncxx . . $ OGRGeomFieldDefn# *poGeomField,
458 int bApproxOK)
459 {
460 if (!IsUpdatablecxx . . $ OGRMemLayer#IsUpdatable(50ce9a9e25b4a850).() || !IngestAllcxx . . $ OGRGeoJSONLayer#IngestAll(c9857a73d68e59ba).())
461 return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!;
462 return OGRMemLayercxx . . $ OGRMemLayer#::CreateGeomFieldcxx . . $ OGRMemLayer#CreateGeomField(6dac0ba981f896cd).(poGeomField, bApproxOK);
463 }
464
465 OGRErr OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::IGetExtentcxx . . $ OGRGeoJSONLayer#IGetExtent(ee9c866093418aa0).(int iGeomField, OGREnvelope *psExtent,
466 bool bForce)
467 {
468 if (iGeomField != 0)
469 {
470 return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!;
471 }
472
473 if (poReader_cxx . . $ OGRGeoJSONLayer#poReader_. && poReader_cxx . . $ OGRGeoJSONLayer#poReader_.->ExtentReadcxx . . $ OGRGeoJSONBaseReader#ExtentRead(50ce9a9e25b4a850).() &&
474 TestCapabilitycxx . . $ OGRGeoJSONLayer#TestCapability(78f035161ffa9fe2).(OLCFastGetExtentcxx . . $ `ogr/ogr_core.h:986:9`!))
475 {
476 *psExtent = poReader_cxx . . $ OGRGeoJSONLayer#poReader_.->GetExtent3Dcxx . . $ OGRGeoJSONBaseReader#GetExtent3D(d914a03a7fe66544).();
477 return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!;
478 }
479 else
480 {
481 return OGRMemLayercxx . . $ OGRMemLayer#::IGetExtentcxx . . $ OGRLayer#IGetExtent(ee9c866093418aa0).(iGeomField, psExtent, bForce);
482 }
483 }
484
485 OGRErr OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::IGetExtent3Dcxx . . $ OGRGeoJSONLayer#IGetExtent3D(308398dff6ed51e0).(int iGeomField, OGREnvelope3D *psExtent3D,
486 bool bForce)
487 {
488
489 if (iGeomField != 0)
490 {
491 return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!;
492 }
493
494 if (poReader_cxx . . $ OGRGeoJSONLayer#poReader_. && poReader_cxx . . $ OGRGeoJSONLayer#poReader_.->ExtentReadcxx . . $ OGRGeoJSONBaseReader#ExtentRead(50ce9a9e25b4a850).() &&
495 TestCapabilitycxx . . $ OGRGeoJSONLayer#TestCapability(78f035161ffa9fe2).(OLCFastGetExtent3Dcxx . . $ `ogr/ogr_core.h:988:9`!))
496 {
497 *psExtent3D = poReader_cxx . . $ OGRGeoJSONLayer#poReader_.->GetExtent3Dcxx . . $ OGRGeoJSONBaseReader#GetExtent3D(d914a03a7fe66544).();
498 return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!;
499 }
500 else
501 {
502 return OGRMemLayercxx . . $ OGRMemLayer#::IGetExtent3Dcxx . . $ OGRLayer#IGetExtent3D(308398dff6ed51e0).(iGeomField, psExtent3D, bForce);
503 }
504 }
505
506 /************************************************************************/
507 /* TestCapability() */
508 /************************************************************************/
509
510 int OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::TestCapabilitycxx . . $ OGRGeoJSONLayer#TestCapability(78f035161ffa9fe2).(const char *pszCap) const
511
512 {
513 if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCCurveGeometriescxx . . $ `ogr/ogr_core.h:1023:9`!))
514 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
515 else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCMeasuredGeometriescxx . . $ `ogr/ogr_core.h:1025:9`!))
516 return m_bSupportsMGeometriescxx . . $ OGRGeoJSONLayer#m_bSupportsMGeometries.;
517 else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCZGeometriescxx . . $ `ogr/ogr_core.h:1028:9`!))
518 return m_bSupportsZGeometriescxx . . $ OGRGeoJSONLayer#m_bSupportsZGeometries.;
519 else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCStringsAsUTF8cxx . . $ `ogr/ogr_core.h:1016:9`!))
520 return TRUEcxx . . $ `port/cpl_port.h:1184:9`!;
521 else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCFastGetExtentcxx . . $ `ogr/ogr_core.h:986:9`!) ||
522 EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCFastGetExtent3Dcxx . . $ `ogr/ogr_core.h:988:9`!))
523 return m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. == nullptr && m_poAttrQuerycxx . . $ OGRLayer#m_poAttrQuery. == nullptr;
524 return OGRMemLayercxx . . $ OGRMemLayer#::TestCapabilitycxx . . $ OGRMemLayer#TestCapability(78f035161ffa9fe2).(pszCap);
525 }
526
527 /************************************************************************/
528 /* SyncToDisk() */
529 /************************************************************************/
530
531 OGRErr OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::SyncToDiskcxx . . $ OGRGeoJSONLayer#SyncToDisk(b126dc7c1de90089).()
532 {
533 TerminateAppendSessioncxx . . $ OGRGeoJSONLayer#TerminateAppendSession(49f6e7a06ebc5aa8).();
534
535 poDS_cxx . . $ OGRGeoJSONLayer#poDS_.->FlushCachecxx . . $ OGRGeoJSONDataSource#FlushCache(426a86739463d040).(false);
536 return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!;
537 }
538
539 /************************************************************************/
540 /* AddFeature */
541 /************************************************************************/
542
543 void OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::AddFeaturecxx . . $ OGRGeoJSONLayer#AddFeature(cb47ac782fdd8401).(stdcxx . . $ std/::unique_ptr<OGRFeaturecxx . . $ OGRFeature#> poFeature)
544 {
545 GIntBigcxx . . $ GIntBig# nFID = poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).();
546
547 // Detect potential FID duplicates and make sure they are eventually
548 // unique.
549 if (-1 == nFID)
550 {
551 nFID = GetFeatureCountcxx . . $ OGRGeoJSONLayer#GetFeatureCount(9ccc33c3ebad048d).(FALSEcxx . . $ `port/cpl_port.h:1180:9`!);
552 OGRFeaturecxx . . $ OGRFeature# *poTryFeature = nullptr;
553 while ((poTryFeature = GetFeaturecxx . . $ OGRGeoJSONLayer#GetFeature(86ac52c37891ada7).(nFID)) != nullptr)
554 {
555 nFID++;
556 delete poTryFeature;
557 }
558 }
559 else
560 {
561 OGRFeaturecxx . . $ OGRFeature# *poTryFeature = nullptr;
562 if ((poTryFeature = GetFeaturecxx . . $ OGRGeoJSONLayer#GetFeature(86ac52c37891ada7).(nFID)) != nullptr)
563 {
564 if (!bOriginalIdModified_cxx . . $ OGRGeoJSONLayer#bOriginalIdModified_.)
565 {
566 CPLError(
567 CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!,
568 "Several features with id = " CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! " have been "
569 "found. Altering it to be unique. This warning will not "
570 "be emitted anymore for this layer",
571 nFID);
572 bOriginalIdModified_cxx . . $ OGRGeoJSONLayer#bOriginalIdModified_. = true;
573 }
574 delete poTryFeature;
575 nFID = GetFeatureCountcxx . . $ OGRGeoJSONLayer#GetFeatureCount(9ccc33c3ebad048d).(FALSEcxx . . $ `port/cpl_port.h:1180:9`!);
576 while ((poTryFeature = GetFeaturecxx . . $ OGRGeoJSONLayer#GetFeature(86ac52c37891ada7).(nFID)) != nullptr)
577 {
578 nFID++;
579 delete poTryFeature;
580 }
581 }
582 }
583 poFeature->SetFIDcxx . . $ OGRFeature#SetFID(a070d6d14e988596).(nFID);
584
585 if (!CPL_INT64_FITS_ON_INT32cxx . . $ `port/cpl_port.h:265:9`!(nFID))
586 SetMetadataItemcxx . . $ GDALMajorObject#SetMetadataItem(216fc8eb9053a851).(OLMD_FID64cxx . . $ `ogr/ogr_core.h:1089:9`!, "YES");
587
588 const bool bIsUpdatable = IsUpdatablecxx . . $ OGRMemLayer#IsUpdatable(50ce9a9e25b4a850).();
589 SetUpdatablecxx . . $ OGRMemLayer#SetUpdatable(b45ddcbc8423892c).(true); // Temporary toggle on updatable flag.
590 CPL_IGNORE_RET_VAL(OGRMemLayercxx . . $ OGRMemLayer#::SetFeaturecxx . . $ OGRLayer#SetFeature(acdbcf288a99bc2c).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(poFeature)));
591 SetUpdatablecxx . . $ OGRMemLayer#SetUpdatable(b45ddcbc8423892c).(bIsUpdatable);
592 SetUpdatedcxx . . $ OGRMemLayer#SetUpdated(b45ddcbc8423892c).(false);
593 }
594
595 /************************************************************************/
596 /* DetectGeometryType */
597 /************************************************************************/
598
599 void OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::DetectGeometryTypecxx . . $ OGRGeoJSONLayer#DetectGeometryType(49f6e7a06ebc5aa8).()
600 {
601 auto poFDefn = GetLayerDefncxx . . $ OGRLayer#GetLayerDefn(407fccde18759965).();
602 if (poFDefn->GetGeomTypecxx . . $ OGRFeatureDefn#GetGeomType(5a40c54c5ff210ce).() != wkbUnknown)
603 return;
604
605 ResetReadingcxx . . $ OGRGeoJSONLayer#ResetReading(49f6e7a06ebc5aa8).();
606 bool bFirstGeometry = true;
607 OGRwkbGeometryType eLayerGeomType = wkbUnknown;
608 for (const auto &poFeature : *this)
609 {
610 const OGRGeometrycxx . . $ OGRGeometry# *poGeometry = poFeature->GetGeometryRefcxx . . $ OGRFeature#GetGeometryRef(3dfc1d32c7db2584).();
611 if (nullptr != poGeometry)
612 {
613 OGRwkbGeometryType eGeomType = poGeometry->getGeometryTypecxx . . $ OGRGeometry#getGeometryType(5a40c54c5ff210ce).();
614 if (!OGRGeoJSONUpdateLayerGeomTypecxx . . $ OGRGeoJSONUpdateLayerGeomType(e87a275bf12b61c5).(bFirstGeometry, eGeomType,
615 eLayerGeomType))
616 {
617 break;
618 }
619 }
620 }
621
622 {
623 auto oTemporaryUnsealer(poFDefn->GetTemporaryUnsealercxx . . $ OGRFeatureDefn#GetTemporaryUnsealer(af2f58307af7aba).());
624 poFDefn->SetGeomTypecxx . . $ OGRFeatureDefn#SetGeomType(f47ce3f1fe923726).(eLayerGeomType);
625 }
626
627 ResetReadingcxx . . $ OGRGeoJSONLayer#ResetReading(49f6e7a06ebc5aa8).();
628 }
629
630 /************************************************************************/
631 /* GetDataset() */
632 /************************************************************************/
633
634 GDALDatasetcxx . . $ GDALDataset# *OGRGeoJSONLayercxx . . $ OGRGeoJSONLayer#::GetDatasetcxx . . $ OGRGeoJSONLayer#GetDataset(76c1989f6ffbc048).()
635 {
636 return poDS_cxx . . $ OGRGeoJSONLayer#poDS_.;
637 }