Debian Codegraph @

ogr/ogrsf_frmts/kml/ogrkmldatasource.cpp

raw symbols SCIP
1 /******************************************************************************
2 *
3 * Project: KML Driver
4 * Purpose: Implementation of OGRKMLDataSource class.
5 * Author: Christopher Condit, [email protected];
6 * Jens Oberender, [email protected]
7 *
8 ******************************************************************************
9 * Copyright (c) 2006, Christopher Condit
10 * 2007, Jens Oberender
11 * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
12 *
13 * SPDX-License-Identifier: MIT
14 ****************************************************************************/
15 #include "cpl_port.h"cxx . . $ `<file>/port/cpl_port.h`/
16 #include "ogr_kml.h"cxx . . $ `<file>/ogr/ogrsf_frmts/kml/ogr_kml.h`/
17
18 #include <cstring>
19 #include <string>
20
21 #include "cpl_conv.h"cxx . . $ `<file>/port/cpl_conv.h`/
22 #include "cpl_error.h"cxx . . $ `<file>/port/cpl_error.h`/
23 #include "cpl_minixml.h"cxx . . $ `<file>/port/cpl_minixml.h`/
24 #include "cpl_string.h"cxx . . $ `<file>/port/cpl_string.h`/
25 #include "cpl_vsi.h"cxx . . $ `<file>/port/cpl_vsi.h`/
26 #include "cpl_vsi_error.h"cxx . . $ `<file>/port/cpl_vsi_error.h`/
27 #include "ogr_core.h"cxx . . $ `<file>/ogr/ogr_core.h`/
28 #include "ogr_spatialref.h"cxx . . $ `<file>/ogr/ogr_spatialref.h`/
29 #include "kml.h"cxx . . $ `<file>/ogr/ogrsf_frmts/kml/kml.h`/
30 #include "kmlutility.h"cxx . . $ `<file>/ogr/ogrsf_frmts/kml/kmlutility.h`/
31 #include "kmlvector.h"cxx . . $ `<file>/ogr/ogrsf_frmts/kml/kmlvector.h`/
32 #include "ogrsf_frmts.h"cxx . . $ `<file>/ogr/ogrsf_frmts/ogrsf_frmts.h`/
33
34 /************************************************************************/
35 /* OGRKMLDataSource() */
36 /************************************************************************/
37
38 OGRKMLDataSourcecxx . . $ OGRKMLDataSource#::OGRKMLDataSourcecxx . . $ OGRKMLDataSource#OGRKMLDataSource(49f6e7a06ebc5aa8).() = default;
39
40 /************************************************************************/
41 /* ~OGRKMLDataSource() */
42 /************************************************************************/
43
44 OGRKMLDataSourcecxx . . $ OGRKMLDataSource#::~cxx . . $ OGRKMLDataSource#`~OGRKMLDataSource`(ced63f7c635d850d).OGRKMLDataSourcecxx . . $ OGRKMLDataSource#()
45 {
46 if (fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_. != nullptr)
47 {
48 if (nLayers_cxx . . $ OGRKMLDataSource#nLayers_. > 0)
49 {
50 if (nLayers_cxx . . $ OGRKMLDataSource#nLayers_. == 1 && papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.[0]->nWroteFeatureCount_cxx . . $ OGRKMLLayer#nWroteFeatureCount_. == 0)
51 {
52 VSIFPrintfL(fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_., "<Folder><name>%s</name>\n",
53 papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.[0]->GetNamecxx . . $ OGRLayer#GetName(a9f41ea0e82d88cf).());
54 }
55
56 VSIFPrintfL(fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_., "%s", "</Folder>\n");
57
58 for (int i = 0; i < nLayers_cxx . . $ OGRKMLDataSource#nLayers_.; i++)
59 {
60 if (!(papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.[i]->bSchemaWritten_cxx . . $ OGRKMLLayer#bSchemaWritten_.) &&
61 papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.[i]->nWroteFeatureCount_cxx . . $ OGRKMLLayer#nWroteFeatureCount_. != 0)
62 {
63 CPLString osRet = papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.[i]->WriteSchemacxx . . $ OGRKMLLayer#WriteSchema(cdfd1e859161399b).();
64 if (!osRet.empty())
65 VSIFPrintfL(fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_., "%s", osRet.c_str());
66 }
67 }
68 }
69 VSIFPrintfL(fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_., "%s", "</Document></kml>\n");
70
71 VSIFCloseL(fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_.);
72 }
73
74 CSLDestroy(papszCreateOptions_cxx . . $ OGRKMLDataSource#papszCreateOptions_.);
75 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszNameField_cxx . . $ OGRKMLDataSource#pszNameField_.);
76 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszDescriptionField_cxx . . $ OGRKMLDataSource#pszDescriptionField_.);
77 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszAltitudeMode_cxx . . $ OGRKMLDataSource#pszAltitudeMode_.);
78
79 for (int i = 0; i < nLayers_cxx . . $ OGRKMLDataSource#nLayers_.; i++)
80 {
81 delete papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.[i];
82 }
83
84 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.);
85
86 #ifdef HAVE_EXPATcxx . . $ `<built-in>:483:9`!
87 delete poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.;
88 #endif
89 }
90
91 /************************************************************************/
92 /* Open() */
93 /************************************************************************/
94
95 #ifdef HAVE_EXPATcxx . . $ `<built-in>:483:9`!
96 int OGRKMLDataSourcecxx . . $ OGRKMLDataSource#::Opencxx . . $ OGRKMLDataSource#Open(cb7559238bb26814).(const char *pszNewName, int bTestOpen)
97 {
98 CPLAssertcxx . . $ `port/cpl_error.h:353:9`!(nullptr != pszNewName);
99
100 /* -------------------------------------------------------------------- */
101 /* Create a KML object and open the source file. */
102 /* -------------------------------------------------------------------- */
103 poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_. = new KMLVectorcxx . . $ KMLVector#();
104
105 if (!poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->opencxx . . $ KML#open(c5f7da30cbc0f4e9).(pszNewName))
106 {
107 delete poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.;
108 poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_. = nullptr;
109 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
110 }
111
112 /* -------------------------------------------------------------------- */
113 /* If we aren't sure it is KML, validate it by start parsing */
114 /* -------------------------------------------------------------------- */
115 if (bTestOpen && !poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->isValidcxx . . $ KML#isValid(c9857a73d68e59ba).())
116 {
117 delete poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.;
118 poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_. = nullptr;
119 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
120 }
121
122 /* -------------------------------------------------------------------- */
123 /* Prescan the KML file so we can later work with the structure */
124 /* -------------------------------------------------------------------- */
125 if (!poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->parsecxx . . $ KML#parse(c9857a73d68e59ba).())
126 {
127 delete poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.;
128 poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_. = nullptr;
129 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
130 }
131
132 /* -------------------------------------------------------------------- */
133 /* Classify the nodes */
134 /* -------------------------------------------------------------------- */
135 if (!poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->classifyNodescxx . . $ KML#classifyNodes(b126dc7c1de90089).())
136 {
137 delete poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.;
138 poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_. = nullptr;
139 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
140 }
141
142 /* -------------------------------------------------------------------- */
143 /* Eliminate the empty containers (if there is at least one */
144 /* valid container !) */
145 /* -------------------------------------------------------------------- */
146 const bool bHasOnlyEmpty = poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->hasOnlyEmptycxx . . $ KML#hasOnlyEmpty(50ce9a9e25b4a850).();
147 if (bHasOnlyEmpty)
148 CPLDebug("KML", "Has only empty containers");
149 else
150 poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->eliminateEmptycxx . . $ KML#eliminateEmpty(49f6e7a06ebc5aa8).();
151
152 /* -------------------------------------------------------------------- */
153 /* Find layers to use in the KML structure */
154 /* -------------------------------------------------------------------- */
155 poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->findLayerscxx . . $ KML#findLayers(5de86920d35a041f).(nullptr, bHasOnlyEmpty);
156
157 /* -------------------------------------------------------------------- */
158 /* Print the structure */
159 /* -------------------------------------------------------------------- */
160 if (CPLGetConfigOption("KML_DEBUG", nullptr) != nullptr)
161 poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->printcxx . . $ KML#print(ed53e3bbd3fa2f69).(3);
162
163 const int nLayers = poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->getNumLayerscxx . . $ KML#getNumLayers(455f465bc33b4cdf).();
164
165 /* -------------------------------------------------------------------- */
166 /* Allocate memory for the Layers */
167 /* -------------------------------------------------------------------- */
168 papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_. =
169 static_cast<OGRKMLLayercxx . . $ OGRKMLLayer# **>(CPLMalloc(sizeof(OGRKMLLayercxx . . $ OGRKMLLayer# *) * nLayers));
170
171 OGRSpatialReferencecxx . . $ OGRSpatialReference# *poSRS =
172 new OGRSpatialReferencecxx . . $ OGRSpatialReference#OGRSpatialReference(85c52e162fed56f9).(SRS_WKT_WGS84_LAT_LONGcxx . . $ `ogr/ogr_srs_api.h:63:9`!);
173 poSRS->SetAxisMappingStrategycxx . . $ OGRSpatialReference#SetAxisMappingStrategy(3d39f43974738d6a).(OAMS_TRADITIONAL_GIS_ORDER);
174
175 /* -------------------------------------------------------------------- */
176 /* Create the Layers and fill them */
177 /* -------------------------------------------------------------------- */
178 for (int nCount = 0; nCount < nLayers; nCount++)
179 {
180 if (!poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->selectLayercxx . . $ KML#selectLayer(83c267b20bac841a).(nCount))
181 {
182 CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!,
183 "There are no layers or a layer can not be found!");
184 break;
185 }
186
187 OGRwkbGeometryType poGeotype = wkbUnknown;
188 if (poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->getCurrentTypecxx . . $ KML#getCurrentType(f38676a9ab40e3).() == Pointcxx . . $ OGRKML/Point.)
189 poGeotype = wkbPoint;
190 else if (poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->getCurrentTypecxx . . $ KML#getCurrentType(f38676a9ab40e3).() == LineStringcxx . . $ OGRKML/LineString.)
191 poGeotype = wkbLineString;
192 else if (poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->getCurrentTypecxx . . $ KML#getCurrentType(f38676a9ab40e3).() == Polygoncxx . . $ OGRKML/Polygon.)
193 poGeotype = wkbPolygon;
194 else if (poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->getCurrentTypecxx . . $ KML#getCurrentType(f38676a9ab40e3).() == MultiPointcxx . . $ OGRKML/MultiPoint.)
195 poGeotype = wkbMultiPoint;
196 else if (poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->getCurrentTypecxx . . $ KML#getCurrentType(f38676a9ab40e3).() == MultiLineStringcxx . . $ OGRKML/MultiLineString.)
197 poGeotype = wkbMultiLineString;
198 else if (poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->getCurrentTypecxx . . $ KML#getCurrentType(f38676a9ab40e3).() == MultiPolygoncxx . . $ OGRKML/MultiPolygon.)
199 poGeotype = wkbMultiPolygon;
200 else if (poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->getCurrentTypecxx . . $ KML#getCurrentType(f38676a9ab40e3).() == MultiGeometrycxx . . $ OGRKML/MultiGeometry.)
201 poGeotype = wkbGeometryCollection;
202
203 if (poGeotype != wkbUnknown && poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->is25Dcxx . . $ KML#is25D(455f465bc33b4cdf).())
204 poGeotype = wkbSetZcxx . . $ `ogr/ogr_core.h:585:9`!(poGeotype);
205
206 /* --------------------------------------------------------------------
207 */
208 /* Create the layer object. */
209 /* --------------------------------------------------------------------
210 */
211 CPLString sName(poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->getCurrentNamecxx . . $ KML#getCurrentName(219584694fe2b248).());
212
213 if (sName.empty())
214 {
215 sName.Printf("Layer #%d", nCount);
216 }
217 else
218 {
219 // Build unique layer name
220 int nIter = 2;
221 while (true)
222 {
223 if (GetLayerByNamecxx . . $ GDALDataset#GetLayerByName(5ddf27af0841fa5b).(sName) == nullptr)
224 break;
225 sName = CPLSPrintf("%s (#%d)",
226 poKMLFile_cxx . . $ OGRKMLDataSource#poKMLFile_.->getCurrentNamecxx . . $ KML#getCurrentName(219584694fe2b248).().c_str(), nIter);
227 nIter++;
228 }
229 }
230
231 OGRKMLLayercxx . . $ OGRKMLLayer# *poLayer =
232 new OGRKMLLayercxx . . $ OGRKMLLayer#(sName.c_str(), poSRS, false, poGeotype, this);
233
234 poLayer->SetLayerNumbercxx . . $ OGRKMLLayer#SetLayerNumber(d4f767463ce0a6b3).(nCount);
235
236 /* --------------------------------------------------------------------
237 */
238 /* Add layer to data source layer list. */
239 /* --------------------------------------------------------------------
240 */
241 papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.[nCount] = poLayer;
242
243 nLayers_cxx . . $ OGRKMLDataSource#nLayers_. = nCount + 1;
244 }
245
246 poSRS->Releasecxx . . $ OGRSpatialReference#Release(49f6e7a06ebc5aa8).();
247
248 return TRUEcxx . . $ `port/cpl_port.h:1184:9`!;
249 }
250 #endif /* HAVE_EXPAT */
251
252 /************************************************************************/
253 /* Create() */
254 /************************************************************************/
255
256 int OGRKMLDataSourcecxx . . $ OGRKMLDataSource#::Createcxx . . $ OGRKMLDataSource#Create(5a7b06e3ce74da13).(const char *pszName, CSLConstListcxx . . $ CSLConstList# papszOptions)
257 {
258 CPLAssertcxx . . $ `port/cpl_error.h:353:9`!(nullptr != pszName);
259
260 if (fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_. != nullptr)
261 {
262 CPLAssertcxx . . $ `port/cpl_error.h:353:9`!(false);
263 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
264 }
265
266 if (CSLFetchNameValue(papszOptions, "NameField"))
267 pszNameField_cxx . . $ OGRKMLDataSource#pszNameField_. = CPLStrdup(CSLFetchNameValue(papszOptions, "NameField"));
268 else
269 pszNameField_cxx . . $ OGRKMLDataSource#pszNameField_. = CPLStrdup("Name");
270
271 if (CSLFetchNameValue(papszOptions, "DescriptionField"))
272 pszDescriptionField_cxx . . $ OGRKMLDataSource#pszDescriptionField_. =
273 CPLStrdup(CSLFetchNameValue(papszOptions, "DescriptionField"));
274 else
275 pszDescriptionField_cxx . . $ OGRKMLDataSource#pszDescriptionField_. = CPLStrdup("Description");
276
277 pszAltitudeMode_cxx . . $ OGRKMLDataSource#pszAltitudeMode_. =
278 CPLStrdup(CSLFetchNameValue(papszOptions, "AltitudeMode"));
279 if ((nullptr != pszAltitudeMode_cxx . . $ OGRKMLDataSource#pszAltitudeMode_.) && strlen(pszAltitudeMode_cxx . . $ OGRKMLDataSource#pszAltitudeMode_.) > 0)
280 {
281 // Check to see that the specified AltitudeMode is valid
282 if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszAltitudeMode_, "clampToGround") ||
283 EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszAltitudeMode_, "relativeToGround") ||
284 EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszAltitudeMode_, "absolute"))
285 {
286 CPLDebug("KML", "Using '%s' for AltitudeMode", pszAltitudeMode_cxx . . $ OGRKMLDataSource#pszAltitudeMode_.);
287 }
288 else
289 {
290 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszAltitudeMode_cxx . . $ OGRKMLDataSource#pszAltitudeMode_.);
291 pszAltitudeMode_cxx . . $ OGRKMLDataSource#pszAltitudeMode_. = nullptr;
292 CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!,
293 "Invalid AltitudeMode specified, ignoring");
294 }
295 }
296 else
297 {
298 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszAltitudeMode_cxx . . $ OGRKMLDataSource#pszAltitudeMode_.);
299 pszAltitudeMode_cxx . . $ OGRKMLDataSource#pszAltitudeMode_. = nullptr;
300 }
301
302 /* -------------------------------------------------------------------- */
303 /* Create the output file. */
304 /* -------------------------------------------------------------------- */
305
306 if (strcmp(pszName, "/dev/stdout") == 0)
307 pszName = "/vsistdout/";
308
309 fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_. = VSIFOpenExL(pszName, "wb", true);
310 if (fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_. == nullptr)
311 {
312 CPLError(CE_Failure, CPLE_OpenFailedcxx . . $ `port/cpl_error.h:114:9`!,
313 "Failed to create KML file %s: %s", pszName,
314 VSIGetLastErrorMsg());
315 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
316 }
317
318 /* -------------------------------------------------------------------- */
319 /* Write out "standard" header. */
320 /* -------------------------------------------------------------------- */
321 VSIFPrintfL(fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_., "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
322
323 VSIFPrintfL(fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_.,
324 "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n"
325 "<Document id=\"%s\">\n",
326 CSLFetchNameValueDef(papszOptions, "DOCUMENT_ID", "root_doc"));
327
328 return TRUEcxx . . $ `port/cpl_port.h:1184:9`!;
329 }
330
331 /************************************************************************/
332 /* ICreateLayer() */
333 /************************************************************************/
334
335 OGRLayercxx . . $ OGRLayer# *
336 OGRKMLDataSourcecxx . . $ OGRKMLDataSource#::ICreateLayercxx . . $ OGRKMLDataSource#ICreateLayer(d0342318947b6f88).(const char *pszLayerName,
337 const OGRGeomFieldDefncxx . . $ OGRGeomFieldDefn# *poGeomFieldDefn,
338 CSLConstListcxx . . $ CSLConstList# /* papszOptions*/)
339 {
340 CPLAssertcxx . . $ `port/cpl_error.h:353:9`!(nullptr != pszLayerName);
341
342 /* -------------------------------------------------------------------- */
343 /* Verify we are in update mode. */
344 /* -------------------------------------------------------------------- */
345 if (fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_. == nullptr)
346 {
347 CPLError(CE_Failure, CPLE_NoWriteAccesscxx . . $ `port/cpl_error.h:122:9`!,
348 "Data source %s opened for read access. "
349 "New layer %s cannot be created.",
350 GetDescriptioncxx . . $ GDALMajorObject#GetDescription(a9f41ea0e82d88cf).(), pszLayerName);
351
352 return nullptr;
353 }
354
355 const auto eType = poGeomFieldDefn ? poGeomFieldDefn->GetTypecxx . . $ OGRGeomFieldDefn#GetType(5a40c54c5ff210ce).() : wkbNone;
356 const auto poSRS =
357 poGeomFieldDefn ? poGeomFieldDefn->GetSpatialRefcxx . . $ OGRGeomFieldDefn#GetSpatialRef(8a5496c2eeefaeaf).() : nullptr;
358
359 /* -------------------------------------------------------------------- */
360 /* Close the previous layer (if there is one open) */
361 /* -------------------------------------------------------------------- */
362 if (GetLayerCountcxx . . $ OGRKMLDataSource#GetLayerCount(455f465bc33b4cdf).() > 0)
363 {
364 if (nLayers_cxx . . $ OGRKMLDataSource#nLayers_. == 1 && papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.[0]->nWroteFeatureCount_cxx . . $ OGRKMLLayer#nWroteFeatureCount_. == 0)
365 {
366 VSIFPrintfL(fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_., "<Folder><name>%s</name>\n",
367 papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.[0]->GetNamecxx . . $ OGRLayer#GetName(a9f41ea0e82d88cf).());
368 }
369
370 VSIFPrintfL(fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_., "</Folder>\n");
371 papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.[GetLayerCountcxx . . $ OGRKMLDataSource#GetLayerCount(455f465bc33b4cdf).() - 1]->SetClosedForWritingcxx . . $ OGRKMLLayer#SetClosedForWriting(49f6e7a06ebc5aa8).();
372 }
373
374 /* -------------------------------------------------------------------- */
375 /* Ensure name is safe as an element name. */
376 /* -------------------------------------------------------------------- */
377 char *pszCleanLayerName = CPLStrdup(pszLayerName);
378
379 CPLCleanXMLElementName(pszCleanLayerName);
380 if (strcmp(pszCleanLayerName, pszLayerName) != 0)
381 {
382 CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!,
383 "Layer name '%s' adjusted to '%s' for XML validity.",
384 pszLayerName, pszCleanLayerName);
385 }
386
387 if (GetLayerCountcxx . . $ OGRKMLDataSource#GetLayerCount(455f465bc33b4cdf).() > 0)
388 {
389 VSIFPrintfL(fpOutput_cxx . . $ OGRKMLDataSource#fpOutput_., "<Folder><name>%s</name>\n", pszCleanLayerName);
390 }
391
392 /* -------------------------------------------------------------------- */
393 /* Create the layer object. */
394 /* -------------------------------------------------------------------- */
395 OGRKMLLayercxx . . $ OGRKMLLayer# *poLayer =
396 new OGRKMLLayercxx . . $ OGRKMLLayer#(pszCleanLayerName, poSRS, true, eType, this);
397
398 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszCleanLayerName);
399
400 /* -------------------------------------------------------------------- */
401 /* Add layer to data source layer list. */
402 /* -------------------------------------------------------------------- */
403 papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_. = static_cast<OGRKMLLayercxx . . $ OGRKMLLayer# **>(
404 CPLRealloc(papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_., sizeof(OGRKMLLayercxx . . $ OGRKMLLayer# *) * (nLayers_cxx . . $ OGRKMLDataSource#nLayers_. + 1)));
405
406 papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.[nLayers_cxx . . $ OGRKMLDataSource#nLayers_.++] = poLayer;
407
408 return poLayer;
409 }
410
411 /************************************************************************/
412 /* TestCapability() */
413 /************************************************************************/
414
415 int OGRKMLDataSourcecxx . . $ OGRKMLDataSource#::TestCapabilitycxx . . $ OGRKMLDataSource#TestCapability(78f035161ffa9fe2).(const char *pszCap) const
416
417 {
418 if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, ODsCCreateLayercxx . . $ `ogr/ogr_core.h:1040:9`!))
419 return TRUEcxx . . $ `port/cpl_port.h:1184:9`!;
420 else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, ODsCZGeometriescxx . . $ `ogr/ogr_core.h:1058:9`!))
421 return TRUEcxx . . $ `port/cpl_port.h:1184:9`!;
422
423 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
424 }
425
426 /************************************************************************/
427 /* GetLayer() */
428 /************************************************************************/
429
430 const OGRLayercxx . . $ OGRLayer# *OGRKMLDataSourcecxx . . $ OGRKMLDataSource#::GetLayercxx . . $ OGRKMLDataSource#GetLayer(3ead67c79a3185c4).(int iLayer) const
431 {
432 if (iLayer < 0 || iLayer >= nLayers_cxx . . $ OGRKMLDataSource#nLayers_.)
433 return nullptr;
434
435 return papoLayers_cxx . . $ OGRKMLDataSource#papoLayers_.[iLayer];
436 }
437
438 /************************************************************************/
439 /* GrowExtents() */
440 /************************************************************************/
441
442 void OGRKMLDataSourcecxx . . $ OGRKMLDataSource#::GrowExtentscxx . . $ OGRKMLDataSource#GrowExtents(96d1bd861ec74f3c).(OGREnvelope *psGeomBounds)
443 {
444 CPLAssertcxx . . $ `port/cpl_error.h:353:9`!(nullptr != psGeomBounds);
445
446 oEnvelope_cxx . . $ OGRKMLDataSource#oEnvelope_..Merge(*psGeomBounds);
447 }