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