Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: KML Driver 4 : * Purpose: Specialization of the kml class, only for vectors in kml files. 5 : * Author: Jens Oberender, j.obi@troja.net 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2007, Jens Oberender 9 : * Copyright (c) 2009-2012, Even Rouault <even dot rouault at spatialys.com> 10 : * 11 : * SPDX-License-Identifier: MIT 12 : ****************************************************************************/ 13 : 14 : #include "cpl_port.h" 15 : #include "kmlvector.h" 16 : 17 : #include <string> 18 : 19 : #include "cpl_conv.h" 20 : #include "cpl_error.h" 21 : // #include "kmlnode.h" 22 : #include "kmlutility.h" 23 : 24 5659 : bool KMLVector::isLeaf(std::string const &sIn) const 25 : { 26 15806 : return sIn.compare("name") == 0 || sIn.compare("coordinates") == 0 || 27 15806 : sIn.compare("altitudeMode") == 0 || sIn.compare("description") == 0; 28 : } 29 : 30 : // Container - FeatureContainer - Feature 31 : 32 5971 : bool KMLVector::isContainer(std::string const &sIn) const 33 : { 34 11537 : return sIn.compare("Folder") == 0 || sIn.compare("Document") == 0 || 35 11537 : sIn.compare("kml") == 0; 36 : } 37 : 38 6108 : bool KMLVector::isFeatureContainer(std::string const &sIn) const 39 : { 40 12205 : return sIn.compare("MultiGeometry") == 0 || 41 6097 : sIn.compare("MultiPolygon") == 0 // non conformant 42 6096 : || sIn.compare("MultiLineString") == 0 // non conformant 43 6095 : || sIn.compare("MultiPoint") == 0 // non conformant 44 12205 : || sIn.compare("Placemark") == 0; 45 : } 46 : 47 4738 : bool KMLVector::isFeature(std::string const &sIn) const 48 : { 49 9239 : return sIn.compare("Polygon") == 0 || sIn.compare("LineString") == 0 || 50 9239 : sIn.compare("Point") == 0; 51 : } 52 : 53 5699 : bool KMLVector::isRest(std::string const &sIn) const 54 : { 55 11174 : return sIn.compare("outerBoundaryIs") == 0 || 56 11174 : sIn.compare("innerBoundaryIs") == 0 || 57 11138 : sIn.compare("LinearRing") == 0; 58 : } 59 : 60 144 : void KMLVector::findLayers(KMLNode *poNode, int bKeepEmptyContainers) 61 : { 62 144 : bool bEmpty = true; 63 : 64 : // Start with the trunk 65 144 : if (nullptr == poNode) 66 : { 67 23 : nNumLayers_ = 0; 68 23 : poNode = poTrunk_; 69 : } 70 : 71 288 : if (isFeature(poNode->getName()) || isFeatureContainer(poNode->getName()) || 72 144 : (isRest(poNode->getName()) && poNode->getName().compare("kml") != 0)) 73 : { 74 0 : return; 75 : } 76 144 : else if (isContainer(poNode->getName())) 77 : { 78 730 : for (std::size_t z = 0; z < poNode->countChildren(); z++) 79 : { 80 586 : if (isContainer(poNode->getChild(z)->getName())) 81 : { 82 121 : findLayers(poNode->getChild(z), bKeepEmptyContainers); 83 : } 84 465 : else if (isFeatureContainer(poNode->getChild(z)->getName())) 85 : { 86 253 : bEmpty = false; 87 : } 88 : } 89 : 90 144 : if (bKeepEmptyContainers && poNode->getName() == "Folder") 91 : { 92 6 : if (!bEmpty) 93 3 : poNode->eliminateEmpty(this); 94 : } 95 138 : else if (bEmpty) 96 : { 97 61 : return; 98 : } 99 : 100 83 : Nodetype nodeType = poNode->getType(); 101 160 : if (bKeepEmptyContainers || isFeature(Nodetype2String(nodeType)) || 102 3 : nodeType == Mixed || nodeType == MultiGeometry || 103 160 : nodeType == MultiPoint || nodeType == MultiLineString || 104 0 : nodeType == MultiPolygon) 105 : { 106 83 : poNode->setLayerNumber(nNumLayers_++); 107 83 : papoLayers_ = static_cast<KMLNode **>( 108 83 : CPLRealloc(papoLayers_, nNumLayers_ * sizeof(KMLNode *))); 109 83 : papoLayers_[nNumLayers_ - 1] = poNode; 110 : } 111 : else 112 : { 113 0 : CPLDebug("KML", "We have a strange type here for node %s: %s", 114 0 : poNode->getName().c_str(), 115 0 : Nodetype2String(poNode->getType()).c_str()); 116 : } 117 : } 118 : else 119 : { 120 0 : CPLDebug("KML", 121 : "There is something wrong! Define KML_DEBUG to see details"); 122 0 : if (CPLGetConfigOption("KML_DEBUG", nullptr) != nullptr) 123 0 : print(); 124 : } 125 : }