forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgnmlayer.cpp
372 lines (316 loc) · 11.3 KB
/
gnmlayer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/******************************************************************************
*
* Project: GDAL/OGR Geography Network support (Geographic Network Model)
* Purpose: GNM layer class.
* Authors: Mikhail Gusev (gusevmihs at gmail dot com)
* Dmitry Baryshnikov, [email protected]
*
******************************************************************************
* Copyright (c) 2014, Mikhail Gusev
* Copyright (c) 2014-2015, NextGIS <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
#include "gnm.h"
#include "gnm_priv.h"
/**
* GNMGenericLayer
*/
GNMGenericLayer::GNMGenericLayer(OGRLayer *poLayer,
GNMGenericNetwork *poNetwork)
: OGRLayer(), m_soLayerName(poLayer->GetName()), m_poLayer(poLayer),
m_poNetwork(poNetwork)
{
}
/**
* ~GNMGenericLayer
*/
GNMGenericLayer::~GNMGenericLayer()
{
}
const char *GNMGenericLayer::GetFIDColumn()
{
return GNM_SYSFIELD_GFID;
}
const char *GNMGenericLayer::GetGeometryColumn()
{
return m_poLayer->GetGeometryColumn();
}
OGRErr GNMGenericLayer::SetIgnoredFields(CSLConstList papszFields)
{
return m_poLayer->SetIgnoredFields(papszFields);
}
OGRErr GNMGenericLayer::Intersection(OGRLayer *pLayerMethod,
OGRLayer *pLayerResult,
char **papszOptions,
GDALProgressFunc pfnProgress,
void *pProgressArg)
{
return m_poLayer->Intersection(pLayerMethod, pLayerResult, papszOptions,
pfnProgress, pProgressArg);
}
OGRErr GNMGenericLayer::Union(OGRLayer *pLayerMethod, OGRLayer *pLayerResult,
char **papszOptions, GDALProgressFunc pfnProgress,
void *pProgressArg)
{
return m_poLayer->Union(pLayerMethod, pLayerResult, papszOptions,
pfnProgress, pProgressArg);
}
OGRErr GNMGenericLayer::SymDifference(OGRLayer *pLayerMethod,
OGRLayer *pLayerResult,
char **papszOptions,
GDALProgressFunc pfnProgress,
void *pProgressArg)
{
return m_poLayer->Union(pLayerMethod, pLayerResult, papszOptions,
pfnProgress, pProgressArg);
}
OGRErr GNMGenericLayer::Identity(OGRLayer *pLayerMethod, OGRLayer *pLayerResult,
char **papszOptions,
GDALProgressFunc pfnProgress,
void *pProgressArg)
{
return m_poLayer->Union(pLayerMethod, pLayerResult, papszOptions,
pfnProgress, pProgressArg);
}
OGRErr GNMGenericLayer::Update(OGRLayer *pLayerMethod, OGRLayer *pLayerResult,
char **papszOptions,
GDALProgressFunc pfnProgress, void *pProgressArg)
{
return m_poLayer->Update(pLayerMethod, pLayerResult, papszOptions,
pfnProgress, pProgressArg);
}
OGRErr GNMGenericLayer::Clip(OGRLayer *pLayerMethod, OGRLayer *pLayerResult,
char **papszOptions, GDALProgressFunc pfnProgress,
void *pProgressArg)
{
return m_poLayer->Clip(pLayerMethod, pLayerResult, papszOptions,
pfnProgress, pProgressArg);
}
OGRErr GNMGenericLayer::Erase(OGRLayer *pLayerMethod, OGRLayer *pLayerResult,
char **papszOptions, GDALProgressFunc pfnProgress,
void *pProgressArg)
{
return m_poLayer->Erase(pLayerMethod, pLayerResult, papszOptions,
pfnProgress, pProgressArg);
}
GIntBig GNMGenericLayer::GetFeaturesRead()
{
return m_poLayer->GetFeaturesRead();
}
int GNMGenericLayer::AttributeFilterEvaluationNeedsGeometry()
{
return m_poLayer->AttributeFilterEvaluationNeedsGeometry();
}
//! @cond Doxygen_Suppress
OGRErr GNMGenericLayer::InitializeIndexSupport(const char *pszVal)
{
return m_poLayer->InitializeIndexSupport(pszVal);
}
OGRLayerAttrIndex *GNMGenericLayer::GetIndex()
{
return m_poLayer->GetIndex();
}
OGRErr GNMGenericLayer::ISetFeature(OGRFeature *poFeature)
{
VALIDATE_POINTER1(poFeature, "GNMGenericLayer::ISetFeature", CE_Failure);
std::map<GNMGFID, GIntBig>::iterator it =
m_mnFIDMap.find(poFeature->GetFID());
if (it == m_mnFIDMap.end())
{
CPLError(CE_Failure, CPLE_IllegalArg,
"The FID " CPL_FRMT_GIB " is invalid", poFeature->GetFID());
return OGRERR_NON_EXISTING_FEATURE;
}
// TODO: check connection rules if feature can be changed.
poFeature->SetFID(it->second);
return m_poLayer->SetFeature(poFeature);
}
OGRErr GNMGenericLayer::ICreateFeature(OGRFeature *poFeature)
{
VALIDATE_POINTER1(poFeature, "GNMGenericLayer::ICreateFeature", CE_Failure);
GNMGFID nFID = m_poNetwork->GetNewGlobalFID();
poFeature->SetFID(nFID);
poFeature->SetField(GNM_SYSFIELD_GFID, nFID);
poFeature->SetField(GNM_SYSFIELD_BLOCKED, GNM_BLOCK_NONE);
if (m_poNetwork->AddFeatureGlobalFID(nFID, GetName()) != CE_None)
return OGRERR_FAILURE;
return m_poLayer->CreateFeature(poFeature);
}
//! @endcond
OGRGeometry *GNMGenericLayer::GetSpatialFilter()
{
return m_poLayer->GetSpatialFilter();
}
void GNMGenericLayer::SetSpatialFilter(OGRGeometry *poGeometry)
{
m_poLayer->SetSpatialFilter(poGeometry);
}
void GNMGenericLayer::SetSpatialFilterRect(double dfMinX, double dfMinY,
double dfMaxX, double dfMaxY)
{
m_poLayer->SetSpatialFilterRect(dfMinX, dfMinY, dfMaxX, dfMaxY);
}
void GNMGenericLayer::SetSpatialFilter(int iGeomField, OGRGeometry *poGeometry)
{
m_poLayer->SetSpatialFilter(iGeomField, poGeometry);
}
void GNMGenericLayer::SetSpatialFilterRect(int iGeomField, double dfMinX,
double dfMinY, double dfMaxX,
double dfMaxY)
{
m_poLayer->SetSpatialFilterRect(iGeomField, dfMinX, dfMinY, dfMaxX, dfMaxY);
}
OGRErr GNMGenericLayer::SetAttributeFilter(const char *pszFilter)
{
return m_poLayer->SetAttributeFilter(pszFilter);
}
void GNMGenericLayer::ResetReading()
{
m_poLayer->ResetReading();
}
OGRFeature *GNMGenericLayer::GetNextFeature()
{
OGRFeature *pFeature = m_poLayer->GetNextFeature();
if (nullptr == pFeature)
return nullptr;
GNMGFID nGFID = pFeature->GetFieldAsGNMGFID(GNM_SYSFIELD_GFID);
m_mnFIDMap[nGFID] = pFeature->GetFID();
pFeature->SetFID(nGFID);
return pFeature;
}
OGRErr GNMGenericLayer::SetNextByIndex(GIntBig nIndex)
{
return m_poLayer->SetNextByIndex(nIndex);
}
OGRErr GNMGenericLayer::DeleteFeature(GIntBig nFID)
{
OGRFeature *poFeature = GetFeature(nFID);
if (nullptr == poFeature)
return CE_Failure;
nFID = poFeature->GetFID();
std::map<GNMGFID, GIntBig>::iterator it = m_mnFIDMap.find(nFID);
if (it == m_mnFIDMap.end())
{
CPLError(CE_Failure, CPLE_IllegalArg,
"The FID " CPL_FRMT_GIB " is invalid", nFID);
return OGRERR_NON_EXISTING_FEATURE;
}
OGRFeature::DestroyFeature(poFeature);
// delete from graph
if (m_poNetwork->DisconnectFeaturesWithId((GNMGFID)nFID) != CE_None)
return CE_Failure;
return m_poLayer->DeleteFeature(it->second);
}
const char *GNMGenericLayer::GetName()
{
return m_soLayerName;
}
OGRwkbGeometryType GNMGenericLayer::GetGeomType()
{
return m_poLayer->GetGeomType();
}
int GNMGenericLayer::FindFieldIndex(const char *pszFieldName, int bExactMatch)
{
return m_poLayer->FindFieldIndex(pszFieldName, bExactMatch);
}
OGRSpatialReference *GNMGenericLayer::GetSpatialRef()
{
return m_poLayer->GetSpatialRef();
}
GIntBig GNMGenericLayer::GetFeatureCount(int bForce)
{
return m_poLayer->GetFeatureCount(bForce);
}
OGRErr GNMGenericLayer::GetExtent(OGREnvelope *psExtent, int bForce)
{
return m_poLayer->GetExtent(psExtent, bForce);
}
OGRErr GNMGenericLayer::GetExtent(int iGeomField, OGREnvelope *psExtent,
int bForce)
{
return m_poLayer->GetExtent(iGeomField, psExtent, bForce);
}
int GNMGenericLayer::TestCapability(const char *pszCapability)
{
return m_poLayer->TestCapability(pszCapability);
}
OGRErr GNMGenericLayer::CreateField(const OGRFieldDefn *poField, int bApproxOK)
{
return m_poLayer->CreateField(poField, bApproxOK);
}
OGRErr GNMGenericLayer::DeleteField(int iField)
{
if (iField == FindFieldIndex(GNM_SYSFIELD_GFID, TRUE))
return OGRERR_UNSUPPORTED_OPERATION;
if (iField == FindFieldIndex(GNM_SYSFIELD_BLOCKED, TRUE))
return OGRERR_UNSUPPORTED_OPERATION;
return m_poLayer->DeleteField(iField);
}
OGRErr GNMGenericLayer::ReorderFields(int *panMap)
{
return m_poLayer->ReorderFields(panMap);
}
OGRErr GNMGenericLayer::AlterFieldDefn(int iField, OGRFieldDefn *poNewFieldDefn,
int nFlagsIn)
{
if (iField == FindFieldIndex(GNM_SYSFIELD_GFID, TRUE))
return OGRERR_UNSUPPORTED_OPERATION;
if (iField == FindFieldIndex(GNM_SYSFIELD_BLOCKED, TRUE))
return OGRERR_UNSUPPORTED_OPERATION;
return m_poLayer->AlterFieldDefn(iField, poNewFieldDefn, nFlagsIn);
}
OGRErr GNMGenericLayer::CreateGeomField(const OGRGeomFieldDefn *poField,
int bApproxOK)
{
return m_poLayer->CreateGeomField(poField, bApproxOK);
}
OGRErr GNMGenericLayer::SyncToDisk()
{
return m_poLayer->SyncToDisk();
}
OGRStyleTable *GNMGenericLayer::GetStyleTable()
{
return m_poLayer->GetStyleTable();
}
void GNMGenericLayer::SetStyleTableDirectly(OGRStyleTable *poStyleTable)
{
return m_poLayer->SetStyleTableDirectly(poStyleTable);
}
void GNMGenericLayer::SetStyleTable(OGRStyleTable *poStyleTable)
{
return m_poLayer->SetStyleTable(poStyleTable);
}
OGRErr GNMGenericLayer::StartTransaction()
{
return m_poLayer->StartTransaction();
}
OGRErr GNMGenericLayer::CommitTransaction()
{
return m_poLayer->CommitTransaction();
}
OGRErr GNMGenericLayer::RollbackTransaction()
{
return m_poLayer->RollbackTransaction();
}
OGRFeatureDefn *GNMGenericLayer::GetLayerDefn()
{
// TODO: hide GNM_SYSFIELD_GFID filed
return m_poLayer->GetLayerDefn();
}