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-11-21 22:18:42 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             :  * 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          50 : KMLVector::~KMLVector()
      25             : {
      26          50 : }
      27             : 
      28        5659 : bool KMLVector::isLeaf(std::string const &sIn) const
      29             : {
      30       15806 :     return sIn.compare("name") == 0 || sIn.compare("coordinates") == 0 ||
      31       15806 :            sIn.compare("altitudeMode") == 0 || sIn.compare("description") == 0;
      32             : }
      33             : 
      34             : // Container - FeatureContainer - Feature
      35             : 
      36        5971 : bool KMLVector::isContainer(std::string const &sIn) const
      37             : {
      38       11537 :     return sIn.compare("Folder") == 0 || sIn.compare("Document") == 0 ||
      39       11537 :            sIn.compare("kml") == 0;
      40             : }
      41             : 
      42        6108 : bool KMLVector::isFeatureContainer(std::string const &sIn) const
      43             : {
      44       12205 :     return sIn.compare("MultiGeometry") == 0 ||
      45        6097 :            sIn.compare("MultiPolygon") == 0        // non conformant
      46        6096 :            || sIn.compare("MultiLineString") == 0  // non conformant
      47        6095 :            || sIn.compare("MultiPoint") == 0       // non conformant
      48       12205 :            || sIn.compare("Placemark") == 0;
      49             : }
      50             : 
      51        4738 : bool KMLVector::isFeature(std::string const &sIn) const
      52             : {
      53        9239 :     return sIn.compare("Polygon") == 0 || sIn.compare("LineString") == 0 ||
      54        9239 :            sIn.compare("Point") == 0;
      55             : }
      56             : 
      57        5699 : bool KMLVector::isRest(std::string const &sIn) const
      58             : {
      59       11174 :     return sIn.compare("outerBoundaryIs") == 0 ||
      60       11174 :            sIn.compare("innerBoundaryIs") == 0 ||
      61       11138 :            sIn.compare("LinearRing") == 0;
      62             : }
      63             : 
      64         144 : void KMLVector::findLayers(KMLNode *poNode, int bKeepEmptyContainers)
      65             : {
      66         144 :     bool bEmpty = true;
      67             : 
      68             :     // Start with the trunk
      69         144 :     if (nullptr == poNode)
      70             :     {
      71          23 :         nNumLayers_ = 0;
      72          23 :         poNode = poTrunk_;
      73             :     }
      74             : 
      75         288 :     if (isFeature(poNode->getName()) || isFeatureContainer(poNode->getName()) ||
      76         144 :         (isRest(poNode->getName()) && poNode->getName().compare("kml") != 0))
      77             :     {
      78           0 :         return;
      79             :     }
      80         144 :     else if (isContainer(poNode->getName()))
      81             :     {
      82         730 :         for (int z = 0; z < (int)poNode->countChildren(); z++)
      83             :         {
      84         586 :             if (isContainer(poNode->getChild(z)->getName()))
      85             :             {
      86         121 :                 findLayers(poNode->getChild(z), bKeepEmptyContainers);
      87             :             }
      88         465 :             else if (isFeatureContainer(poNode->getChild(z)->getName()))
      89             :             {
      90         253 :                 bEmpty = false;
      91             :             }
      92             :         }
      93             : 
      94         144 :         if (bKeepEmptyContainers && poNode->getName() == "Folder")
      95             :         {
      96           6 :             if (!bEmpty)
      97           3 :                 poNode->eliminateEmpty(this);
      98             :         }
      99         138 :         else if (bEmpty)
     100             :         {
     101          61 :             return;
     102             :         }
     103             : 
     104          83 :         Nodetype nodeType = poNode->getType();
     105         160 :         if (bKeepEmptyContainers || isFeature(Nodetype2String(nodeType)) ||
     106           3 :             nodeType == Mixed || nodeType == MultiGeometry ||
     107         160 :             nodeType == MultiPoint || nodeType == MultiLineString ||
     108           0 :             nodeType == MultiPolygon)
     109             :         {
     110          83 :             poNode->setLayerNumber(nNumLayers_++);
     111          83 :             papoLayers_ = static_cast<KMLNode **>(
     112          83 :                 CPLRealloc(papoLayers_, nNumLayers_ * sizeof(KMLNode *)));
     113          83 :             papoLayers_[nNumLayers_ - 1] = poNode;
     114             :         }
     115             :         else
     116             :         {
     117           0 :             CPLDebug("KML", "We have a strange type here for node %s: %s",
     118           0 :                      poNode->getName().c_str(),
     119           0 :                      Nodetype2String(poNode->getType()).c_str());
     120             :         }
     121             :     }
     122             :     else
     123             :     {
     124           0 :         CPLDebug("KML",
     125             :                  "There is something wrong!  Define KML_DEBUG to see details");
     126           0 :         if (CPLGetConfigOption("KML_DEBUG", nullptr) != nullptr)
     127           0 :             print();
     128             :     }
     129             : }

Generated by: LCOV version 1.14