| 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Project: KML Driver |
| 4 | * Purpose: Implementation of OGRKMLLayer class. |
| 5 | * Author: Christopher Condit, [email protected] |
| 6 | * Jens Oberender, [email protected] |
| 7 | * |
| 8 | ****************************************************************************** |
| 9 | * Copyright (c) 2006, Christopher Condit |
| 10 | * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com> |
| 11 | * |
| 12 | * SPDX-License-Identifier: MIT |
| 13 | ****************************************************************************/ |
| 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 <string> |
| 19 | |
| 20 | #include "cpl_conv.h"cxx . . $ `<file>/port/cpl_conv.h`/ |
| 21 | #include "cpl_error.h"cxx . . $ `<file>/port/cpl_error.h`/ |
| 22 | #include "cpl_string.h"cxx . . $ `<file>/port/cpl_string.h`/ |
| 23 | #include "cpl_vsi.h"cxx . . $ `<file>/port/cpl_vsi.h`/ |
| 24 | #include "kml.h"cxx . . $ `<file>/ogr/ogrsf_frmts/kml/kml.h`/ |
| 25 | #include "kmlutility.h"cxx . . $ `<file>/ogr/ogrsf_frmts/kml/kmlutility.h`/ |
| 26 | #include "ogr_api.h"cxx . . $ `<file>/ogr/ogr_api.h`/ |
| 27 | #include "ogr_core.h"cxx . . $ `<file>/ogr/ogr_core.h`/ |
| 28 | #include "ogr_feature.h"cxx . . $ `<file>/ogr/ogr_feature.h`/ |
| 29 | #include "ogr_featurestyle.h"cxx . . $ `<file>/ogr/ogr_featurestyle.h`/ |
| 30 | #include "ogr_geometry.h"cxx . . $ `<file>/ogr/ogr_geometry.h`/ |
| 31 | #include "ogr_p.h"cxx . . $ `<file>/ogr/ogr_p.h`/ |
| 32 | #include "ogr_spatialref.h"cxx . . $ `<file>/ogr/ogr_spatialref.h`/ |
| 33 | #include "ogrsf_frmts.h"cxx . . $ `<file>/ogr/ogrsf_frmts/ogrsf_frmts.h`/ |
| 34 | |
| 35 | /* Function utility to dump OGRGeometry to KML text. */ |
| 36 | char *OGR_G_ExportToKMLcxx . . $ OGR_G_ExportToKML(df512cf1ab4f8f70).(OGRGeometryH hGeometry, const char *pszAltitudeMode); |
| 37 | |
| 38 | /************************************************************************/ |
| 39 | /* OGRKMLLayer() */ |
| 40 | /************************************************************************/ |
| 41 | |
| 42 | OGRKMLLayercxx . . $ OGRKMLLayer#::OGRKMLLayercxx . . $ OGRKMLLayer#OGRKMLLayer(d6dca405ac3918aa).(const char *pszName, |
| 43 | const OGRSpatialReferencecxx . . $ OGRSpatialReference# *poSRSIn, bool bWriterIn, |
| 44 | OGRwkbGeometryType eReqType, OGRKMLDataSourcecxx . . $ OGRKMLDataSource# *poDSIn) |
| 45 | : poDS_cxx . . $ OGRKMLLayer#poDS_.(poDSIn), |
| 46 | poSRS_cxx . . $ OGRKMLLayer#poSRS_.(poSRSIn ? new OGRSpatialReferencecxx . . $ OGRSpatialReference#OGRSpatialReference(85c52e162fed56f9).(nullptr) : nullptr), |
| 47 | poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.(new OGRFeatureDefncxx . . $ OGRFeatureDefn#(pszName)), bWriter_cxx . . $ OGRKMLLayer#bWriter_.(bWriterIn), |
| 48 | pszName_cxx . . $ OGRKMLLayer#pszName_.(CPLStrdup(pszName)) |
| 49 | { |
| 50 | // KML should be created as WGS84. |
| 51 | if (poSRSIn != nullptr) |
| 52 | { |
| 53 | poSRS_cxx . . $ OGRKMLLayer#poSRS_.->SetWellKnownGeogCScxx . . $ OGRSpatialReference#SetWellKnownGeogCS(5c4306d8553b3696).("WGS84"); |
| 54 | poSRS_cxx . . $ OGRKMLLayer#poSRS_.->SetAxisMappingStrategycxx . . $ OGRSpatialReference#SetAxisMappingStrategy(3d39f43974738d6a).(OAMS_TRADITIONAL_GIS_ORDER); |
| 55 | if (!poSRS_cxx . . $ OGRKMLLayer#poSRS_.->IsSamecxx . . $ OGRSpatialReference#IsSame(1d22f83639af445a).(poSRSIn)) |
| 56 | { |
| 57 | poCT_cxx . . $ OGRKMLLayer#poCT_. = OGRCreateCoordinateTransformationcxx . . $ OGRCreateCoordinateTransformation(2d3c2de25cb16c6e).(poSRSIn, poSRS_cxx . . $ OGRKMLLayer#poSRS_.); |
| 58 | if (poCT_cxx . . $ OGRKMLLayer#poCT_. == nullptr && poDSIn->IsFirstCTErrorcxx . . $ OGRKMLDataSource#IsFirstCTError(50ce9a9e25b4a850).()) |
| 59 | { |
| 60 | // If we can't create a transformation, issue a warning - but |
| 61 | // continue the transformation. |
| 62 | char *pszWKT = nullptr; |
| 63 | |
| 64 | poSRSIn->exportToPrettyWktcxx . . $ OGRSpatialReference#exportToPrettyWkt(bb89171cb0b0565c).(&pszWKT, FALSEcxx . . $ `port/cpl_port.h:1180:9`!); |
| 65 | |
| 66 | CPLError( |
| 67 | CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 68 | "Failed to create coordinate transformation between the " |
| 69 | "input coordinate system and WGS84. This may be because " |
| 70 | "they are not transformable. " |
| 71 | "KML geometries may not render correctly. " |
| 72 | "This message will not be issued any more." |
| 73 | "\nSource:\n%s\n", |
| 74 | pszWKT); |
| 75 | |
| 76 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszWKT); |
| 77 | poDSIn->IssuedFirstCTErrorcxx . . $ OGRKMLDataSource#IssuedFirstCTError(49f6e7a06ebc5aa8).(); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | SetDescriptioncxx . . $ GDALMajorObject#SetDescription(85c52e162fed56f9).(poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->GetNamecxx . . $ OGRFeatureDefn#GetName(a9f41ea0e82d88cf).()); |
| 83 | poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->Referencecxx . . $ OGRFeatureDefn#Reference(b126dc7c1de90089).(); |
| 84 | poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->SetGeomTypecxx . . $ OGRFeatureDefn#SetGeomType(f47ce3f1fe923726).(eReqType); |
| 85 | if (poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() != 0) |
| 86 | poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->SetSpatialRefcxx . . $ OGRGeomFieldDefn#SetSpatialRef(9ff39b79387a6086).(poSRS_cxx . . $ OGRKMLLayer#poSRS_.); |
| 87 | |
| 88 | OGRFieldDefncxx . . $ OGRFieldDefn# oFieldNamecxx . . $ OGRFieldDefn#OGRFieldDefn(786ecb48a0b3b841).("Name", OFTString); |
| 89 | poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->AddFieldDefncxx . . $ OGRFeatureDefn#AddFieldDefn(f8bad7d30df65bbb).(&oFieldName); |
| 90 | |
| 91 | OGRFieldDefncxx . . $ OGRFieldDefn# oFieldDesccxx . . $ OGRFieldDefn#OGRFieldDefn(786ecb48a0b3b841).("Description", OFTString); |
| 92 | poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->AddFieldDefncxx . . $ OGRFeatureDefn#AddFieldDefn(f8bad7d30df65bbb).(&oFieldDesc); |
| 93 | |
| 94 | bClosedForWritingcxx . . $ OGRKMLLayer#bClosedForWriting. = !bWriterIn; |
| 95 | } |
| 96 | |
| 97 | /************************************************************************/ |
| 98 | /* ~OGRKMLLayer() */ |
| 99 | /************************************************************************/ |
| 100 | |
| 101 | OGRKMLLayercxx . . $ OGRKMLLayer#::~cxx . . $ OGRKMLLayer#`~OGRKMLLayer`(ced63f7c635d850d).OGRKMLLayercxx . . $ OGRKMLLayer#() |
| 102 | { |
| 103 | if (nullptr != poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.) |
| 104 | poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->Releasecxx . . $ OGRFeatureDefn#Release(49f6e7a06ebc5aa8).(); |
| 105 | |
| 106 | if (nullptr != poSRS_cxx . . $ OGRKMLLayer#poSRS_.) |
| 107 | poSRS_cxx . . $ OGRKMLLayer#poSRS_.->Releasecxx . . $ OGRSpatialReference#Release(49f6e7a06ebc5aa8).(); |
| 108 | |
| 109 | if (nullptr != poCT_cxx . . $ OGRKMLLayer#poCT_.) |
| 110 | delete poCT_cxx . . $ OGRKMLLayer#poCT_.; |
| 111 | |
| 112 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszName_cxx . . $ OGRKMLLayer#pszName_.); |
| 113 | } |
| 114 | |
| 115 | /************************************************************************/ |
| 116 | /* GetLayerDefn() */ |
| 117 | /************************************************************************/ |
| 118 | |
| 119 | const OGRFeatureDefncxx . . $ OGRFeatureDefn# *OGRKMLLayercxx . . $ OGRKMLLayer#::GetLayerDefncxx . . $ OGRKMLLayer#GetLayerDefn(448b209f43d15bcc).() const |
| 120 | { |
| 121 | return poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.; |
| 122 | } |
| 123 | |
| 124 | /************************************************************************/ |
| 125 | /* ResetReading() */ |
| 126 | /************************************************************************/ |
| 127 | |
| 128 | void OGRKMLLayercxx . . $ OGRKMLLayer#::ResetReadingcxx . . $ OGRKMLLayer#ResetReading(49f6e7a06ebc5aa8).() |
| 129 | { |
| 130 | iNextKMLId_cxx . . $ OGRKMLLayer#iNextKMLId_. = 0; |
| 131 | nLastAskedcxx . . $ OGRKMLLayer#nLastAsked. = -1; |
| 132 | nLastCountcxx . . $ OGRKMLLayer#nLastCount. = -1; |
| 133 | } |
| 134 | |
| 135 | /************************************************************************/ |
| 136 | /* GetNextFeature() */ |
| 137 | /************************************************************************/ |
| 138 | |
| 139 | OGRFeaturecxx . . $ OGRFeature# *OGRKMLLayercxx . . $ OGRKMLLayer#::GetNextFeaturecxx . . $ OGRKMLLayer#GetNextFeature(ec9eceddec1d9563).() |
| 140 | { |
| 141 | #ifndef HAVE_EXPATcxx . . $ `<built-in>:483:9`! |
| 142 | return nullptr; |
| 143 | #else |
| 144 | /* -------------------------------------------------------------------- */ |
| 145 | /* Loop till we find a feature matching our criteria. */ |
| 146 | /* -------------------------------------------------------------------- */ |
| 147 | KMLcxx . . $ KML# *poKMLFile = poDS_cxx . . $ OGRKMLLayer#poDS_.->GetKMLFilecxx . . $ OGRKMLDataSource#GetKMLFile(c6132cb0cb593c2d).(); |
| 148 | if (poKMLFile == nullptr) |
| 149 | return nullptr; |
| 150 | |
| 151 | poKMLFile->selectLayercxx . . $ KML#selectLayer(83c267b20bac841a).(nLayerNumber_cxx . . $ OGRKMLLayer#nLayerNumber_.); |
| 152 | |
| 153 | while (true) |
| 154 | { |
| 155 | auto poFeatureKML = stdcxx . . $ std/::unique_ptr<Featurecxx . . $ OGRKML/Feature#>( |
| 156 | poKMLFile->getFeaturecxx . . $ KML#getFeature(7e844c00511f9654).(iNextKMLId_cxx . . $ OGRKMLLayer#iNextKMLId_.++, nLastAskedcxx . . $ OGRKMLLayer#nLastAsked., nLastCountcxx . . $ OGRKMLLayer#nLastCount.)); |
| 157 | |
| 158 | if (poFeatureKML == nullptr) |
| 159 | return nullptr; |
| 160 | |
| 161 | auto poFeature = stdcxx . . $ std/::make_unique<OGRFeaturecxx . . $ OGRFeature#>(poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.); |
| 162 | |
| 163 | if (poFeatureKML->poGeomcxx . . $ OGRKML/Feature#poGeom.) |
| 164 | { |
| 165 | poFeature->SetGeometrycxx . . $ OGRFeature#SetGeometry(409c5ef120a740b2).(stdcxx . . $ std/::move(poFeatureKML->poGeomcxx . . $ OGRKML/Feature#poGeom.)); |
| 166 | } |
| 167 | |
| 168 | // Add fields. |
| 169 | poFeature->SetFieldcxx . . $ OGRFeature#SetField(66835f578de1bcb3).(poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->GetFieldIndexcxx . . $ OGRFeatureDefn#GetFieldIndex(78f035161ffa9fe2).("Name"), |
| 170 | poFeatureKML->sNamecxx . . $ OGRKML/Feature#sName..c_str()); |
| 171 | poFeature->SetFieldcxx . . $ OGRFeature#SetField(66835f578de1bcb3).(poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->GetFieldIndexcxx . . $ OGRFeatureDefn#GetFieldIndex(78f035161ffa9fe2).("Description"), |
| 172 | poFeatureKML->sDescriptioncxx . . $ OGRKML/Feature#sDescription..c_str()); |
| 173 | poFeature->SetFIDcxx . . $ OGRFeature#SetFID(a070d6d14e988596).(iNextKMLId_cxx . . $ OGRKMLLayer#iNextKMLId_. - 1); |
| 174 | |
| 175 | if (poFeature->GetGeometryRefcxx . . $ OGRFeature#GetGeometryRef(3dfc1d32c7db2584).() != nullptr && poSRS_cxx . . $ OGRKMLLayer#poSRS_. != nullptr) |
| 176 | { |
| 177 | poFeature->GetGeometryRefcxx . . $ OGRFeature#GetGeometryRef(3dfc1d32c7db2584).()->assignSpatialReferencecxx . . $ OGRGeometry#assignSpatialReference(9ff39b79387a6086).(poSRS_cxx . . $ OGRKMLLayer#poSRS_.); |
| 178 | } |
| 179 | |
| 180 | // Check spatial/attribute filters. |
| 181 | if ((m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. == nullptr || |
| 182 | FilterGeometrycxx . . $ OGRLayer#FilterGeometry(fed901b2566802ff).(poFeature->GetGeometryRefcxx . . $ OGRFeature#GetGeometryRef(3dfc1d32c7db2584).())) && |
| 183 | (m_poAttrQuerycxx . . $ OGRLayer#m_poAttrQuery. == nullptr || |
| 184 | m_poAttrQuerycxx . . $ OGRLayer#m_poAttrQuery.->Evaluatecxx . . $ OGRFeatureQuery#Evaluate(2048609adab03aab).(poFeature.get()))) |
| 185 | { |
| 186 | return poFeature.release(); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | #endif /* HAVE_EXPAT */ |
| 191 | } |
| 192 | |
| 193 | /************************************************************************/ |
| 194 | /* GetFeatureCount() */ |
| 195 | /************************************************************************/ |
| 196 | |
| 197 | #ifndef HAVE_EXPATcxx . . $ `<built-in>:483:9`! |
| 198 | GIntBig OGRKMLLayer::GetFeatureCount(int /* bForce */) |
| 199 | { |
| 200 | return 0; |
| 201 | } |
| 202 | #else |
| 203 | |
| 204 | GIntBigcxx . . $ GIntBig# OGRKMLLayercxx . . $ OGRKMLLayer#::GetFeatureCountcxx . . $ OGRKMLLayer#GetFeatureCount(9ccc33c3ebad048d).(int bForce) |
| 205 | { |
| 206 | if (m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. != nullptr || m_poAttrQuerycxx . . $ OGRLayer#m_poAttrQuery. != nullptr) |
| 207 | return OGRLayercxx . . $ OGRLayer#::GetFeatureCountcxx . . $ OGRLayer#GetFeatureCount(9ccc33c3ebad048d).(bForce); |
| 208 | |
| 209 | KMLcxx . . $ KML# *poKMLFile = poDS_cxx . . $ OGRKMLLayer#poDS_.->GetKMLFilecxx . . $ OGRKMLDataSource#GetKMLFile(c6132cb0cb593c2d).(); |
| 210 | if (nullptr == poKMLFile) |
| 211 | return 0; |
| 212 | |
| 213 | poKMLFile->selectLayercxx . . $ KML#selectLayer(83c267b20bac841a).(nLayerNumber_cxx . . $ OGRKMLLayer#nLayerNumber_.); |
| 214 | |
| 215 | return poKMLFile->getNumFeaturescxx . . $ KML#getNumFeatures(b126dc7c1de90089).(); |
| 216 | } |
| 217 | #endif |
| 218 | |
| 219 | /************************************************************************/ |
| 220 | /* WriteSchema() */ |
| 221 | /************************************************************************/ |
| 222 | |
| 223 | CPLString OGRKMLLayercxx . . $ OGRKMLLayer#::WriteSchemacxx . . $ OGRKMLLayer#WriteSchema(cdfd1e859161399b).() |
| 224 | { |
| 225 | if (bSchemaWritten_cxx . . $ OGRKMLLayer#bSchemaWritten_.) |
| 226 | return ""; |
| 227 | |
| 228 | CPLString osRet; |
| 229 | |
| 230 | const OGRFeatureDefncxx . . $ OGRFeatureDefn# *featureDefinition = GetLayerDefncxx . . $ OGRKMLLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 231 | for (int j = 0; j < featureDefinition->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); j++) |
| 232 | { |
| 233 | const OGRFieldDefncxx . . $ OGRFieldDefn# *fieldDefinition = |
| 234 | featureDefinition->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(j); |
| 235 | |
| 236 | if (nullptr != poDS_cxx . . $ OGRKMLLayer#poDS_.->GetNameFieldcxx . . $ OGRKMLDataSource#GetNameField(a9f41ea0e82d88cf).() && |
| 237 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(fieldDefinition->GetNameRef(), poDS_->GetNameField())) |
| 238 | continue; |
| 239 | |
| 240 | if (nullptr != poDS_cxx . . $ OGRKMLLayer#poDS_.->GetDescriptionFieldcxx . . $ OGRKMLDataSource#GetDescriptionField(a9f41ea0e82d88cf).() && |
| 241 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(fieldDefinition->GetNameRef(), poDS_->GetDescriptionField())) |
| 242 | continue; |
| 243 | |
| 244 | if (osRet.empty()) |
| 245 | { |
| 246 | osRet += CPLSPrintf("<Schema name=\"%s\" id=\"%s\">\n", pszName_cxx . . $ OGRKMLLayer#pszName_., |
| 247 | pszName_cxx . . $ OGRKMLLayer#pszName_.); |
| 248 | } |
| 249 | |
| 250 | const char *pszKMLType = nullptr; |
| 251 | const char *pszKMLEltName = nullptr; |
| 252 | // Match the OGR type to the GDAL type. |
| 253 | switch (fieldDefinition->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).()) |
| 254 | { |
| 255 | case OFTInteger: |
| 256 | pszKMLType = "int"; |
| 257 | pszKMLEltName = "SimpleField"; |
| 258 | break; |
| 259 | case OFTIntegerList: |
| 260 | pszKMLType = "int"; |
| 261 | pszKMLEltName = "SimpleArrayField"; |
| 262 | break; |
| 263 | case OFTReal: |
| 264 | pszKMLType = "float"; |
| 265 | pszKMLEltName = "SimpleField"; |
| 266 | break; |
| 267 | case OFTRealList: |
| 268 | pszKMLType = "float"; |
| 269 | pszKMLEltName = "SimpleArrayField"; |
| 270 | break; |
| 271 | case OFTString: |
| 272 | pszKMLType = "string"; |
| 273 | pszKMLEltName = "SimpleField"; |
| 274 | break; |
| 275 | case OFTStringList: |
| 276 | pszKMLType = "string"; |
| 277 | pszKMLEltName = "SimpleArrayField"; |
| 278 | break; |
| 279 | // TODO: KML doesn't handle these data types yet... |
| 280 | case OFTDate: |
| 281 | case OFTTime: |
| 282 | case OFTDateTime: |
| 283 | pszKMLType = "string"; |
| 284 | pszKMLEltName = "SimpleField"; |
| 285 | break; |
| 286 | |
| 287 | default: |
| 288 | pszKMLType = "string"; |
| 289 | pszKMLEltName = "SimpleField"; |
| 290 | break; |
| 291 | } |
| 292 | osRet += CPLSPrintf("\t<%s name=\"%s\" type=\"%s\"></%s>\n", |
| 293 | pszKMLEltName, fieldDefinition->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), |
| 294 | pszKMLType, pszKMLEltName); |
| 295 | } |
| 296 | |
| 297 | if (!osRet.empty()) |
| 298 | osRet += CPLSPrintf("%s", "</Schema>\n"); |
| 299 | |
| 300 | return osRet; |
| 301 | } |
| 302 | |
| 303 | /************************************************************************/ |
| 304 | /* ICreateFeature() */ |
| 305 | /************************************************************************/ |
| 306 | |
| 307 | OGRErr OGRKMLLayercxx . . $ OGRKMLLayer#::ICreateFeaturecxx . . $ OGRKMLLayer#ICreateFeature(2048609adab03aab).(OGRFeaturecxx . . $ OGRFeature# *poFeature) |
| 308 | { |
| 309 | CPLAssertcxx . . $ `port/cpl_error.h:353:9`!(nullptr != poFeature); |
| 310 | CPLAssertcxx . . $ `port/cpl_error.h:353:9`!(nullptr != poDS_); |
| 311 | |
| 312 | if (!bWriter_cxx . . $ OGRKMLLayer#bWriter_.) |
| 313 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 314 | |
| 315 | if (bClosedForWritingcxx . . $ OGRKMLLayer#bClosedForWriting.) |
| 316 | { |
| 317 | CPLError( |
| 318 | CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, |
| 319 | "Interleaved feature adding to different layers is not supported"); |
| 320 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 321 | } |
| 322 | |
| 323 | VSILFILE *fp = poDS_cxx . . $ OGRKMLLayer#poDS_.->GetOutputFPcxx . . $ OGRKMLDataSource#GetOutputFP(c5a74e05fa14bf1).(); |
| 324 | CPLAssertcxx . . $ `port/cpl_error.h:353:9`!(nullptr != fp); |
| 325 | |
| 326 | if (poDS_cxx . . $ OGRKMLLayer#poDS_.->GetLayerCountcxx . . $ OGRKMLDataSource#GetLayerCount(455f465bc33b4cdf).() == 1 && nWroteFeatureCount_cxx . . $ OGRKMLLayer#nWroteFeatureCount_. == 0) |
| 327 | { |
| 328 | CPLString osRet = WriteSchemacxx . . $ OGRKMLLayer#WriteSchema(cdfd1e859161399b).(); |
| 329 | if (!osRet.empty()) |
| 330 | VSIFPrintfL(fp, "%s", osRet.c_str()); |
| 331 | bSchemaWritten_cxx . . $ OGRKMLLayer#bSchemaWritten_. = true; |
| 332 | |
| 333 | VSIFPrintfL(fp, "<Folder><name>%s</name>\n", pszName_cxx . . $ OGRKMLLayer#pszName_.); |
| 334 | } |
| 335 | |
| 336 | ++nWroteFeatureCount_cxx . . $ OGRKMLLayer#nWroteFeatureCount_.; |
| 337 | char *pszEscapedLayerName = OGRGetXML_UTF8_EscapedStringcxx . . $ OGRGetXML_UTF8_EscapedString(a8b8e32347182212).(GetDescriptioncxx . . $ GDALMajorObject#GetDescription(a9f41ea0e82d88cf).()); |
| 338 | VSIFPrintfL(fp, " <Placemark id=\"%s." CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! "\">\n", |
| 339 | pszEscapedLayerName, nWroteFeatureCount_cxx . . $ OGRKMLLayer#nWroteFeatureCount_.); |
| 340 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszEscapedLayerName); |
| 341 | |
| 342 | if (poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).() == OGRNullFIDcxx . . $ `ogr/ogr_core.h:848:9`!) |
| 343 | poFeature->SetFIDcxx . . $ OGRFeature#SetFID(a070d6d14e988596).(iNextKMLId_cxx . . $ OGRKMLLayer#iNextKMLId_.++); |
| 344 | |
| 345 | // Find and write the name element |
| 346 | if (nullptr != poDS_cxx . . $ OGRKMLLayer#poDS_.->GetNameFieldcxx . . $ OGRKMLDataSource#GetNameField(a9f41ea0e82d88cf).()) |
| 347 | { |
| 348 | for (int iField = 0; iField < poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); iField++) |
| 349 | { |
| 350 | OGRFieldDefncxx . . $ OGRFieldDefn# *poField = poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iField); |
| 351 | |
| 352 | if (poFeature->IsFieldSetAndNotNullcxx . . $ OGRFeature#IsFieldSetAndNotNull(4a668f6de69bf818).(iField) && |
| 353 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(poField->GetNameRef(), poDS_->GetNameField())) |
| 354 | { |
| 355 | const char *pszRaw = poFeature->GetFieldAsStringcxx . . $ OGRFeature#GetFieldAsString(afbf07f2bc1a9437).(iField); |
| 356 | while (*pszRaw == ' ') |
| 357 | pszRaw++; |
| 358 | |
| 359 | char *pszEscaped = OGRGetXML_UTF8_EscapedStringcxx . . $ OGRGetXML_UTF8_EscapedString(a8b8e32347182212).(pszRaw); |
| 360 | |
| 361 | VSIFPrintfL(fp, "\t<name>%s</name>\n", pszEscaped); |
| 362 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszEscaped); |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | if (nullptr != poDS_cxx . . $ OGRKMLLayer#poDS_.->GetDescriptionFieldcxx . . $ OGRKMLDataSource#GetDescriptionField(a9f41ea0e82d88cf).()) |
| 368 | { |
| 369 | for (int iField = 0; iField < poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); iField++) |
| 370 | { |
| 371 | OGRFieldDefncxx . . $ OGRFieldDefn# *poField = poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iField); |
| 372 | |
| 373 | if (poFeature->IsFieldSetAndNotNullcxx . . $ OGRFeature#IsFieldSetAndNotNull(4a668f6de69bf818).(iField) && |
| 374 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(poField->GetNameRef(), poDS_->GetDescriptionField())) |
| 375 | { |
| 376 | const char *pszRaw = poFeature->GetFieldAsStringcxx . . $ OGRFeature#GetFieldAsString(afbf07f2bc1a9437).(iField); |
| 377 | while (*pszRaw == ' ') |
| 378 | pszRaw++; |
| 379 | |
| 380 | char *pszEscaped = OGRGetXML_UTF8_EscapedStringcxx . . $ OGRGetXML_UTF8_EscapedString(a8b8e32347182212).(pszRaw); |
| 381 | |
| 382 | VSIFPrintfL(fp, "\t<description>%s</description>\n", |
| 383 | pszEscaped); |
| 384 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszEscaped); |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | OGRwkbGeometryType eGeomType = wkbNone; |
| 390 | if (poFeature->GetGeometryRefcxx . . $ OGRFeature#GetGeometryRef(3dfc1d32c7db2584).() != nullptr) |
| 391 | eGeomType = wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!(poFeature->GetGeometryRef()->getGeometryType()); |
| 392 | |
| 393 | if (wkbPolygon == eGeomType || wkbMultiPolygon == eGeomType || |
| 394 | wkbLineString == eGeomType || wkbMultiLineString == eGeomType) |
| 395 | { |
| 396 | OGRStylePencxx . . $ OGRStylePen# *poPen = nullptr; |
| 397 | OGRStyleMgrcxx . . $ OGRStyleMgr# oSMcxx . . $ OGRStyleMgr#OGRStyleMgr(dac37a74c9edd45f).; |
| 398 | |
| 399 | if (poFeature->GetStyleStringcxx . . $ OGRFeature#GetStyleString(a9f41ea0e82d88cf).() != nullptr) |
| 400 | { |
| 401 | oSM.InitFromFeaturecxx . . $ OGRStyleMgr#InitFromFeature(b91ef6b9dcdd714e).(poFeature); |
| 402 | |
| 403 | for (int i = 0; i < oSM.GetPartCountcxx . . $ OGRStyleMgr#GetPartCount(5c4306d8553b3696).(); i++) |
| 404 | { |
| 405 | OGRStyleToolcxx . . $ OGRStyleTool# *poTool = oSM.GetPartcxx . . $ OGRStyleMgr#GetPart(df35922318cb76c3).(i); |
| 406 | if (poTool && poTool->GetTypecxx . . $ OGRStyleTool#GetType(8052caf53f6ed207).() == OGRSTCPen) |
| 407 | { |
| 408 | poPen = cpl::down_cast<OGRStylePencxx . . $ OGRStylePen# *>(poTool); |
| 409 | break; |
| 410 | } |
| 411 | delete poTool; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | VSIFPrintfL(fp, "\t<Style>"); |
| 416 | if (poPen != nullptr) |
| 417 | { |
| 418 | GBoolcxx . . $ GBool# bDefault = FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 419 | |
| 420 | /* Require width to be returned in pixel */ |
| 421 | poPen->SetUnitcxx . . $ OGRStyleTool#SetUnit(ed5870a629093d9e).(OGRSTUPixel); |
| 422 | double fW = poPen->Widthcxx . . $ OGRStylePen#Width(88fc23358c96bb53).(bDefault); |
| 423 | if (bDefault) |
| 424 | fW = 1; |
| 425 | const char *pszColor = poPen->Colorcxx . . $ OGRStylePen#Color(b82f50771e6c26e2).(bDefault); |
| 426 | const int nColorLen = static_cast<int>(CPLStrnlen(pszColor, 10)); |
| 427 | if (pszColor != nullptr && pszColor[0] == '#' && !bDefault && |
| 428 | nColorLen >= 7) |
| 429 | { |
| 430 | char acColor[9] = {0}; |
| 431 | /* Order of KML color is aabbggrr, whereas OGR color is |
| 432 | * #rrggbb[aa] ! */ |
| 433 | if (nColorLen == 9) |
| 434 | { |
| 435 | acColor[0] = pszColor[7]; /* A */ |
| 436 | acColor[1] = pszColor[8]; |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | acColor[0] = 'F'; |
| 441 | acColor[1] = 'F'; |
| 442 | } |
| 443 | acColor[2] = pszColor[5]; /* B */ |
| 444 | acColor[3] = pszColor[6]; |
| 445 | acColor[4] = pszColor[3]; /* G */ |
| 446 | acColor[5] = pszColor[4]; |
| 447 | acColor[6] = pszColor[1]; /* R */ |
| 448 | acColor[7] = pszColor[2]; |
| 449 | VSIFPrintfL(fp, "<LineStyle><color>%s</color>", acColor); |
| 450 | VSIFPrintfL(fp, "<width>%g</width>", fW); |
| 451 | VSIFPrintfL(fp, "</LineStyle>"); |
| 452 | } |
| 453 | else |
| 454 | { |
| 455 | VSIFPrintfL(fp, |
| 456 | "<LineStyle><color>ff0000ff</color></LineStyle>"); |
| 457 | } |
| 458 | } |
| 459 | else |
| 460 | { |
| 461 | VSIFPrintfL(fp, "<LineStyle><color>ff0000ff</color></LineStyle>"); |
| 462 | } |
| 463 | delete poPen; |
| 464 | // If we're dealing with a polygon, add a line style that will stand out |
| 465 | // a bit. |
| 466 | VSIFPrintfL(fp, "<PolyStyle><fill>0</fill></PolyStyle></Style>\n"); |
| 467 | } |
| 468 | |
| 469 | bool bHasFoundOtherField = false; |
| 470 | |
| 471 | // Write all fields as SchemaData |
| 472 | for (int iField = 0; iField < poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); iField++) |
| 473 | { |
| 474 | OGRFieldDefncxx . . $ OGRFieldDefn# *poField = poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iField); |
| 475 | |
| 476 | if (poFeature->IsFieldSetAndNotNullcxx . . $ OGRFeature#IsFieldSetAndNotNull(4a668f6de69bf818).(iField)) |
| 477 | { |
| 478 | if (nullptr != poDS_cxx . . $ OGRKMLLayer#poDS_.->GetNameFieldcxx . . $ OGRKMLDataSource#GetNameField(a9f41ea0e82d88cf).() && |
| 479 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(poField->GetNameRef(), poDS_->GetNameField())) |
| 480 | continue; |
| 481 | |
| 482 | if (nullptr != poDS_cxx . . $ OGRKMLLayer#poDS_.->GetDescriptionFieldcxx . . $ OGRKMLDataSource#GetDescriptionField(a9f41ea0e82d88cf).() && |
| 483 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(poField->GetNameRef(), poDS_->GetDescriptionField())) |
| 484 | continue; |
| 485 | |
| 486 | if (!bHasFoundOtherField) |
| 487 | { |
| 488 | VSIFPrintfL(fp, |
| 489 | "\t<ExtendedData><SchemaData schemaUrl=\"#%s\">\n", |
| 490 | pszName_cxx . . $ OGRKMLLayer#pszName_.); |
| 491 | bHasFoundOtherField = true; |
| 492 | } |
| 493 | const char *pszRaw = poFeature->GetFieldAsStringcxx . . $ OGRFeature#GetFieldAsString(afbf07f2bc1a9437).(iField); |
| 494 | |
| 495 | while (*pszRaw == ' ') |
| 496 | pszRaw++; |
| 497 | |
| 498 | char *pszEscaped = nullptr; |
| 499 | if (poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iField)->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTReal) |
| 500 | { |
| 501 | pszEscaped = CPLStrdup(pszRaw); |
| 502 | } |
| 503 | else |
| 504 | { |
| 505 | pszEscaped = OGRGetXML_UTF8_EscapedStringcxx . . $ OGRGetXML_UTF8_EscapedString(a8b8e32347182212).(pszRaw); |
| 506 | } |
| 507 | |
| 508 | VSIFPrintfL(fp, "\t\t<SimpleData name=\"%s\">%s</SimpleData>\n", |
| 509 | poField->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), pszEscaped); |
| 510 | |
| 511 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszEscaped); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | if (bHasFoundOtherField) |
| 516 | { |
| 517 | VSIFPrintfL(fp, "\t</SchemaData></ExtendedData>\n"); |
| 518 | } |
| 519 | |
| 520 | // Write out Geometry - for now it isn't indented properly. |
| 521 | if (poFeature->GetGeometryRefcxx . . $ OGRFeature#GetGeometryRef(3dfc1d32c7db2584).() != nullptr) |
| 522 | { |
| 523 | char *pszGeometry = nullptr; |
| 524 | OGREnvelope sGeomBounds; |
| 525 | OGRGeometrycxx . . $ OGRGeometry# *poWGS84Geom = nullptr; |
| 526 | |
| 527 | if (nullptr != poCT_cxx . . $ OGRKMLLayer#poCT_.) |
| 528 | { |
| 529 | poWGS84Geom = poFeature->GetGeometryRefcxx . . $ OGRFeature#GetGeometryRef(3dfc1d32c7db2584).()->clonecxx . . $ OGRGeometry#clone(bac917acb50a3c43).(); |
| 530 | poWGS84Geom->transformcxx . . $ OGRGeometry#transform(8ea9c28d9400a78d).(poCT_cxx . . $ OGRKMLLayer#poCT_.); |
| 531 | } |
| 532 | else |
| 533 | { |
| 534 | poWGS84Geom = poFeature->GetGeometryRefcxx . . $ OGRFeature#GetGeometryRef(3dfc1d32c7db2584).(); |
| 535 | } |
| 536 | |
| 537 | pszGeometry = OGR_G_ExportToKMLcxx . . $ OGR_G_ExportToKML(df512cf1ab4f8f70).(OGRGeometrycxx . . $ OGRGeometry#::ToHandlecxx . . $ OGRGeometry#ToHandle(76b24ad94dcfe536).(poWGS84Geom), |
| 538 | poDS_cxx . . $ OGRKMLLayer#poDS_.->GetAltitudeModecxx . . $ OGRKMLDataSource#GetAltitudeMode(33a1f659e94feb42).()); |
| 539 | if (pszGeometry != nullptr) |
| 540 | { |
| 541 | VSIFPrintfL(fp, " %s\n", pszGeometry); |
| 542 | } |
| 543 | else |
| 544 | { |
| 545 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 546 | "Export of geometry to KML failed"); |
| 547 | } |
| 548 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszGeometry); |
| 549 | |
| 550 | poWGS84Geom->getEnvelopecxx . . $ OGRGeometry#getEnvelope(e5217c1f2a4fd7ce).(&sGeomBounds); |
| 551 | poDS_cxx . . $ OGRKMLLayer#poDS_.->GrowExtentscxx . . $ OGRKMLDataSource#GrowExtents(96d1bd861ec74f3c).(&sGeomBounds); |
| 552 | |
| 553 | if (nullptr != poCT_cxx . . $ OGRKMLLayer#poCT_.) |
| 554 | { |
| 555 | delete poWGS84Geom; |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | VSIFPrintfL(fp, " </Placemark>\n"); |
| 560 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 561 | } |
| 562 | |
| 563 | /************************************************************************/ |
| 564 | /* TestCapability() */ |
| 565 | /************************************************************************/ |
| 566 | |
| 567 | int OGRKMLLayercxx . . $ OGRKMLLayer#::TestCapabilitycxx . . $ OGRKMLLayer#TestCapability(78f035161ffa9fe2).(const char *pszCap) const |
| 568 | { |
| 569 | if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCSequentialWritecxx . . $ `ogr/ogr_core.h:978:9`!)) |
| 570 | { |
| 571 | return bWriter_cxx . . $ OGRKMLLayer#bWriter_.; |
| 572 | } |
| 573 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCCreateFieldcxx . . $ `ogr/ogr_core.h:990:9`!)) |
| 574 | { |
| 575 | return bWriter_cxx . . $ OGRKMLLayer#bWriter_. && iNextKMLId_cxx . . $ OGRKMLLayer#iNextKMLId_. == 0; |
| 576 | } |
| 577 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCFastFeatureCountcxx . . $ `ogr/ogr_core.h:983:9`!)) |
| 578 | { |
| 579 | // if( poFClass == NULL |
| 580 | // || m_poFilterGeom != NULL |
| 581 | // || m_poAttrQuery != NULL ) |
| 582 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 583 | |
| 584 | // return poFClass->GetFeatureCount() != -1; |
| 585 | } |
| 586 | |
| 587 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCStringsAsUTF8cxx . . $ `ogr/ogr_core.h:1016:9`!)) |
| 588 | return TRUEcxx . . $ `port/cpl_port.h:1184:9`!; |
| 589 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCZGeometriescxx . . $ `ogr/ogr_core.h:1028:9`!)) |
| 590 | return TRUEcxx . . $ `port/cpl_port.h:1184:9`!; |
| 591 | |
| 592 | return FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 593 | } |
| 594 | |
| 595 | /************************************************************************/ |
| 596 | /* CreateField() */ |
| 597 | /************************************************************************/ |
| 598 | |
| 599 | OGRErr OGRKMLLayercxx . . $ OGRKMLLayer#::CreateFieldcxx . . $ OGRKMLLayer#CreateField(2cf5282e6e90de1e).(const OGRFieldDefncxx . . $ OGRFieldDefn# *poField, |
| 600 | CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! int bApproxOK) |
| 601 | { |
| 602 | if (!bWriter_cxx . . $ OGRKMLLayer#bWriter_. || iNextKMLId_cxx . . $ OGRKMLLayer#iNextKMLId_. != 0) |
| 603 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 604 | |
| 605 | OGRFieldDefncxx . . $ OGRFieldDefn# oCleanCopycxx . . $ OGRFieldDefn#OGRFieldDefn(f8bad7d30df65bbb).(poField); |
| 606 | poFeatureDefn_cxx . . $ OGRKMLLayer#poFeatureDefn_.->AddFieldDefncxx . . $ OGRFeatureDefn#AddFieldDefn(f8bad7d30df65bbb).(&oCleanCopy); |
| 607 | |
| 608 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 609 | } |
| 610 | |
| 611 | /************************************************************************/ |
| 612 | /* SetLayerNumber() */ |
| 613 | /************************************************************************/ |
| 614 | |
| 615 | void OGRKMLLayercxx . . $ OGRKMLLayer#::SetLayerNumbercxx . . $ OGRKMLLayer#SetLayerNumber(d4f767463ce0a6b3).(int nLayer) |
| 616 | { |
| 617 | nLayerNumber_cxx . . $ OGRKMLLayer#nLayerNumber_. = nLayer; |
| 618 | } |
| 619 | |
| 620 | /************************************************************************/ |
| 621 | /* GetDataset() */ |
| 622 | /************************************************************************/ |
| 623 | |
| 624 | GDALDatasetcxx . . $ GDALDataset# *OGRKMLLayercxx . . $ OGRKMLLayer#::GetDatasetcxx . . $ OGRKMLLayer#GetDataset(76c1989f6ffbc048).() |
| 625 | { |
| 626 | return poDS_cxx . . $ OGRKMLLayer#poDS_.; |
| 627 | } |