LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/kml - kmlvector.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 53 48 90.6 %
Date: 2012-04-28 Functions: 12 9 75.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: kmlvector.cpp 23978 2012-02-14 20:42:34Z rouault $
       3                 :  *
       4                 :  * Project:  KML Driver
       5                 :  * Purpose:  Specialization of the kml class, only for vectors in kml files.
       6                 :  * Author:   Jens Oberender, j.obi@troja.net
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2007, Jens Oberender
      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                 : #include "kmlvector.h"
      30                 : #include "kmlnode.h"
      31                 : #include "cpl_conv.h"
      32                 : // std
      33                 : #include <string>
      34                 : 
      35             164 : KMLVector::~KMLVector()
      36                 : {
      37             164 : }
      38                 : 
      39            3380 : bool KMLVector::isLeaf(std::string const& sIn) const
      40                 : {
      41            3380 :     if( sIn.compare("name") == 0
      42                 :         || sIn.compare("coordinates") == 0
      43                 :         || sIn.compare("altitudeMode") == 0
      44                 :         || sIn.compare("description") == 0 )
      45                 :     {
      46             688 :         return true;
      47                 :     }
      48            2692 :     return false;
      49                 : }
      50                 : 
      51                 : // Container - FeatureContainer - Feature
      52                 : 
      53            3552 : bool KMLVector::isContainer(std::string const& sIn) const
      54                 : {
      55            3552 :     if( sIn.compare("Folder") == 0
      56                 :         || sIn.compare("Document") == 0
      57                 :         || sIn.compare("kml") == 0 )
      58                 :     {
      59             276 :         return true;
      60                 :     }
      61            3276 :     return false;
      62                 : }
      63                 : 
      64            3686 : bool KMLVector::isFeatureContainer(std::string const& sIn) const
      65                 : {
      66            3686 :     if( sIn.compare("MultiGeometry") == 0
      67                 :         || sIn.compare("Placemark") == 0 )
      68                 :     {
      69             416 :         return true;
      70                 :     }
      71            3270 :     return false;
      72                 : }
      73                 : 
      74            2828 : bool KMLVector::isFeature(std::string const& sIn) const
      75                 : {
      76            2828 :     if( sIn.compare("Polygon") == 0
      77                 :         || sIn.compare("LineString") == 0
      78                 :         || sIn.compare("Point") == 0 )
      79                 :     {
      80             230 :         return true;
      81                 :     }
      82            2598 :     return false;
      83                 : }
      84                 : 
      85            3420 : bool KMLVector::isRest(std::string const& sIn) const
      86                 : {
      87            3420 :     if( sIn.compare("outerBoundaryIs") == 0
      88                 :         || sIn.compare("innerBoundaryIs") == 0
      89                 :         || sIn.compare("LinearRing") == 0 )
      90                 :     {
      91             396 :         return true;
      92                 :     }
      93            3024 :     return false;
      94                 : }
      95                 : 
      96              90 : void KMLVector::findLayers(KMLNode* poNode, int bKeepEmptyContainers)
      97                 : {
      98              90 :     bool bEmpty = true;
      99                 : 
     100                 :     // Start with the trunk
     101              90 :     if( NULL == poNode )
     102                 :     {
     103              18 :         nNumLayers_ = 0;
     104              18 :         poNode = poTrunk_;
     105                 :     }
     106                 : 
     107             270 :     if( isFeature(poNode->getName())
     108              90 :         || isFeatureContainer(poNode->getName())
     109              90 :         || ( isRest(poNode->getName())
     110                 :              && poNode->getName().compare("kml") != 0 ) )
     111                 :     {
     112               0 :         return;
     113                 :     }
     114              90 :     else if( isContainer(poNode->getName()) )
     115                 :     {
     116             466 :         for( int z = 0; z < (int) poNode->countChildren(); z++ )
     117                 :         {
     118             376 :             if( isContainer(poNode->getChild(z)->getName()) )
     119                 :             {
     120              72 :                 findLayers(poNode->getChild(z), bKeepEmptyContainers);
     121                 :             }
     122             304 :             else if( isFeatureContainer(poNode->getChild(z)->getName()) )
     123                 :             {
     124             182 :                 bEmpty = false;
     125                 :             }
     126                 :         }
     127                 : 
     128              90 :         if( bKeepEmptyContainers && poNode->getName() == "Folder" )
     129                 :         {
     130               4 :             if (!bEmpty)
     131               2 :                 poNode->eliminateEmpty(this);
     132                 :         }
     133              86 :         else if(bEmpty)
     134                 :         {
     135              40 :             return;
     136                 :         }
     137                 :         
     138              50 :         Nodetype nodeType = poNode->getType();
     139              96 :         if( bKeepEmptyContainers ||
     140              46 :             isFeature(Nodetype2String(nodeType)) ||
     141                 :             nodeType == Mixed ||
     142                 :             nodeType == MultiGeometry || nodeType == MultiPoint ||
     143                 :             nodeType == MultiLineString || nodeType == MultiPolygon)
     144                 :         {
     145              50 :             poNode->setLayerNumber(nNumLayers_++);
     146              50 :             papoLayers_ = (KMLNode**)CPLRealloc(papoLayers_, nNumLayers_ * sizeof(KMLNode*));
     147              50 :             papoLayers_[nNumLayers_ - 1] = poNode;
     148                 :         }
     149                 :         else
     150                 :         {
     151                 :             CPLDebug( "KML", "We have a strange type here for node %s: %s",
     152               0 :                       poNode->getName().c_str(), Nodetype2String(poNode->getType()).c_str() );
     153                 :         }
     154                 :     }
     155                 :     else
     156                 :     {
     157               0 :         CPLDebug("KML", "There is something wrong!  Define KML_DEBUG to see details");
     158               0 :         if( CPLGetConfigOption("KML_DEBUG",NULL) != NULL )
     159               0 :             print();
     160                 :     }
     161            4029 : }
     162                 : 

Generated by: LCOV version 1.7