Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: OpenGIS Simple Features Reference Implementation
4 : * Purpose: Implements OGRLayerDecorator class
5 : * Author: Even Rouault, even dot rouault at spatialys.com
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 2012-2013, Even Rouault <even dot rouault at spatialys.com>
9 : *
10 : * SPDX-License-Identifier: MIT
11 : ****************************************************************************/
12 :
13 : #ifndef DOXYGEN_SKIP
14 :
15 : #include "ogrlayerdecorator.h"
16 : #include "ogr_recordbatch.h"
17 :
18 691 : OGRLayerDecorator::OGRLayerDecorator(OGRLayer *poDecoratedLayer,
19 0 : int bTakeOwnership)
20 691 : : m_poDecoratedLayer(poDecoratedLayer), m_bHasOwnership(bTakeOwnership)
21 : {
22 691 : CPLAssert(poDecoratedLayer != nullptr);
23 691 : SetDescription(poDecoratedLayer->GetDescription());
24 691 : }
25 :
26 691 : OGRLayerDecorator::~OGRLayerDecorator()
27 : {
28 691 : if (m_bHasOwnership)
29 408 : delete m_poDecoratedLayer;
30 691 : }
31 :
32 18 : OGRGeometry *OGRLayerDecorator::GetSpatialFilter()
33 : {
34 18 : if (!m_poDecoratedLayer)
35 0 : return nullptr;
36 18 : return m_poDecoratedLayer->GetSpatialFilter();
37 : }
38 :
39 189 : OGRErr OGRLayerDecorator::ISetSpatialFilter(int iGeomField,
40 : const OGRGeometry *poGeom)
41 : {
42 189 : if (!m_poDecoratedLayer)
43 0 : return OGRERR_FAILURE;
44 189 : return m_poDecoratedLayer->SetSpatialFilter(iGeomField, poGeom);
45 : }
46 :
47 512 : OGRErr OGRLayerDecorator::SetAttributeFilter(const char *poAttrFilter)
48 : {
49 512 : if (!m_poDecoratedLayer)
50 0 : return OGRERR_FAILURE;
51 512 : return m_poDecoratedLayer->SetAttributeFilter(poAttrFilter);
52 : }
53 :
54 927 : void OGRLayerDecorator::ResetReading()
55 : {
56 927 : if (!m_poDecoratedLayer)
57 0 : return;
58 927 : m_poDecoratedLayer->ResetReading();
59 : }
60 :
61 2243 : OGRFeature *OGRLayerDecorator::GetNextFeature()
62 : {
63 2243 : if (!m_poDecoratedLayer)
64 0 : return nullptr;
65 2243 : return m_poDecoratedLayer->GetNextFeature();
66 : }
67 :
68 68 : GDALDataset *OGRLayerDecorator::GetDataset()
69 : {
70 68 : if (!m_poDecoratedLayer)
71 0 : return nullptr;
72 68 : return m_poDecoratedLayer->GetDataset();
73 : }
74 :
75 99 : bool OGRLayerDecorator::GetArrowStream(struct ArrowArrayStream *out_stream,
76 : CSLConstList papszOptions)
77 : {
78 99 : if (!m_poDecoratedLayer)
79 : {
80 0 : memset(out_stream, 0, sizeof(*out_stream));
81 0 : return false;
82 : }
83 99 : return m_poDecoratedLayer->GetArrowStream(out_stream, papszOptions);
84 : }
85 :
86 72 : OGRErr OGRLayerDecorator::SetNextByIndex(GIntBig nIndex)
87 : {
88 72 : if (!m_poDecoratedLayer)
89 0 : return OGRERR_FAILURE;
90 72 : return m_poDecoratedLayer->SetNextByIndex(nIndex);
91 : }
92 :
93 134 : OGRFeature *OGRLayerDecorator::GetFeature(GIntBig nFID)
94 : {
95 134 : if (!m_poDecoratedLayer)
96 0 : return nullptr;
97 134 : return m_poDecoratedLayer->GetFeature(nFID);
98 : }
99 :
100 17 : OGRErr OGRLayerDecorator::ISetFeature(OGRFeature *poFeature)
101 : {
102 17 : if (!m_poDecoratedLayer)
103 0 : return OGRERR_FAILURE;
104 17 : return m_poDecoratedLayer->SetFeature(poFeature);
105 : }
106 :
107 : OGRErr
108 0 : OGRLayerDecorator::ISetFeatureUniqPtr(std::unique_ptr<OGRFeature> poFeature)
109 : {
110 0 : if (!m_poDecoratedLayer)
111 0 : return OGRERR_FAILURE;
112 0 : return m_poDecoratedLayer->SetFeature(std::move(poFeature));
113 : }
114 :
115 0 : OGRErr OGRLayerDecorator::ICreateFeature(OGRFeature *poFeature)
116 : {
117 0 : if (!m_poDecoratedLayer)
118 0 : return OGRERR_FAILURE;
119 0 : return m_poDecoratedLayer->CreateFeature(poFeature);
120 : }
121 :
122 : OGRErr
123 0 : OGRLayerDecorator::ICreateFeatureUniqPtr(std::unique_ptr<OGRFeature> poFeature,
124 : GIntBig *pnFID)
125 : {
126 0 : if (!m_poDecoratedLayer)
127 0 : return OGRERR_FAILURE;
128 0 : return m_poDecoratedLayer->CreateFeature(std::move(poFeature), pnFID);
129 : }
130 :
131 0 : OGRErr OGRLayerDecorator::IUpsertFeature(OGRFeature *poFeature)
132 : {
133 0 : if (!m_poDecoratedLayer)
134 0 : return OGRERR_FAILURE;
135 0 : return m_poDecoratedLayer->UpsertFeature(poFeature);
136 : }
137 :
138 0 : OGRErr OGRLayerDecorator::IUpdateFeature(OGRFeature *poFeature,
139 : int nUpdatedFieldsCount,
140 : const int *panUpdatedFieldsIdx,
141 : int nUpdatedGeomFieldsCount,
142 : const int *panUpdatedGeomFieldsIdx,
143 : bool bUpdateStyleString)
144 : {
145 0 : if (!m_poDecoratedLayer)
146 0 : return OGRERR_FAILURE;
147 0 : return m_poDecoratedLayer->UpdateFeature(
148 : poFeature, nUpdatedFieldsCount, panUpdatedFieldsIdx,
149 0 : nUpdatedGeomFieldsCount, panUpdatedGeomFieldsIdx, bUpdateStyleString);
150 : }
151 :
152 38 : OGRErr OGRLayerDecorator::DeleteFeature(GIntBig nFID)
153 : {
154 38 : if (!m_poDecoratedLayer)
155 0 : return OGRERR_FAILURE;
156 38 : return m_poDecoratedLayer->DeleteFeature(nFID);
157 : }
158 :
159 1608 : const char *OGRLayerDecorator::GetName() const
160 : {
161 1608 : if (!m_poDecoratedLayer)
162 0 : return GetDescription();
163 1608 : return m_poDecoratedLayer->GetName();
164 : }
165 :
166 18 : OGRwkbGeometryType OGRLayerDecorator::GetGeomType() const
167 : {
168 18 : if (!m_poDecoratedLayer)
169 0 : return wkbNone;
170 18 : return m_poDecoratedLayer->GetGeomType();
171 : }
172 :
173 452 : const OGRFeatureDefn *OGRLayerDecorator::GetLayerDefn() const
174 : {
175 452 : if (!m_poDecoratedLayer)
176 0 : return nullptr;
177 452 : return m_poDecoratedLayer->GetLayerDefn();
178 : }
179 :
180 65 : const OGRSpatialReference *OGRLayerDecorator::GetSpatialRef() const
181 : {
182 65 : if (!m_poDecoratedLayer)
183 0 : return nullptr;
184 65 : return m_poDecoratedLayer->GetSpatialRef();
185 : }
186 :
187 198 : GIntBig OGRLayerDecorator::GetFeatureCount(int bForce)
188 : {
189 198 : if (!m_poDecoratedLayer)
190 0 : return 0;
191 198 : return m_poDecoratedLayer->GetFeatureCount(bForce);
192 : }
193 :
194 60 : OGRErr OGRLayerDecorator::IGetExtent(int iGeomField, OGREnvelope *psExtent,
195 : bool bForce)
196 : {
197 60 : if (!m_poDecoratedLayer)
198 0 : return OGRERR_FAILURE;
199 60 : return m_poDecoratedLayer->GetExtent(iGeomField, psExtent, bForce);
200 : }
201 :
202 0 : OGRErr OGRLayerDecorator::IGetExtent3D(int iGeomField, OGREnvelope3D *psExtent,
203 : bool bForce)
204 : {
205 0 : if (!m_poDecoratedLayer)
206 0 : return OGRERR_FAILURE;
207 0 : return m_poDecoratedLayer->GetExtent3D(iGeomField, psExtent, bForce);
208 : }
209 :
210 444 : int OGRLayerDecorator::TestCapability(const char *pszCapability) const
211 : {
212 444 : if (!m_poDecoratedLayer)
213 0 : return FALSE;
214 444 : return m_poDecoratedLayer->TestCapability(pszCapability);
215 : }
216 :
217 0 : OGRErr OGRLayerDecorator::CreateField(const OGRFieldDefn *poField,
218 : int bApproxOK)
219 : {
220 0 : if (!m_poDecoratedLayer)
221 0 : return OGRERR_FAILURE;
222 0 : return m_poDecoratedLayer->CreateField(poField, bApproxOK);
223 : }
224 :
225 0 : OGRErr OGRLayerDecorator::DeleteField(int iField)
226 : {
227 0 : if (!m_poDecoratedLayer)
228 0 : return OGRERR_FAILURE;
229 0 : return m_poDecoratedLayer->DeleteField(iField);
230 : }
231 :
232 0 : OGRErr OGRLayerDecorator::ReorderFields(int *panMap)
233 : {
234 0 : if (!m_poDecoratedLayer)
235 0 : return OGRERR_FAILURE;
236 0 : return m_poDecoratedLayer->ReorderFields(panMap);
237 : }
238 :
239 0 : OGRErr OGRLayerDecorator::AlterFieldDefn(int iField,
240 : OGRFieldDefn *poNewFieldDefn,
241 : int nFlagsIn)
242 : {
243 0 : if (!m_poDecoratedLayer)
244 0 : return OGRERR_FAILURE;
245 0 : return m_poDecoratedLayer->AlterFieldDefn(iField, poNewFieldDefn, nFlagsIn);
246 : }
247 :
248 0 : OGRErr OGRLayerDecorator::AlterGeomFieldDefn(
249 : int iGeomField, const OGRGeomFieldDefn *poNewGeomFieldDefn, int nFlagsIn)
250 : {
251 0 : if (!m_poDecoratedLayer)
252 0 : return OGRERR_FAILURE;
253 0 : return m_poDecoratedLayer->AlterGeomFieldDefn(iGeomField,
254 0 : poNewGeomFieldDefn, nFlagsIn);
255 : }
256 :
257 0 : OGRErr OGRLayerDecorator::CreateGeomField(const OGRGeomFieldDefn *poField,
258 : int bApproxOK)
259 : {
260 0 : if (!m_poDecoratedLayer)
261 0 : return OGRERR_FAILURE;
262 0 : return m_poDecoratedLayer->CreateGeomField(poField, bApproxOK);
263 : }
264 :
265 0 : OGRErr OGRLayerDecorator::SyncToDisk()
266 : {
267 0 : if (!m_poDecoratedLayer)
268 0 : return OGRERR_FAILURE;
269 0 : return m_poDecoratedLayer->SyncToDisk();
270 : }
271 :
272 8 : OGRStyleTable *OGRLayerDecorator::GetStyleTable()
273 : {
274 8 : if (!m_poDecoratedLayer)
275 0 : return nullptr;
276 8 : return m_poDecoratedLayer->GetStyleTable();
277 : }
278 :
279 0 : void OGRLayerDecorator::SetStyleTableDirectly(OGRStyleTable *poStyleTable)
280 : {
281 0 : if (!m_poDecoratedLayer)
282 0 : return;
283 0 : m_poDecoratedLayer->SetStyleTableDirectly(poStyleTable);
284 : }
285 :
286 35 : void OGRLayerDecorator::SetStyleTable(OGRStyleTable *poStyleTable)
287 : {
288 35 : if (!m_poDecoratedLayer)
289 0 : return;
290 35 : m_poDecoratedLayer->SetStyleTable(poStyleTable);
291 : }
292 :
293 0 : OGRErr OGRLayerDecorator::StartTransaction()
294 : {
295 0 : if (!m_poDecoratedLayer)
296 0 : return OGRERR_FAILURE;
297 0 : return m_poDecoratedLayer->StartTransaction();
298 : }
299 :
300 0 : OGRErr OGRLayerDecorator::CommitTransaction()
301 : {
302 0 : if (!m_poDecoratedLayer)
303 0 : return OGRERR_FAILURE;
304 0 : return m_poDecoratedLayer->CommitTransaction();
305 : }
306 :
307 0 : OGRErr OGRLayerDecorator::RollbackTransaction()
308 : {
309 0 : if (!m_poDecoratedLayer)
310 0 : return OGRERR_FAILURE;
311 0 : return m_poDecoratedLayer->RollbackTransaction();
312 : }
313 :
314 412 : const char *OGRLayerDecorator::GetFIDColumn() const
315 : {
316 412 : if (!m_poDecoratedLayer)
317 0 : return "";
318 412 : return m_poDecoratedLayer->GetFIDColumn();
319 : }
320 :
321 41 : const char *OGRLayerDecorator::GetGeometryColumn() const
322 : {
323 41 : if (!m_poDecoratedLayer)
324 0 : return "";
325 41 : return m_poDecoratedLayer->GetGeometryColumn();
326 : }
327 :
328 182 : OGRErr OGRLayerDecorator::SetIgnoredFields(CSLConstList papszFields)
329 : {
330 182 : if (!m_poDecoratedLayer)
331 0 : return OGRERR_FAILURE;
332 182 : return m_poDecoratedLayer->SetIgnoredFields(papszFields);
333 : }
334 :
335 71 : char **OGRLayerDecorator::GetMetadata(const char *pszDomain)
336 : {
337 71 : if (!m_poDecoratedLayer)
338 0 : return nullptr;
339 71 : return m_poDecoratedLayer->GetMetadata(pszDomain);
340 : }
341 :
342 10 : CPLErr OGRLayerDecorator::SetMetadata(char **papszMetadata,
343 : const char *pszDomain)
344 : {
345 10 : if (!m_poDecoratedLayer)
346 0 : return CE_Failure;
347 10 : return m_poDecoratedLayer->SetMetadata(papszMetadata, pszDomain);
348 : }
349 :
350 177 : const char *OGRLayerDecorator::GetMetadataItem(const char *pszName,
351 : const char *pszDomain)
352 : {
353 177 : if (!m_poDecoratedLayer)
354 0 : return nullptr;
355 177 : return m_poDecoratedLayer->GetMetadataItem(pszName, pszDomain);
356 : }
357 :
358 0 : CPLErr OGRLayerDecorator::SetMetadataItem(const char *pszName,
359 : const char *pszValue,
360 : const char *pszDomain)
361 : {
362 0 : if (!m_poDecoratedLayer)
363 0 : return CE_Failure;
364 0 : return m_poDecoratedLayer->SetMetadataItem(pszName, pszValue, pszDomain);
365 : }
366 :
367 0 : OGRErr OGRLayerDecorator::Rename(const char *pszNewName)
368 : {
369 0 : if (!m_poDecoratedLayer)
370 0 : return OGRERR_FAILURE;
371 0 : OGRErr eErr = m_poDecoratedLayer->Rename(pszNewName);
372 0 : if (eErr == OGRERR_NONE)
373 : {
374 0 : SetDescription(m_poDecoratedLayer->GetDescription());
375 : }
376 0 : return eErr;
377 : }
378 :
379 : #endif /* #ifndef DOXYGEN_SKIP */
|