Debian Codegraph @

ogr/ogrsf_frmts/ili/ogrili1layer.cpp

raw symbols SCIP
1 /******************************************************************************
2 *
3 * Project: Interlis 1 Translator
4 * Purpose: Implements OGRILI1Layer class.
5 * Author: Pirmin Kalberer, Sourcepole AG
6 *
7 ******************************************************************************
8 * Copyright (c) 2004, Pirmin Kalberer, Sourcepole AG
9 * Copyright (c) 2008-2013, Even Rouault <even dot rouault at spatialys.com>
10 *
11 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14 #include "cpl_conv.h"cxx . . $ `<file>/port/cpl_conv.h`/
15 #include "cpl_string.h"cxx . . $ `<file>/port/cpl_string.h`/
16 #include "ogr_geos.h"cxx . . $ `<file>/ogr/ogr_geos.h`/
17 #include "ogr_ili1.h"cxx . . $ `<file>/ogr/ogrsf_frmts/ili/ogr_ili1.h`/
18
19 #include <map>
20 #include <vector>
21
22 /************************************************************************/
23 /* OGRILI1Layer() */
24 /************************************************************************/
25
26 OGRILI1Layercxx . . $ OGRILI1Layer#::OGRILI1Layercxx . . $ OGRILI1Layer#OGRILI1Layer(2d2f6f91f998b025).(OGRFeatureDefncxx . . $ OGRFeatureDefn# *poFeatureDefnIn,
27 const GeomFieldInfoscxx . . $ GeomFieldInfos# &oGeomFieldInfosIn,
28 OGRILI1DataSourcecxx . . $ OGRILI1DataSource# *poDSIn)
29 : poFeatureDefncxx . . $ OGRILI1Layer#poFeatureDefn.(poFeatureDefnIn), oGeomFieldInfoscxx . . $ OGRILI1Layer#oGeomFieldInfos.(oGeomFieldInfosIn),
30 nFeaturescxx . . $ OGRILI1Layer#nFeatures.(0), papoFeaturescxx . . $ OGRILI1Layer#papoFeatures.(nullptr), nFeatureIdxcxx . . $ OGRILI1Layer#nFeatureIdx.(0), bGeomsJoinedcxx . . $ OGRILI1Layer#bGeomsJoined.(FALSEcxx . . $ `port/cpl_port.h:1180:9`!),
31 poDScxx . . $ OGRILI1Layer#poDS.(poDSIn)
32 {
33 SetDescriptioncxx . . $ GDALMajorObject#SetDescription(85c52e162fed56f9).(poFeatureDefncxx . . $ OGRILI1Layer#poFeatureDefn.->GetNamecxx . . $ OGRFeatureDefn#GetName(a9f41ea0e82d88cf).());
34 poFeatureDefncxx . . $ OGRILI1Layer#poFeatureDefn.->Referencecxx . . $ OGRFeatureDefn#Reference(b126dc7c1de90089).();
35 }
36
37 /************************************************************************/
38 /* ~OGRILI1Layer() */
39 /************************************************************************/
40
41 OGRILI1Layercxx . . $ OGRILI1Layer#::~cxx . . $ OGRILI1Layer#`~OGRILI1Layer`(ced63f7c635d850d).OGRILI1Layercxx . . $ OGRILI1Layer#()
42 {
43 for (int i = 0; i < nFeaturescxx . . $ OGRILI1Layer#nFeatures.; i++)
44 {
45 delete papoFeaturescxx . . $ OGRILI1Layer#papoFeatures.[i];
46 }
47 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(papoFeaturescxx . . $ OGRILI1Layer#papoFeatures.);
48
49 if (poFeatureDefncxx . . $ OGRILI1Layer#poFeatureDefn.)
50 poFeatureDefncxx . . $ OGRILI1Layer#poFeatureDefn.->Releasecxx . . $ OGRFeatureDefn#Release(49f6e7a06ebc5aa8).();
51 }
52
53 OGRErr OGRILI1Layercxx . . $ OGRILI1Layer#::AddFeaturecxx . . $ OGRILI1Layer#AddFeature(2048609adab03aab).(OGRFeaturecxx . . $ OGRFeature# *poFeature)
54 {
55 nFeaturescxx . . $ OGRILI1Layer#nFeatures.++;
56
57 papoFeaturescxx . . $ OGRILI1Layer#papoFeatures. = static_cast<OGRFeaturecxx . . $ OGRFeature# **>(
58 CPLRealloc(papoFeaturescxx . . $ OGRILI1Layer#papoFeatures., sizeof(void *) * nFeaturescxx . . $ OGRILI1Layer#nFeatures.));
59
60 papoFeaturescxx . . $ OGRILI1Layer#papoFeatures.[nFeaturescxx . . $ OGRILI1Layer#nFeatures. - 1] = poFeature;
61
62 return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!;
63 }
64
65 /************************************************************************/
66 /* ResetReading() */
67 /************************************************************************/
68
69 void OGRILI1Layercxx . . $ OGRILI1Layer#::ResetReadingcxx . . $ OGRILI1Layer#ResetReading(49f6e7a06ebc5aa8).()
70 {
71 nFeatureIdxcxx . . $ OGRILI1Layer#nFeatureIdx. = 0;
72 }
73
74 /************************************************************************/
75 /* GetNextFeature() */
76 /************************************************************************/
77
78 OGRFeaturecxx . . $ OGRFeature# *OGRILI1Layercxx . . $ OGRILI1Layer#::GetNextFeaturecxx . . $ OGRILI1Layer#GetNextFeature(ec9eceddec1d9563).()
79 {
80 if (!bGeomsJoinedcxx . . $ OGRILI1Layer#bGeomsJoined.)
81 JoinGeomLayerscxx . . $ OGRILI1Layer#JoinGeomLayers(49f6e7a06ebc5aa8).();
82
83 while (nFeatureIdxcxx . . $ OGRILI1Layer#nFeatureIdx. < nFeaturescxx . . $ OGRILI1Layer#nFeatures.)
84 {
85 OGRFeaturecxx . . $ OGRFeature# *poFeature = GetNextFeatureRefcxx . . $ OGRILI1Layer#GetNextFeatureRef(ec9eceddec1d9563).();
86 if (poFeature)
87 return poFeature->Clonecxx . . $ OGRFeature#Clone(bcd776315d3947b8).();
88 }
89 return nullptr;
90 }
91
92 OGRFeaturecxx . . $ OGRFeature# *OGRILI1Layercxx . . $ OGRILI1Layer#::GetNextFeatureRefcxx . . $ OGRILI1Layer#GetNextFeatureRef(ec9eceddec1d9563).()
93 {
94 OGRFeaturecxx . . $ OGRFeature# *poFeature = nullptr;
95 if (nFeatureIdxcxx . . $ OGRILI1Layer#nFeatureIdx. < nFeaturescxx . . $ OGRILI1Layer#nFeatures.)
96 {
97 poFeature = papoFeaturescxx . . $ OGRILI1Layer#papoFeatures.[nFeatureIdxcxx . . $ OGRILI1Layer#nFeatureIdx.++];
98 // apply filters
99 if ((m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. == nullptr ||
100 FilterGeometrycxx . . $ OGRLayer#FilterGeometry(fed901b2566802ff).(poFeature->GetGeometryRefcxx . . $ OGRFeature#GetGeometryRef(3dfc1d32c7db2584).())) &&
101 (m_poAttrQuerycxx . . $ OGRLayer#m_poAttrQuery. == nullptr || m_poAttrQuerycxx . . $ OGRLayer#m_poAttrQuery.->Evaluatecxx . . $ OGRFeatureQuery#Evaluate(2048609adab03aab).(poFeature)))
102 return poFeature;
103 }
104 return nullptr;
105 }
106
107 /************************************************************************/
108 /* GetFeatureRef() */
109 /************************************************************************/
110
111 OGRFeaturecxx . . $ OGRFeature# *OGRILI1Layercxx . . $ OGRILI1Layer#::GetFeatureRefcxx . . $ OGRILI1Layer#GetFeatureRef(86ac52c37891ada7).(GIntBigcxx . . $ GIntBig# nFID)
112
113 {
114 ResetReadingcxx . . $ OGRILI1Layer#ResetReading(49f6e7a06ebc5aa8).();
115
116 OGRFeaturecxx . . $ OGRFeature# *poFeature = nullptr;
117 while ((poFeature = GetNextFeatureRefcxx . . $ OGRILI1Layer#GetNextFeatureRef(ec9eceddec1d9563).()) != nullptr)
118 {
119 if (poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).() == nFID)
120 return poFeature;
121 }
122
123 return nullptr;
124 }
125
126 OGRFeaturecxx . . $ OGRFeature# *OGRILI1Layercxx . . $ OGRILI1Layer#::GetFeatureRefcxx . . $ OGRILI1Layer#GetFeatureRef(abcb54832bf2c223).(const char *fid)
127
128 {
129 ResetReadingcxx . . $ OGRILI1Layer#ResetReading(49f6e7a06ebc5aa8).();
130
131 OGRFeaturecxx . . $ OGRFeature# *poFeature = nullptr;
132 while ((poFeature = GetNextFeatureRefcxx . . $ OGRILI1Layer#GetNextFeatureRef(ec9eceddec1d9563).()) != nullptr)
133 {
134 if (!strcmp(poFeature->GetFieldAsStringcxx . . $ OGRFeature#GetFieldAsString(afbf07f2bc1a9437).(0), fid))
135 return poFeature;
136 }
137
138 return nullptr;
139 }
140
141 /************************************************************************/
142 /* GetFeatureCount() */
143 /************************************************************************/
144
145 GIntBigcxx . . $ GIntBig# OGRILI1Layercxx . . $ OGRILI1Layer#::GetFeatureCountcxx . . $ OGRILI1Layer#GetFeatureCount(9ccc33c3ebad048d).(int bForce)
146 {
147 if (m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. == nullptr && m_poAttrQuerycxx . . $ OGRLayer#m_poAttrQuery. == nullptr
148 /* && poAreaLineLayer == NULL*/)
149 {
150 return nFeaturescxx . . $ OGRILI1Layer#nFeatures.;
151 }
152 else
153 {
154 return OGRLayercxx . . $ OGRLayer#::GetFeatureCountcxx . . $ OGRLayer#GetFeatureCount(9ccc33c3ebad048d).(bForce);
155 }
156 }
157
158 /************************************************************************/
159 /* TestCapability() */
160 /************************************************************************/
161
162 int OGRILI1Layercxx . . $ OGRILI1Layer#::TestCapabilitycxx . . $ OGRILI1Layer#TestCapability(78f035161ffa9fe2).(const char *pszCap) const
163 {
164 if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCCurveGeometriescxx . . $ `ogr/ogr_core.h:1023:9`!))
165 return TRUEcxx . . $ `port/cpl_port.h:1184:9`!;
166 if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCZGeometriescxx . . $ `ogr/ogr_core.h:1028:9`!))
167 return TRUEcxx . . $ `port/cpl_port.h:1184:9`!;
168
169 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
170 }
171
172 /************************************************************************/
173 /* Internal routines */
174 /************************************************************************/
175
176 void OGRILI1Layercxx . . $ OGRILI1Layer#::JoinGeomLayerscxx . . $ OGRILI1Layer#JoinGeomLayers(49f6e7a06ebc5aa8).()
177 {
178 bGeomsJoinedcxx . . $ OGRILI1Layer#bGeomsJoined. = true;
179
180 CPLConfigOptionSetter oSetter("OGR_ARC_STEPSIZE", "0.96",
181 /* bSetOnlyIfUndefined = */ true);
182
183 for (GeomFieldInfoscxx . . $ GeomFieldInfos#::const_iteratorcxx . . $ std/map#const_iterator# it = oGeomFieldInfoscxx . . $ std/_Rb_tree_const_iterator#_Rb_tree_const_iterator(dc529b7882ffd73b)..begincxx . . $ std/map#begin(7e4de33083b6e738).();
184 it !=cxx . . $ std/`operator!=`(a84eb84a7a5e8237). oGeomFieldInfoscxx . . $ std/_Rb_tree_const_iterator#_Rb_tree_const_iterator(dc529b7882ffd73b)..endcxx . . $ std/map#end(7e4de33083b6e738).(); ++cxx . . $ std/_Rb_tree_const_iterator#operator++(9cb79ab07bb244bf).it)
185 {
186 OGRFeatureDefncxx . . $ OGRFeatureDefn# *geomFeatureDefn = it->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).second.GetGeomTableDefnRefcxx . . $ GeomFieldInfo#GetGeomTableDefnRef(df2524e70945a265).();
187 if (geomFeatureDefn)
188 {
189 CPLDebug("OGR_ILI", "Join geometry table %s of field '%s'",
190 geomFeatureDefn->GetNamecxx . . $ OGRFeatureDefn#GetName(a9f41ea0e82d88cf).(), it->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).first.c_str());
191 OGRILI1Layercxx . . $ OGRILI1Layer# *poGeomLayer =
192 poDScxx . . $ OGRILI1Layer#poDS.->GetLayerByNamecxx . . $ OGRILI1DataSource#GetLayerByName(22769fe554addabe).(geomFeatureDefn->GetNamecxx . . $ OGRFeatureDefn#GetName(a9f41ea0e82d88cf).());
193 const int nGeomFieldIndex =
194 GetLayerDefncxx . . $ OGRLayer#GetLayerDefn(407fccde18759965).()->GetGeomFieldIndexcxx . . $ OGRFeatureDefn#GetGeomFieldIndex(78f035161ffa9fe2).(it->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).first.c_str());
195 if (it->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).second.iliGeomTypecxx . . $ GeomFieldInfo#iliGeomType. == "Surface")
196 {
197 JoinSurfaceLayercxx . . $ OGRILI1Layer#JoinSurfaceLayer(3e9191173dc6f63f).(poGeomLayer, nGeomFieldIndex);
198 }
199 else if (it->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).second.iliGeomTypecxx . . $ GeomFieldInfo#iliGeomType. == "Area")
200 {
201 CPLString pointField = it->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).first + "__Point";
202 const int nPointFieldIndex =
203 GetLayerDefncxx . . $ OGRLayer#GetLayerDefn(407fccde18759965).()->GetGeomFieldIndexcxx . . $ OGRFeatureDefn#GetGeomFieldIndex(78f035161ffa9fe2).(pointField.c_str());
204 PolygonizeAreaLayercxx . . $ OGRILI1Layer#PolygonizeAreaLayer(6e8c02cfd600561b).(poGeomLayer, nGeomFieldIndex,
205 nPointFieldIndex);
206 }
207 }
208 }
209 }
210
211 void OGRILI1Layercxx . . $ OGRILI1Layer#::JoinSurfaceLayercxx . . $ OGRILI1Layer#JoinSurfaceLayer(3e9191173dc6f63f).(OGRILI1Layercxx . . $ OGRILI1Layer# *poSurfaceLineLayer,
212 int nSurfaceFieldIndex)
213 {
214 CPLDebug("OGR_ILI", "Joining surface layer %s with geometries",
215 GetLayerDefncxx . . $ OGRLayer#GetLayerDefn(407fccde18759965).()->GetNamecxx . . $ OGRFeatureDefn#GetName(a9f41ea0e82d88cf).());
216 OGRwkbGeometryType geomType =
217 GetLayerDefncxx . . $ OGRLayer#GetLayerDefn(407fccde18759965).()->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(nSurfaceFieldIndex)->GetTypecxx . . $ OGRGeomFieldDefn#GetType(5a40c54c5ff210ce).();
218
219 stdcxx . . $ std/::mapcxx . . $ std/map#<OGRFeaturecxx . . $ OGRFeature# *, stdcxx . . $ std/::vector<OGRCurvecxx . . $ OGRCurve# *>> oMapFeatureToGeomSetcxx . . $ std/map#map(49f6e7a06ebc5aa8).;
220
221 poSurfaceLineLayer->ResetReadingcxx . . $ OGRILI1Layer#ResetReading(49f6e7a06ebc5aa8).();
222
223 // First map: for each target curvepolygon, find all belonging curves
224 while (OGRFeaturecxx . . $ OGRFeature# *linefeature = poSurfaceLineLayer->GetNextFeatureRefcxx . . $ OGRILI1Layer#GetNextFeatureRef(ec9eceddec1d9563).())
225 {
226 // OBJE entries with same _RefTID are polygon rings of same feature
227 OGRFeaturecxx . . $ OGRFeature# *feature = nullptr;
228 if (poFeatureDefncxx . . $ OGRILI1Layer#poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(0)->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTString)
229 {
230 feature = GetFeatureRefcxx . . $ OGRILI1Layer#GetFeatureRef(abcb54832bf2c223).(linefeature->GetFieldAsStringcxx . . $ OGRFeature#GetFieldAsString(afbf07f2bc1a9437).(1));
231 }
232 else
233 {
234 GIntBigcxx . . $ GIntBig# reftid = linefeature->GetFieldAsInteger64cxx . . $ OGRFeature#GetFieldAsInteger64(f3f16611d465c84c).(1);
235 feature = GetFeatureRefcxx . . $ OGRILI1Layer#GetFeatureRef(86ac52c37891ada7).(reftid);
236 }
237 if (feature)
238 {
239 OGRGeometrycxx . . $ OGRGeometry# *poGeom = linefeature->GetGeomFieldRefcxx . . $ OGRFeature#GetGeomFieldRef(ea443ccec24c6360).(0);
240 OGRMultiCurvecxx . . $ OGRMultiCurve# *curves = dynamic_cast<OGRMultiCurvecxx . . $ OGRMultiCurve# *>(poGeom);
241 if (curves)
242 {
243 for (auto &&curve : curves)
244 {
245 if (!curve->IsEmptycxx . . $ OGRGeometry#IsEmpty(455f465bc33b4cdf).())
246 oMapFeatureToGeomSet[cxx . . $ std/map#`operator[]`(bbd415b616967878).feature].push_back(curve);
247 }
248 }
249 }
250 else
251 {
252 CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!,
253 "Couldn't join feature FID " CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`!,
254 linefeature->GetFieldAsInteger64cxx . . $ OGRFeature#GetFieldAsInteger64(f3f16611d465c84c).(1));
255 }
256 }
257
258 // Now for each target polygon, assemble the curves together.
259 stdcxx . . $ std/::mapcxx . . $ std/map#<OGRFeature *, std::vector<OGRCurve *>>::const_iteratorcxx . . $ std/map#const_iterator# oIter =
260 oMapFeatureToGeomSetcxx . . $ std/_Rb_tree_const_iterator#_Rb_tree_const_iterator(dc529b7882ffd73b)..begincxx . . $ std/map#begin(7e4de33083b6e738).();
261 for (; oIter !=cxx . . $ std/`operator!=`(a84eb84a7a5e8237). oMapFeatureToGeomSetcxx . . $ std/_Rb_tree_const_iterator#_Rb_tree_const_iterator(dc529b7882ffd73b)..endcxx . . $ std/map#end(7e4de33083b6e738).(); ++cxx . . $ std/_Rb_tree_const_iterator#operator++(9cb79ab07bb244bf).oIter)
262 {
263 OGRFeaturecxx . . $ OGRFeature# *feature = oIter->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).first;
264 stdcxx . . $ std/::vector<OGRCurvecxx . . $ OGRCurve# *> oCurves = oIter->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).second;
265
266 stdcxx . . $ std/::vector<OGRCurvecxx . . $ OGRCurve# *> oSetDestCurves;
267 double dfLargestArea = 0.0;
268 OGRCurvecxx . . $ OGRCurve# *poLargestCurve = nullptr;
269 while (true)
270 {
271 stdcxx . . $ std/::vector<OGRCurve *>::iterator oIterCurves = oCurves.begin();
272 if (oIterCurves == oCurves.end())
273 break;
274
275 OGRPointcxx . . $ OGRPoint# endPointCCcxx . . $ OGRPoint#OGRPoint(49f6e7a06ebc5aa8).;
276 OGRCompoundCurvecxx . . $ OGRCompoundCurve# *poCC = new OGRCompoundCurvecxx . . $ OGRCompoundCurve#OGRCompoundCurve(49f6e7a06ebc5aa8).();
277
278 bool bFirst = true;
279 while (true)
280 {
281 bool bNewCurveAdded = false;
282 const double dfEps = 1e-14;
283 for (oIterCurves = oCurves.begin();
284 oIterCurves != oCurves.end(); ++oIterCurves)
285 {
286 OGRCurvecxx . . $ OGRCurve# *curve = *oIterCurves;
287 OGRPointcxx . . $ OGRPoint# startPointcxx . . $ OGRPoint#OGRPoint(49f6e7a06ebc5aa8).;
288 OGRPointcxx . . $ OGRPoint# endPointcxx . . $ OGRPoint#OGRPoint(49f6e7a06ebc5aa8).;
289 curve->StartPointcxx . . $ OGRCurve#StartPoint(f684dfc4658939be).(&startPoint);
290 curve->EndPointcxx . . $ OGRCurve#EndPoint(f684dfc4658939be).(&endPoint);
291 if (bFirst ||
292 (fabscxx . . $ fabs(fee4f1d22bc8e617).(startPoint.getXcxx . . $ OGRPoint#getX(21b6c25e127938e2).() - endPointCC.getXcxx . . $ OGRPoint#getX(21b6c25e127938e2).()) < dfEps &&
293 fabscxx . . $ fabs(fee4f1d22bc8e617).(startPoint.getYcxx . . $ OGRPoint#getY(21b6c25e127938e2).() - endPointCC.getYcxx . . $ OGRPoint#getY(21b6c25e127938e2).()) < dfEps))
294 {
295 bFirst = false;
296
297 curve->EndPointcxx . . $ OGRCurve#EndPoint(f684dfc4658939be).(&endPointCC);
298
299 const OGRwkbGeometryType eCurveType =
300 wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!(curve->getGeometryType());
301 if (eCurveType == wkbCompoundCurve)
302 {
303 OGRCompoundCurvecxx . . $ OGRCompoundCurve# *poCCSub =
304 curve->toCompoundCurvecxx . . $ OGRGeometry#toCompoundCurve(f420d930cef762f7).();
305 for (auto &&subCurve : poCCSub)
306 {
307 poCC->addCurvecxx . . $ OGRCompoundCurve#addCurve(86651797a7420928).(subCurve);
308 }
309 }
310 else
311 {
312 poCC->addCurvecxx . . $ OGRCompoundCurve#addCurve(86651797a7420928).(curve);
313 }
314 oCurves.erase(oIterCurves);
315 bNewCurveAdded = true;
316 break;
317 }
318 else if (fabscxx . . $ fabs(fee4f1d22bc8e617).(endPoint.getXcxx . . $ OGRPoint#getX(21b6c25e127938e2).() - endPointCC.getXcxx . . $ OGRPoint#getX(21b6c25e127938e2).()) <
319 dfEps &&
320 fabscxx . . $ fabs(fee4f1d22bc8e617).(endPoint.getYcxx . . $ OGRPoint#getY(21b6c25e127938e2).() - endPointCC.getYcxx . . $ OGRPoint#getY(21b6c25e127938e2).()) < dfEps)
321 {
322 curve->StartPointcxx . . $ OGRCurve#StartPoint(f684dfc4658939be).(&endPointCC);
323
324 const OGRwkbGeometryType eCurveType =
325 wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!(curve->getGeometryType());
326 if (eCurveType == wkbLineString ||
327 eCurveType == wkbCircularString)
328 {
329 OGRSimpleCurvecxx . . $ OGRSimpleCurve# *poSC =
330 curve->toSimpleCurvecxx . . $ OGRCurve#toSimpleCurve(4cd73d5fa03b5bad).()->clonecxx . . $ OGRSimpleCurve#clone(9781ff08489aedd3).();
331 poSC->reversePointscxx . . $ OGRSimpleCurve#reversePoints(49f6e7a06ebc5aa8).();
332 poCC->addCurveDirectlycxx . . $ OGRCompoundCurve#addCurveDirectly(4d58c58bd53f5672).(poSC);
333 }
334 else if (eCurveType == wkbCompoundCurve)
335 {
336 // Reverse the order of the elements of the
337 // compound curve
338 OGRCompoundCurvecxx . . $ OGRCompoundCurve# *poCCSub =
339 curve->toCompoundCurvecxx . . $ OGRGeometry#toCompoundCurve(f420d930cef762f7).();
340 for (int i = poCCSub->getNumCurvescxx . . $ OGRCompoundCurve#getNumCurves(455f465bc33b4cdf).() - 1; i >= 0;
341 --i)
342 {
343 OGRSimpleCurvecxx . . $ OGRSimpleCurve# *poSC = poCCSub->getCurvecxx . . $ OGRCompoundCurve#getCurve(89fccc3d00c4654b).(i)
344 ->toSimpleCurvecxx . . $ OGRCurve#toSimpleCurve(4cd73d5fa03b5bad).()
345 ->clonecxx . . $ OGRSimpleCurve#clone(9781ff08489aedd3).();
346 poSC->reversePointscxx . . $ OGRSimpleCurve#reversePoints(49f6e7a06ebc5aa8).();
347 poCC->addCurveDirectlycxx . . $ OGRCompoundCurve#addCurveDirectly(4d58c58bd53f5672).(poSC);
348 }
349 }
350
351 oCurves.erase(oIterCurves);
352 bNewCurveAdded = true;
353 break;
354 }
355 }
356 if (!bNewCurveAdded || oCurves.empty() || poCC->get_IsClosedcxx . . $ OGRCurve#get_IsClosed(455f465bc33b4cdf).())
357 break;
358 }
359
360 if (!poCC->get_IsClosedcxx . . $ OGRCurve#get_IsClosed(455f465bc33b4cdf).())
361 {
362 char *pszJSon = poCC->exportToJsoncxx . . $ OGRGeometry#exportToJson(93cd719b7158384e).();
363 CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!,
364 "A ring %s for feature " CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! " in layer %s "
365 "was not closed. Dropping it",
366 pszJSon, feature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).(), GetNamecxx . . $ OGRLayer#GetName(a9f41ea0e82d88cf).());
367 delete poCC;
368 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszJSon);
369 }
370 else
371 {
372 double dfArea = poCC->get_Areacxx . . $ OGRCompoundCurve#get_Area(21b6c25e127938e2).();
373 if (dfArea >= dfLargestArea)
374 {
375 dfLargestArea = dfArea;
376 poLargestCurve = poCC;
377 }
378 oSetDestCurves.push_back(poCC);
379 }
380 }
381
382 // Now build the final polygon by first inserting the largest ring.
383 OGRCurvePolygoncxx . . $ OGRCurvePolygon# *poPoly =
384 (geomType == wkbPolygon) ? new OGRPolygoncxx . . $ OGRPolygon#OGRPolygon(49f6e7a06ebc5aa8).() : new OGRCurvePolygoncxx . . $ OGRCurvePolygon#OGRCurvePolygon(49f6e7a06ebc5aa8).();
385 if (poLargestCurve)
386 {
387 stdcxx . . $ std/::vector<OGRCurve *>::iterator oIterCurves =
388 oSetDestCurves.begin();
389 for (; oIterCurves != oSetDestCurves.end(); ++oIterCurves)
390 {
391 OGRCurvecxx . . $ OGRCurve# *poCurve = *oIterCurves;
392 if (poCurve == poLargestCurve)
393 {
394 oSetDestCurves.erase(oIterCurves);
395 break;
396 }
397 }
398
399 if (geomType == wkbPolygon)
400 {
401 poLargestCurve = OGRCurvecxx . . $ OGRCurve#::CastToLinearRingcxx . . $ OGRCurve#CastToLinearRing(f9244d9516d6dfa1).(poLargestCurve);
402 }
403 OGRErr error = poPoly->addRingDirectlycxx . . $ OGRCurvePolygon#addRingDirectly(2f65f96c58d3f239).(poLargestCurve);
404 if (error != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!)
405 {
406 char *pszJSon = poLargestCurve->exportToJsoncxx . . $ OGRGeometry#exportToJson(93cd719b7158384e).();
407 CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!,
408 "Cannot add ring %s to feature " CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`!
409 " in layer %s",
410 pszJSon, feature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).(), GetNamecxx . . $ OGRLayer#GetName(a9f41ea0e82d88cf).());
411 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszJSon);
412 }
413
414 oIterCurves = oSetDestCurves.begin();
415 for (; oIterCurves != oSetDestCurves.end(); ++oIterCurves)
416 {
417 OGRCurvecxx . . $ OGRCurve# *poCurve = *oIterCurves;
418 if (geomType == wkbPolygon)
419 {
420 poCurve = OGRCurvecxx . . $ OGRCurve#::CastToLinearRingcxx . . $ OGRCurve#CastToLinearRing(f9244d9516d6dfa1).(poCurve);
421 }
422 error = poPoly->addRingDirectlycxx . . $ OGRCurvePolygon#addRingDirectly(2f65f96c58d3f239).(poCurve);
423 if (error != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!)
424 {
425 char *pszJSon = poCurve->exportToJsoncxx . . $ OGRGeometry#exportToJson(93cd719b7158384e).();
426 CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!,
427 "Cannot add ring %s to feature " CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`!
428 " in layer %s",
429 pszJSon, feature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).(), GetNamecxx . . $ OGRLayer#GetName(a9f41ea0e82d88cf).());
430 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszJSon);
431 }
432 }
433 }
434
435 feature->SetGeomFieldDirectlycxx . . $ OGRFeature#SetGeomFieldDirectly(98e5e580b88dff4e).(nSurfaceFieldIndex, poPoly);
436 }
437
438 ResetReadingcxx . . $ OGRILI1Layer#ResetReading(49f6e7a06ebc5aa8).();
439 }
440
441 OGRMultiPolygoncxx . . $ OGRMultiPolygon# *OGRILI1Layercxx . . $ OGRILI1Layer#::Polygonizecxx . . $ OGRILI1Layer#Polygonize(15590671deebb338).(OGRGeometryCollectioncxx . . $ OGRGeometryCollection# *poLines,
442 bool
443 #if defined(HAVE_GEOScxx . . $ `<built-in>:483:9`!)
444 fix_crossing_lines
445 #endif
446 )
447 {
448 if (poLines->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).() == 0)
449 {
450 return new OGRMultiPolygoncxx . . $ OGRMultiPolygon#OGRMultiPolygon(49f6e7a06ebc5aa8).();
451 }
452
453 #if defined(HAVE_GEOScxx . . $ `<built-in>:483:9`!)
454 GEOSGeomcxx . . $ GEOSGeom# *ahInGeoms = nullptr;
455 OGRGeometryCollectioncxx . . $ OGRGeometryCollection# *poNoncrossingLines = poLines;
456 GEOSGeomcxx . . $ GEOSGeom# hResultGeom = nullptr;
457 OGRGeometrycxx . . $ OGRGeometry# *poMP = nullptr;
458
459 if (fix_crossing_lines && poLines->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).() > 0)
460 {
461 CPLDebug("OGR_ILI", "Fixing crossing lines");
462 // A union of the geometry collection with one line fixes
463 // invalid geometries.
464 OGRGeometrycxx . . $ OGRGeometry# *poUnion = poLines->Unioncxx . . $ OGRGeometry#Union(56846f9bc045ff64).(poLines->getGeometryRefcxx . . $ OGRGeometryCollection#getGeometryRef(ea443ccec24c6360).(0));
465 if (poUnion != nullptr)
466 {
467 if (wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!(poUnion->getGeometryType()) ==
468 wkbGeometryCollection ||
469 wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!(poUnion->getGeometryType()) == wkbMultiLineString)
470 {
471 poNoncrossingLines =
472 dynamic_cast<OGRGeometryCollectioncxx . . $ OGRGeometryCollection# *>(poUnion);
473 CPLDebug("OGR_ILI", "Fixed lines: %d",
474 poNoncrossingLines->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).() -
475 poLines->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).());
476 }
477 else
478 {
479 delete poUnion;
480 }
481 }
482 }
483
484 GEOSContextHandle_tcxx . . $ GEOSContextHandle_t# hGEOSCtxt = OGRGeometrycxx . . $ OGRGeometry#::createGEOSContextcxx . . $ OGRGeometry#createGEOSContext(ca83928f457800be).();
485
486 ahInGeoms = static_cast<GEOSGeomcxx . . $ GEOSGeom# *>(
487 CPLCalloc(sizeof(void *), poNoncrossingLines->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).()));
488 for (int i = 0; i < poNoncrossingLines->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).(); i++)
489 ahInGeoms[i] =
490 poNoncrossingLines->getGeometryRefcxx . . $ OGRGeometryCollection#getGeometryRef(ea443ccec24c6360).(i)->exportToGEOScxx . . $ OGRGeometry#exportToGEOS(58e0cef0dc8050fb).(hGEOSCtxt);
491
492 hResultGeom = GEOSPolygonize_r(hGEOSCtxt, ahInGeoms,
493 poNoncrossingLines->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).());
494
495 for (int i = 0; i < poNoncrossingLines->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).(); i++)
496 GEOSGeom_destroy_r(hGEOSCtxt, ahInGeoms[i]);
497 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(ahInGeoms);
498 if (poNoncrossingLines != poLines)
499 delete poNoncrossingLines;
500
501 if (hResultGeom == nullptr)
502 {
503 OGRGeometrycxx . . $ OGRGeometry#::freeGEOSContextcxx . . $ OGRGeometry#freeGEOSContext(3f598d35b50be6e7).(hGEOSCtxt);
504 return new OGRMultiPolygoncxx . . $ OGRMultiPolygon#OGRMultiPolygon(49f6e7a06ebc5aa8).();
505 }
506
507 poMP = OGRGeometryFactorycxx . . $ OGRGeometryFactory#::createFromGEOScxx . . $ OGRGeometryFactory#createFromGEOS(f82f72aba36a8768).(hGEOSCtxt, hResultGeom);
508
509 GEOSGeom_destroy_r(hGEOSCtxt, hResultGeom);
510 OGRGeometrycxx . . $ OGRGeometry#::freeGEOSContextcxx . . $ OGRGeometry#freeGEOSContext(3f598d35b50be6e7).(hGEOSCtxt);
511
512 poMP = OGRGeometryFactorycxx . . $ OGRGeometryFactory#::forceToMultiPolygoncxx . . $ OGRGeometryFactory#forceToMultiPolygon(7e6837eba2cca85f).(poMP);
513 if (poMP && wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!(poMP->getGeometryType()) == wkbMultiPolygon)
514 return dynamic_cast<OGRMultiPolygoncxx . . $ OGRMultiPolygon# *>(poMP);
515
516 delete poMP;
517 return new OGRMultiPolygoncxx . . $ OGRMultiPolygon#OGRMultiPolygon(49f6e7a06ebc5aa8).();
518
519 #else
520 return new OGRMultiPolygon();
521 #endif
522 }
523
524 void OGRILI1Layercxx . . $ OGRILI1Layer#::PolygonizeAreaLayercxx . . $ OGRILI1Layer#PolygonizeAreaLayer(6e8c02cfd600561b).(OGRILI1Layercxx . . $ OGRILI1Layer# *poAreaLineLayer,
525 int
526 #if defined(HAVE_GEOScxx . . $ `<built-in>:483:9`!)
527 nAreaFieldIndex
528 #endif
529 ,
530 int
531 #if defined(HAVE_GEOScxx . . $ `<built-in>:483:9`!)
532 nPointFieldIndex
533 #endif
534 )
535 {
536 // add all lines from poAreaLineLayer to collection
537 OGRGeometryCollectioncxx . . $ OGRGeometryCollection# *gc = new OGRGeometryCollectioncxx . . $ OGRGeometryCollection#OGRGeometryCollection(49f6e7a06ebc5aa8).();
538 poAreaLineLayer->ResetReadingcxx . . $ OGRILI1Layer#ResetReading(49f6e7a06ebc5aa8).();
539 while (OGRFeaturecxx . . $ OGRFeature# *feature = poAreaLineLayer->GetNextFeatureRefcxx . . $ OGRILI1Layer#GetNextFeatureRef(ec9eceddec1d9563).())
540 gc->addGeometrycxx . . $ OGRGeometryCollection#addGeometry(fed901b2566802ff).(feature->GetGeometryRefcxx . . $ OGRFeature#GetGeometryRef(3dfc1d32c7db2584).());
541
542 // polygonize lines
543 CPLDebug("OGR_ILI", "Polygonizing layer %s with %d multilines",
544 poAreaLineLayer->GetLayerDefncxx . . $ OGRLayer#GetLayerDefn(407fccde18759965).()->GetNamecxx . . $ OGRFeatureDefn#GetName(a9f41ea0e82d88cf).(),
545 gc->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).());
546 poAreaLineLayer = nullptr;
547 OGRMultiPolygoncxx . . $ OGRMultiPolygon# *polys = Polygonizecxx . . $ OGRILI1Layer#Polygonize(15590671deebb338).(gc, false);
548 CPLDebug("OGR_ILI", "Resulting polygons: %d", polys->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).());
549 if (polys->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).() != GetFeatureCountcxx . . $ OGRILI1Layer#GetFeatureCount(9ccc33c3ebad048d).())
550 {
551 CPLDebug("OGR_ILI", "Feature count of layer %s: " CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`!,
552 GetLayerDefncxx . . $ OGRLayer#GetLayerDefn(407fccde18759965).()->GetNamecxx . . $ OGRFeatureDefn#GetName(a9f41ea0e82d88cf).(), GetFeatureCountcxx . . $ OGRILI1Layer#GetFeatureCount(9ccc33c3ebad048d).());
553 CPLDebug("OGR_ILI", "Polygonizing again with crossing line fix");
554 delete polys;
555 polys = Polygonizecxx . . $ OGRILI1Layer#Polygonize(15590671deebb338).(gc, true); // try again with crossing line fix
556 CPLDebug("OGR_ILI", "Resulting polygons: %d",
557 polys->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).());
558 }
559 delete gc;
560
561 // associate polygon feature with data row according to centroid
562 #if defined(HAVE_GEOScxx . . $ `<built-in>:483:9`!)
563 OGRPolygoncxx . . $ OGRPolygon# emptyPolycxx . . $ OGRPolygon#OGRPolygon(49f6e7a06ebc5aa8).;
564
565 CPLDebug("OGR_ILI", "Associating layer %s with area polygons",
566 GetLayerDefncxx . . $ OGRLayer#GetLayerDefn(407fccde18759965).()->GetNamecxx . . $ OGRFeatureDefn#GetName(a9f41ea0e82d88cf).());
567 GEOSGeomcxx . . $ GEOSGeom# *ahInGeoms = static_cast<GEOSGeomcxx . . $ GEOSGeom# *>(
568 CPLCalloc(sizeof(void *), polys->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).()));
569 GEOSContextHandle_tcxx . . $ GEOSContextHandle_t# hGEOSCtxt = OGRGeometrycxx . . $ OGRGeometry#::createGEOSContextcxx . . $ OGRGeometry#createGEOSContext(ca83928f457800be).();
570 for (int i = 0; i < polys->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).(); i++)
571 {
572 ahInGeoms[i] = polys->getGeometryRefcxx . . $ OGRMultiPolygon#getGeometryRef(5aba10be3506df50).(i)->exportToGEOScxx . . $ OGRGeometry#exportToGEOS(58e0cef0dc8050fb).(hGEOSCtxt);
573 if (!GEOSisValid_r(hGEOSCtxt, ahInGeoms[i]))
574 ahInGeoms[i] = nullptr;
575 }
576 for (int nFidx = 0; nFidx < nFeaturescxx . . $ OGRILI1Layer#nFeatures.; nFidx++)
577 {
578 OGRFeaturecxx . . $ OGRFeature# *feature = papoFeaturescxx . . $ OGRILI1Layer#papoFeatures.[nFidx];
579 OGRGeometrycxx . . $ OGRGeometry# *geomRef = feature->GetGeomFieldRefcxx . . $ OGRFeature#GetGeomFieldRef(ea443ccec24c6360).(nPointFieldIndex);
580 if (!geomRef)
581 {
582 continue;
583 }
584 GEOSGeomcxx . . $ GEOSGeom# point =
585 reinterpret_cast<GEOSGeomcxx . . $ GEOSGeom#>(geomRef->exportToGEOScxx . . $ OGRGeometry#exportToGEOS(58e0cef0dc8050fb).(hGEOSCtxt));
586
587 int i = 0;
588 for (; i < polys->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).(); i++)
589 {
590 if (ahInGeoms[i] && GEOSWithin_r(hGEOSCtxt, point, ahInGeoms[i]))
591 {
592 feature->SetGeomFieldcxx . . $ OGRFeature#SetGeomField(896393ecef503097).(nAreaFieldIndex,
593 polys->getGeometryRefcxx . . $ OGRMultiPolygon#getGeometryRef(5aba10be3506df50).(i));
594 break;
595 }
596 }
597 if (i == polys->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).())
598 {
599 CPLDebug("OGR_ILI", "Association between area and point failed.");
600 feature->SetGeometrycxx . . $ OGRFeature#SetGeometry(fed901b2566802ff).(&emptyPoly);
601 }
602 GEOSGeom_destroy_r(hGEOSCtxt, point);
603 }
604 for (int i = 0; i < polys->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).(); i++)
605 GEOSGeom_destroy_r(hGEOSCtxt, ahInGeoms[i]);
606 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(ahInGeoms);
607 OGRGeometrycxx . . $ OGRGeometry#::freeGEOSContextcxx . . $ OGRGeometry#freeGEOSContext(3f598d35b50be6e7).(hGEOSCtxt);
608 #endif
609 delete polys;
610 }
611
612 /************************************************************************/
613 /* GetDataset() */
614 /************************************************************************/
615
616 GDALDatasetcxx . . $ GDALDataset# *OGRILI1Layercxx . . $ OGRILI1Layer#::GetDatasetcxx . . $ OGRILI1Layer#GetDataset(76c1989f6ffbc048).()
617 {
618 return poDScxx . . $ OGRILI1Layer#poDS.;
619 }