LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/kml - kmlvector.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 47 55 85.5 %
Date: 2024-04-27 17:22:41 Functions: 8 8 100.0 %

          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             :  * Permission is hereby granted, free of charge, to any person obtaining a
      12             :  * copy of this software and associated documentation files (the "Software"),
      13             :  * to deal in the Software without restriction, including without limitation
      14             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15             :  * and/or sell copies of the Software, and to permit persons to whom the
      16             :  * Software is furnished to do so, subject to the following conditions:
      17             :  *
      18             :  * The above copyright notice and this permission notice shall be included
      19             :  * in all copies or substantial portions of the Software.
      20             :  *
      21             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27             :  * DEALINGS IN THE SOFTWARE.
      28             :  ****************************************************************************/
      29             : 
      30             : #include "cpl_port.h"
      31             : #include "kmlvector.h"
      32             : 
      33             : #include <string>
      34             : 
      35             : #include "cpl_conv.h"
      36             : #include "cpl_error.h"
      37             : // #include "kmlnode.h"
      38             : #include "kmlutility.h"
      39             : 
      40          50 : KMLVector::~KMLVector()
      41             : {
      42          50 : }
      43             : 
      44        5659 : bool KMLVector::isLeaf(std::string const &sIn) const
      45             : {
      46       15806 :     return sIn.compare("name") == 0 || sIn.compare("coordinates") == 0 ||
      47       15806 :            sIn.compare("altitudeMode") == 0 || sIn.compare("description") == 0;
      48             : }
      49             : 
      50             : // Container - FeatureContainer - Feature
      51             : 
      52        5971 : bool KMLVector::isContainer(std::string const &sIn) const
      53             : {
      54       11537 :     return sIn.compare("Folder") == 0 || sIn.compare("Document") == 0 ||
      55       11537 :            sIn.compare("kml") == 0;
      56             : }
      57             : 
      58        6108 : bool KMLVector::isFeatureContainer(std::string const &sIn) const
      59             : {
      60       12205 :     return sIn.compare("MultiGeometry") == 0 ||
      61        6097 :            sIn.compare("MultiPolygon") == 0        // non conformant
      62        6096 :            || sIn.compare("MultiLineString") == 0  // non conformant
      63        6095 :            || sIn.compare("MultiPoint") == 0       // non conformant
      64       12205 :            || sIn.compare("Placemark") == 0;
      65             : }
      66             : 
      67        4738 : bool KMLVector::isFeature(std::string const &sIn) const
      68             : {
      69        9239 :     return sIn.compare("Polygon") == 0 || sIn.compare("LineString") == 0 ||
      70        9239 :            sIn.compare("Point") == 0;
      71             : }
      72             : 
      73        5699 : bool KMLVector::isRest(std::string const &sIn) const
      74             : {
      75       11174 :     return sIn.compare("outerBoundaryIs") == 0 ||
      76       11174 :            sIn.compare("innerBoundaryIs") == 0 ||
      77       11138 :            sIn.compare("LinearRing") == 0;
      78             : }
      79             : 
      80         144 : void KMLVector::findLayers(KMLNode *poNode, int bKeepEmptyContainers)
      81             : {
      82         144 :     bool bEmpty = true;
      83             : 
      84             :     // Start with the trunk
      85         144 :     if (nullptr == poNode)
      86             :     {
      87          23 :         nNumLayers_ = 0;
      88          23 :         poNode = poTrunk_;
      89             :     }
      90             : 
      91         288 :     if (isFeature(poNode->getName()) || isFeatureContainer(poNode->getName()) ||
      92         144 :         (isRest(poNode->getName()) && poNode->getName().compare("kml") != 0))
      93             :     {
      94           0 :         return;
      95             :     }
      96         144 :     else if (isContainer(poNode->getName()))
      97             :     {
      98         730 :         for (int z = 0; z < (int)poNode->countChildren(); z++)
      99             :         {
     100         586 :             if (isContainer(poNode->getChild(z)->getName()))
     101             :             {
     102         121 :                 findLayers(poNode->getChild(z), bKeepEmptyContainers);
     103             :             }
     104         465 :             else if (isFeatureContainer(poNode->getChild(z)->getName()))
     105             :             {
     106         253 :                 bEmpty = false;
     107             :             }
     108             :         }
     109             : 
     110         144 :         if (bKeepEmptyContainers && poNode->getName() == "Folder")
     111             :         {
     112           6 :             if (!bEmpty)
     113           3 :                 poNode->eliminateEmpty(this);
     114             :         }
     115         138 :         else if (bEmpty)
     116             :         {
     117          61 :             return;
     118             :         }
     119             : 
     120          83 :         Nodetype nodeType = poNode->getType();
     121         160 :         if (bKeepEmptyContainers || isFeature(Nodetype2String(nodeType)) ||
     122           3 :             nodeType == Mixed || nodeType == MultiGeometry ||
     123         160 :             nodeType == MultiPoint || nodeType == MultiLineString ||
     124           0 :             nodeType == MultiPolygon)
     125             :         {
     126          83 :             poNode->setLayerNumber(nNumLayers_++);
     127          83 :             papoLayers_ = static_cast<KMLNode **>(
     128          83 :                 CPLRealloc(papoLayers_, nNumLayers_ * sizeof(KMLNode *)));
     129          83 :             papoLayers_[nNumLayers_ - 1] = poNode;
     130             :         }
     131             :         else
     132             :         {
     133           0 :             CPLDebug("KML", "We have a strange type here for node %s: %s",
     134           0 :                      poNode->getName().c_str(),
     135           0 :                      Nodetype2String(poNode->getType()).c_str());
     136             :         }
     137             :     }
     138             :     else
     139             :     {
     140           0 :         CPLDebug("KML",
     141             :                  "There is something wrong!  Define KML_DEBUG to see details");
     142           0 :         if (CPLGetConfigOption("KML_DEBUG", nullptr) != nullptr)
     143           0 :             print();
     144             :     }
     145             : }

Generated by: LCOV version 1.14