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-12-26 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              92 : KMLVector::~KMLVector()
      36                 : {
      37              92 : }
      38                 : 
      39            1690 : bool KMLVector::isLeaf(std::string const& sIn) const
      40                 : {
      41            1690 :     if( sIn.compare("name") == 0
      42                 :         || sIn.compare("coordinates") == 0
      43                 :         || sIn.compare("altitudeMode") == 0
      44                 :         || sIn.compare("description") == 0 )
      45                 :     {
      46             344 :         return true;
      47                 :     }
      48            1346 :     return false;
      49                 : }
      50                 : 
      51                 : // Container - FeatureContainer - Feature
      52                 : 
      53            1776 : bool KMLVector::isContainer(std::string const& sIn) const
      54                 : {
      55            1776 :     if( sIn.compare("Folder") == 0
      56                 :         || sIn.compare("Document") == 0
      57                 :         || sIn.compare("kml") == 0 )
      58                 :     {
      59             138 :         return true;
      60                 :     }
      61            1638 :     return false;
      62                 : }
      63                 : 
      64            1843 : bool KMLVector::isFeatureContainer(std::string const& sIn) const
      65                 : {
      66            1843 :     if( sIn.compare("MultiGeometry") == 0
      67                 :         || sIn.compare("Placemark") == 0 )
      68                 :     {
      69             208 :         return true;
      70                 :     }
      71            1635 :     return false;
      72                 : }
      73                 : 
      74            1414 : bool KMLVector::isFeature(std::string const& sIn) const
      75                 : {
      76            1414 :     if( sIn.compare("Polygon") == 0
      77                 :         || sIn.compare("LineString") == 0
      78                 :         || sIn.compare("Point") == 0 )
      79                 :     {
      80             115 :         return true;
      81                 :     }
      82            1299 :     return false;
      83                 : }
      84                 : 
      85            1710 : bool KMLVector::isRest(std::string const& sIn) const
      86                 : {
      87            1710 :     if( sIn.compare("outerBoundaryIs") == 0
      88                 :         || sIn.compare("innerBoundaryIs") == 0
      89                 :         || sIn.compare("LinearRing") == 0 )
      90                 :     {
      91             198 :         return true;
      92                 :     }
      93            1512 :     return false;
      94                 : }
      95                 : 
      96              45 : void KMLVector::findLayers(KMLNode* poNode, int bKeepEmptyContainers)
      97                 : {
      98              45 :     bool bEmpty = true;
      99                 : 
     100                 :     // Start with the trunk
     101              45 :     if( NULL == poNode )
     102                 :     {
     103               9 :         nNumLayers_ = 0;
     104               9 :         poNode = poTrunk_;
     105                 :     }
     106                 : 
     107             135 :     if( isFeature(poNode->getName())
     108              45 :         || isFeatureContainer(poNode->getName())
     109              45 :         || ( isRest(poNode->getName())
     110                 :              && poNode->getName().compare("kml") != 0 ) )
     111                 :     {
     112               0 :         return;
     113                 :     }
     114              45 :     else if( isContainer(poNode->getName()) )
     115                 :     {
     116             233 :         for( int z = 0; z < (int) poNode->countChildren(); z++ )
     117                 :         {
     118             188 :             if( isContainer(poNode->getChild(z)->getName()) )
     119                 :             {
     120              36 :                 findLayers(poNode->getChild(z), bKeepEmptyContainers);
     121                 :             }
     122             152 :             else if( isFeatureContainer(poNode->getChild(z)->getName()) )
     123                 :             {
     124              91 :                 bEmpty = false;
     125                 :             }
     126                 :         }
     127                 : 
     128              45 :         if( bKeepEmptyContainers && poNode->getName() == "Folder" )
     129                 :         {
     130               2 :             if (!bEmpty)
     131               1 :                 poNode->eliminateEmpty(this);
     132                 :         }
     133              43 :         else if(bEmpty)
     134                 :         {
     135              20 :             return;
     136                 :         }
     137                 :         
     138              25 :         Nodetype nodeType = poNode->getType();
     139              48 :         if( bKeepEmptyContainers ||
     140              23 :             isFeature(Nodetype2String(nodeType)) ||
     141                 :             nodeType == Mixed ||
     142                 :             nodeType == MultiGeometry || nodeType == MultiPoint ||
     143                 :             nodeType == MultiLineString || nodeType == MultiPolygon)
     144                 :         {
     145              25 :             poNode->setLayerNumber(nNumLayers_++);
     146              25 :             papoLayers_ = (KMLNode**)CPLRealloc(papoLayers_, nNumLayers_ * sizeof(KMLNode*));
     147              25 :             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            2139 : }
     162                 : 

Generated by: LCOV version 1.7