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