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 672 : OGRLayerDecorator::OGRLayerDecorator(OGRLayer *poDecoratedLayer,
19 0 : int bTakeOwnership)
20 672 : : m_poDecoratedLayer(poDecoratedLayer), m_bHasOwnership(bTakeOwnership)
21 : {
22 672 : CPLAssert(poDecoratedLayer != nullptr);
23 672 : SetDescription(poDecoratedLayer->GetDescription());
24 672 : }
25 :
26 672 : OGRLayerDecorator::~OGRLayerDecorator()
27 : {
28 672 : if (m_bHasOwnership)
29 410 : delete m_poDecoratedLayer;
30 672 : }
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 182 : OGRErr OGRLayerDecorator::ISetSpatialFilter(int iGeomField,
40 : const OGRGeometry *poGeom)
41 : {
42 182 : if (!m_poDecoratedLayer)
43 0 : return OGRERR_FAILURE;
44 182 : return m_poDecoratedLayer->SetSpatialFilter(iGeomField, poGeom);
45 : }
46 :
47 581 : OGRErr OGRLayerDecorator::SetAttributeFilter(const char *poAttrFilter)
48 : {
49 581 : if (!m_poDecoratedLayer)
50 0 : return OGRERR_FAILURE;
51 581 : return m_poDecoratedLayer->SetAttributeFilter(poAttrFilter);
52 : }
53 :
54 998 : void OGRLayerDecorator::ResetReading()
55 : {
56 998 : if (!m_poDecoratedLayer)
57 0 : return;
58 998 : m_poDecoratedLayer->ResetReading();
59 : }
60 :
61 2198 : OGRFeature *OGRLayerDecorator::GetNextFeature()
62 : {
63 2198 : if (!m_poDecoratedLayer)
64 0 : return nullptr;
65 2198 : 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 0 : OGRErr OGRLayerDecorator::ICreateFeature(OGRFeature *poFeature)
108 : {
109 0 : if (!m_poDecoratedLayer)
110 0 : return OGRERR_FAILURE;
111 0 : return m_poDecoratedLayer->CreateFeature(poFeature);
112 : }
113 :
114 0 : OGRErr OGRLayerDecorator::IUpsertFeature(OGRFeature *poFeature)
115 : {
116 0 : if (!m_poDecoratedLayer)
117 0 : return OGRERR_FAILURE;
118 0 : return m_poDecoratedLayer->UpsertFeature(poFeature);
119 : }
120 :
121 0 : OGRErr OGRLayerDecorator::IUpdateFeature(OGRFeature *poFeature,
122 : int nUpdatedFieldsCount,
123 : const int *panUpdatedFieldsIdx,
124 : int nUpdatedGeomFieldsCount,
125 : const int *panUpdatedGeomFieldsIdx,
126 : bool bUpdateStyleString)
127 : {
128 0 : if (!m_poDecoratedLayer)
129 0 : return OGRERR_FAILURE;
130 0 : return m_poDecoratedLayer->UpdateFeature(
131 : poFeature, nUpdatedFieldsCount, panUpdatedFieldsIdx,
132 0 : nUpdatedGeomFieldsCount, panUpdatedGeomFieldsIdx, bUpdateStyleString);
133 : }
134 :
135 38 : OGRErr OGRLayerDecorator::DeleteFeature(GIntBig nFID)
136 : {
137 38 : if (!m_poDecoratedLayer)
138 0 : return OGRERR_FAILURE;
139 38 : return m_poDecoratedLayer->DeleteFeature(nFID);
140 : }
141 :
142 1586 : const char *OGRLayerDecorator::GetName()
143 : {
144 1586 : if (!m_poDecoratedLayer)
145 0 : return GetDescription();
146 1586 : return m_poDecoratedLayer->GetName();
147 : }
148 :
149 18 : OGRwkbGeometryType OGRLayerDecorator::GetGeomType()
150 : {
151 18 : if (!m_poDecoratedLayer)
152 0 : return wkbNone;
153 18 : return m_poDecoratedLayer->GetGeomType();
154 : }
155 :
156 424 : OGRFeatureDefn *OGRLayerDecorator::GetLayerDefn()
157 : {
158 424 : if (!m_poDecoratedLayer)
159 0 : return nullptr;
160 424 : return m_poDecoratedLayer->GetLayerDefn();
161 : }
162 :
163 37 : OGRSpatialReference *OGRLayerDecorator::GetSpatialRef()
164 : {
165 37 : if (!m_poDecoratedLayer)
166 0 : return nullptr;
167 37 : return m_poDecoratedLayer->GetSpatialRef();
168 : }
169 :
170 198 : GIntBig OGRLayerDecorator::GetFeatureCount(int bForce)
171 : {
172 198 : if (!m_poDecoratedLayer)
173 0 : return 0;
174 198 : return m_poDecoratedLayer->GetFeatureCount(bForce);
175 : }
176 :
177 60 : OGRErr OGRLayerDecorator::IGetExtent(int iGeomField, OGREnvelope *psExtent,
178 : bool bForce)
179 : {
180 60 : if (!m_poDecoratedLayer)
181 0 : return OGRERR_FAILURE;
182 60 : return m_poDecoratedLayer->GetExtent(iGeomField, psExtent, bForce);
183 : }
184 :
185 0 : OGRErr OGRLayerDecorator::IGetExtent3D(int iGeomField, OGREnvelope3D *psExtent,
186 : bool bForce)
187 : {
188 0 : if (!m_poDecoratedLayer)
189 0 : return OGRERR_FAILURE;
190 0 : return m_poDecoratedLayer->GetExtent3D(iGeomField, psExtent, bForce);
191 : }
192 :
193 420 : int OGRLayerDecorator::TestCapability(const char *pszCapability)
194 : {
195 420 : if (!m_poDecoratedLayer)
196 0 : return FALSE;
197 420 : return m_poDecoratedLayer->TestCapability(pszCapability);
198 : }
199 :
200 0 : OGRErr OGRLayerDecorator::CreateField(const OGRFieldDefn *poField,
201 : int bApproxOK)
202 : {
203 0 : if (!m_poDecoratedLayer)
204 0 : return OGRERR_FAILURE;
205 0 : return m_poDecoratedLayer->CreateField(poField, bApproxOK);
206 : }
207 :
208 0 : OGRErr OGRLayerDecorator::DeleteField(int iField)
209 : {
210 0 : if (!m_poDecoratedLayer)
211 0 : return OGRERR_FAILURE;
212 0 : return m_poDecoratedLayer->DeleteField(iField);
213 : }
214 :
215 0 : OGRErr OGRLayerDecorator::ReorderFields(int *panMap)
216 : {
217 0 : if (!m_poDecoratedLayer)
218 0 : return OGRERR_FAILURE;
219 0 : return m_poDecoratedLayer->ReorderFields(panMap);
220 : }
221 :
222 0 : OGRErr OGRLayerDecorator::AlterFieldDefn(int iField,
223 : OGRFieldDefn *poNewFieldDefn,
224 : int nFlagsIn)
225 : {
226 0 : if (!m_poDecoratedLayer)
227 0 : return OGRERR_FAILURE;
228 0 : return m_poDecoratedLayer->AlterFieldDefn(iField, poNewFieldDefn, nFlagsIn);
229 : }
230 :
231 0 : OGRErr OGRLayerDecorator::AlterGeomFieldDefn(
232 : int iGeomField, const OGRGeomFieldDefn *poNewGeomFieldDefn, int nFlagsIn)
233 : {
234 0 : if (!m_poDecoratedLayer)
235 0 : return OGRERR_FAILURE;
236 0 : return m_poDecoratedLayer->AlterGeomFieldDefn(iGeomField,
237 0 : poNewGeomFieldDefn, nFlagsIn);
238 : }
239 :
240 0 : OGRErr OGRLayerDecorator::CreateGeomField(const OGRGeomFieldDefn *poField,
241 : int bApproxOK)
242 : {
243 0 : if (!m_poDecoratedLayer)
244 0 : return OGRERR_FAILURE;
245 0 : return m_poDecoratedLayer->CreateGeomField(poField, bApproxOK);
246 : }
247 :
248 0 : OGRErr OGRLayerDecorator::SyncToDisk()
249 : {
250 0 : if (!m_poDecoratedLayer)
251 0 : return OGRERR_FAILURE;
252 0 : return m_poDecoratedLayer->SyncToDisk();
253 : }
254 :
255 4 : OGRStyleTable *OGRLayerDecorator::GetStyleTable()
256 : {
257 4 : if (!m_poDecoratedLayer)
258 0 : return nullptr;
259 4 : return m_poDecoratedLayer->GetStyleTable();
260 : }
261 :
262 0 : void OGRLayerDecorator::SetStyleTableDirectly(OGRStyleTable *poStyleTable)
263 : {
264 0 : if (!m_poDecoratedLayer)
265 0 : return;
266 0 : m_poDecoratedLayer->SetStyleTableDirectly(poStyleTable);
267 : }
268 :
269 32 : void OGRLayerDecorator::SetStyleTable(OGRStyleTable *poStyleTable)
270 : {
271 32 : if (!m_poDecoratedLayer)
272 0 : return;
273 32 : m_poDecoratedLayer->SetStyleTable(poStyleTable);
274 : }
275 :
276 0 : OGRErr OGRLayerDecorator::StartTransaction()
277 : {
278 0 : if (!m_poDecoratedLayer)
279 0 : return OGRERR_FAILURE;
280 0 : return m_poDecoratedLayer->StartTransaction();
281 : }
282 :
283 0 : OGRErr OGRLayerDecorator::CommitTransaction()
284 : {
285 0 : if (!m_poDecoratedLayer)
286 0 : return OGRERR_FAILURE;
287 0 : return m_poDecoratedLayer->CommitTransaction();
288 : }
289 :
290 0 : OGRErr OGRLayerDecorator::RollbackTransaction()
291 : {
292 0 : if (!m_poDecoratedLayer)
293 0 : return OGRERR_FAILURE;
294 0 : return m_poDecoratedLayer->RollbackTransaction();
295 : }
296 :
297 371 : const char *OGRLayerDecorator::GetFIDColumn()
298 : {
299 371 : if (!m_poDecoratedLayer)
300 0 : return "";
301 371 : return m_poDecoratedLayer->GetFIDColumn();
302 : }
303 :
304 35 : const char *OGRLayerDecorator::GetGeometryColumn()
305 : {
306 35 : if (!m_poDecoratedLayer)
307 0 : return "";
308 35 : return m_poDecoratedLayer->GetGeometryColumn();
309 : }
310 :
311 230 : OGRErr OGRLayerDecorator::SetIgnoredFields(CSLConstList papszFields)
312 : {
313 230 : if (!m_poDecoratedLayer)
314 0 : return OGRERR_FAILURE;
315 230 : return m_poDecoratedLayer->SetIgnoredFields(papszFields);
316 : }
317 :
318 53 : char **OGRLayerDecorator::GetMetadata(const char *pszDomain)
319 : {
320 53 : if (!m_poDecoratedLayer)
321 0 : return nullptr;
322 53 : return m_poDecoratedLayer->GetMetadata(pszDomain);
323 : }
324 :
325 6 : CPLErr OGRLayerDecorator::SetMetadata(char **papszMetadata,
326 : const char *pszDomain)
327 : {
328 6 : if (!m_poDecoratedLayer)
329 0 : return CE_Failure;
330 6 : return m_poDecoratedLayer->SetMetadata(papszMetadata, pszDomain);
331 : }
332 :
333 140 : const char *OGRLayerDecorator::GetMetadataItem(const char *pszName,
334 : const char *pszDomain)
335 : {
336 140 : if (!m_poDecoratedLayer)
337 0 : return nullptr;
338 140 : return m_poDecoratedLayer->GetMetadataItem(pszName, pszDomain);
339 : }
340 :
341 0 : CPLErr OGRLayerDecorator::SetMetadataItem(const char *pszName,
342 : const char *pszValue,
343 : const char *pszDomain)
344 : {
345 0 : if (!m_poDecoratedLayer)
346 0 : return CE_Failure;
347 0 : return m_poDecoratedLayer->SetMetadataItem(pszName, pszValue, pszDomain);
348 : }
349 :
350 0 : OGRErr OGRLayerDecorator::Rename(const char *pszNewName)
351 : {
352 0 : if (!m_poDecoratedLayer)
353 0 : return OGRERR_FAILURE;
354 0 : OGRErr eErr = m_poDecoratedLayer->Rename(pszNewName);
355 0 : if (eErr == OGRERR_NONE)
356 : {
357 0 : SetDescription(m_poDecoratedLayer->GetDescription());
358 : }
359 0 : return eErr;
360 : }
361 :
362 : #endif /* #ifndef DOXYGEN_SKIP */
|