1 : /******************************************************************************
2 : * $Id: kmlvector.cpp 17491 2009-08-01 17:22:37Z 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 44 : KMLVector::~KMLVector()
36 : {
37 44 : }
38 :
39 1678 : bool KMLVector::isLeaf(std::string const& sIn) const
40 : {
41 1678 : if( sIn.compare("name") == 0
42 : || sIn.compare("coordinates") == 0
43 : || sIn.compare("altitudeMode") == 0
44 : || sIn.compare("description") == 0 )
45 : {
46 339 : return true;
47 : }
48 1339 : return false;
49 : }
50 :
51 : // Container - FeatureContainer - Feature
52 :
53 1753 : bool KMLVector::isContainer(std::string const& sIn) const
54 : {
55 1753 : if( sIn.compare("Folder") == 0
56 : || sIn.compare("Document") == 0
57 : || sIn.compare("kml") == 0 )
58 : {
59 122 : return true;
60 : }
61 1631 : return false;
62 : }
63 :
64 1823 : bool KMLVector::isFeatureContainer(std::string const& sIn) const
65 : {
66 1823 : if( sIn.compare("MultiGeometry") == 0
67 : || sIn.compare("Placemark") == 0 )
68 : {
69 205 : return true;
70 : }
71 1618 : return false;
72 : }
73 :
74 1401 : bool KMLVector::isFeature(std::string const& sIn) const
75 : {
76 1401 : if( sIn.compare("Polygon") == 0
77 : || sIn.compare("LineString") == 0
78 : || sIn.compare("Point") == 0 )
79 : {
80 115 : return true;
81 : }
82 1286 : return false;
83 : }
84 :
85 1692 : bool KMLVector::isRest(std::string const& sIn) const
86 : {
87 1692 : if( sIn.compare("outerBoundaryIs") == 0
88 : || sIn.compare("innerBoundaryIs") == 0
89 : || sIn.compare("LinearRing") == 0 )
90 : {
91 198 : return true;
92 : }
93 1494 : return false;
94 : }
95 :
96 39 : void KMLVector::findLayers(KMLNode* poNode)
97 : {
98 39 : bool bEmpty = true;
99 :
100 : // Start with the trunk
101 39 : if( NULL == poNode )
102 : {
103 7 : nNumLayers_ = 0;
104 7 : poNode = poTrunk_;
105 : }
106 :
107 117 : if( isFeature(poNode->getName())
108 39 : || isFeatureContainer(poNode->getName())
109 39 : || ( isRest(poNode->getName())
110 : && poNode->getName().compare("kml") != 0 ) )
111 : {
112 0 : return;
113 : }
114 39 : else if( isContainer(poNode->getName()) )
115 : {
116 218 : for( int z = 0; z < (int) poNode->countChildren(); z++ )
117 : {
118 179 : if( isContainer(poNode->getChild(z)->getName()) )
119 : {
120 32 : findLayers(poNode->getChild(z));
121 : }
122 147 : else if( isFeatureContainer(poNode->getChild(z)->getName()) )
123 : {
124 90 : bEmpty = false;
125 : }
126 : }
127 :
128 39 : if(bEmpty)
129 : {
130 16 : return;
131 : }
132 :
133 23 : Nodetype nodeType = poNode->getType();
134 23 : if( isFeature(Nodetype2String(nodeType)) ||
135 : nodeType == Mixed ||
136 : nodeType == MultiGeometry || nodeType == MultiPoint ||
137 : nodeType == MultiLineString || nodeType == MultiPolygon)
138 : {
139 23 : poNode->setLayerNumber(nNumLayers_++);
140 23 : papoLayers_ = (KMLNode**)CPLRealloc(papoLayers_, nNumLayers_ * sizeof(KMLNode*));
141 23 : papoLayers_[nNumLayers_ - 1] = poNode;
142 : }
143 : else
144 : {
145 : CPLDebug( "KML", "We have a strange type here for node %s: %s",
146 0 : poNode->getName().c_str(), Nodetype2String(poNode->getType()).c_str() );
147 : }
148 : }
149 : else
150 : {
151 0 : CPLDebug("KML", "There is something wrong! Define KML_DEBUG to see details");
152 0 : if( CPLGetConfigOption("KML_DEBUG",NULL) != NULL )
153 0 : print();
154 : }
155 1947 : }
156 :
|