Changeset 12152
- Timestamp:
- 09/14/07 03:58:33 (1 year ago)
- Files:
-
- trunk/gdal/ogr/ogrsf_frmts/kml/kmlnode.cpp (modified) (14 diffs)
- trunk/gdal/ogr/ogrsf_frmts/kml/kmlnode.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/gdal/ogr/ogrsf_frmts/kml/kmlnode.cpp
r12150 r12152 37 37 /************************************************************************/ 38 38 39 std::string Nodetype2String(Nodetype t) { 39 std::string Nodetype2String(Nodetype t) 40 { 40 41 if(t == Empty) 41 42 return "Empty"; … … 101 102 /* KMLnode methods */ 102 103 /************************************************************************/ 103 KMLnode::KMLnode() { 104 105 KMLnode::KMLnode() 106 { 104 107 this->sName = ""; 105 108 this->poParent = NULL; … … 112 115 } 113 116 114 KMLnode::~KMLnode() { 115 for(unsigned short z = 0; z < this->pvpoChildren->size();z++) 116 { 117 delete(this->pvpoChildren->at(z)); 118 } 117 KMLnode::~KMLnode() 118 { 119 kml_nodes_t::size_type nCount = 0; 120 121 for( nCount = 0; nCount < pvpoChildren->size(); ++nCount ) 122 { 123 delete (pvpoChildren->at( nCount )); 124 } 125 119 126 delete(this->pvpoChildren); 120 127 delete(this->pvsContent); 121 for(unsigned short z = 0; z < this->pvoAttributes->size();z++) 122 { 123 delete this->pvoAttributes->at(z); 124 } 125 delete(this->pvoAttributes); 126 if(this->psExtent != NULL) 127 delete this->psExtent; 128 } 129 130 void KMLnode::print(unsigned int what) { 128 129 for( nCount = 0; nCount < pvoAttributes->size(); ++nCount) 130 { 131 delete pvoAttributes->at(nCount); 132 } 133 134 delete(pvoAttributes); 135 136 if( psExtent != NULL ) 137 delete psExtent; 138 } 139 140 void KMLnode::print(unsigned int what) 141 { 131 142 std::string indent(""); 143 132 144 for(unsigned int z = 0; z < this->nLevel; z++) 133 145 indent += " "; 134 if(this->nLevel > 0) { 146 147 if(this->nLevel > 0) 148 { 135 149 if(this->nLayerNumber > -1) 136 150 if(this->psExtent != NULL) … … 167 181 } 168 182 169 void KMLnode::classify(KML *kmlclass) { 183 void KMLnode::classify(KML *kmlclass) 184 { 170 185 Nodetype curr = Unknown, all = Empty; 171 186 … … 211 226 } 212 227 213 void KMLnode::eliminateEmpty(KML *kmlclass) { 228 void KMLnode::eliminateEmpty(KML *kmlclass) 229 { 214 230 for(unsigned int z = 0; z < this->pvpoChildren->size(); z++) { 215 231 if(this->pvpoChildren->at(z)->eType == Empty && … … 226 242 } 227 243 228 void KMLnode::setType(Nodetype oNotet) { 244 void KMLnode::setType(Nodetype oNotet) 245 { 229 246 this->eType = oNotet; 230 247 } 231 248 232 Nodetype KMLnode::getType() { 249 Nodetype KMLnode::getType() 250 { 233 251 return this->eType; 234 252 } 235 253 236 void KMLnode::setName(std::string const& sIn) { 254 void KMLnode::setName(std::string const& sIn) 255 { 237 256 this->sName = sIn; 238 257 } 239 258 240 std::string KMLnode::getName() { 259 std::string KMLnode::getName() 260 { 241 261 return this->sName; 242 262 } 243 263 244 void KMLnode::setLevel(unsigned int nLev) { 264 void KMLnode::setLevel(unsigned int nLev) 265 { 245 266 this->nLevel = nLev; 246 267 } 247 268 248 unsigned int KMLnode::getLevel() { 269 unsigned int KMLnode::getLevel() 270 { 249 271 return this->nLevel; 250 272 } 251 273 252 void KMLnode::addAttribute(Attribute *poAttr) { 274 void KMLnode::addAttribute(Attribute *poAttr) 275 { 253 276 this->pvoAttributes->push_back(poAttr); 254 277 } 255 278 256 void KMLnode::setParent(KMLnode* poPar) { 279 void KMLnode::setParent(KMLnode* poPar) 280 { 257 281 this->poParent = poPar; 258 282 } 259 283 260 KMLnode* KMLnode::getParent() { 284 KMLnode* KMLnode::getParent() 285 { 261 286 return this->poParent; 262 287 } 263 288 264 void KMLnode::addChildren(KMLnode *poChil) { 289 void KMLnode::addChildren(KMLnode *poChil) 290 { 265 291 this->pvpoChildren->push_back(poChil); 266 292 } 267 293 268 unsigned short KMLnode::countChildren() { 294 unsigned short KMLnode::countChildren() 295 { 269 296 return this->pvpoChildren->size(); 270 297 } 271 298 272 KMLnode* KMLnode::getChild(unsigned short nNum) { 299 KMLnode* KMLnode::getChild(unsigned short nNum) 300 { 273 301 return this->pvpoChildren->at(nNum); 274 302 } 275 303 276 void KMLnode::addContent(std::string const& sCon) { 304 void KMLnode::addContent(std::string const& sCon) 305 { 277 306 this->pvsContent->push_back(sCon); 278 307 } 279 308 280 void KMLnode::appendContent(std::string sCon) { 309 void KMLnode::appendContent(std::string sCon) 310 { 281 311 this->pvsContent->at(this->pvsContent->size()-1) += sCon; 282 312 } 283 313 284 std::string KMLnode::getContent(unsigned short nNum) { 314 std::string KMLnode::getContent(unsigned short nNum) 315 { 285 316 if(nNum >= this->pvsContent->size()) 286 317 return NULL; … … 288 319 } 289 320 290 void KMLnode::deleteContent(unsigned short nNum) { 321 void KMLnode::deleteContent(unsigned short nNum) 322 { 291 323 if(nNum >= this->pvsContent->size()) 292 324 return; … … 294 326 } 295 327 296 unsigned short KMLnode::numContent() { 328 unsigned short KMLnode::numContent() 329 { 297 330 return this->pvsContent->size(); 298 331 } 299 332 300 void KMLnode::setLayerNumber(short nNum) { 333 void KMLnode::setLayerNumber(short nNum) 334 { 301 335 this->nLayerNumber = nNum; 302 336 } 303 337 304 short KMLnode::getLayerNumber() { 338 short KMLnode::getLayerNumber() 339 { 305 340 return this->nLayerNumber; 306 341 } 307 342 308 KMLnode* KMLnode::getLayer(unsigned short nNum) { 343 KMLnode* KMLnode::getLayer(unsigned short nNum) 344 { 309 345 KMLnode *poTmp; 310 346 if(this->nLayerNumber == nNum) 311 347 return this; 348 312 349 for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 350 { 313 351 if((poTmp = this->pvpoChildren->at(nCount)->getLayer(nNum)) != NULL) 314 352 return poTmp; 353 } 354 315 355 return NULL; 316 356 } 317 357 318 std::string KMLnode::getNameElement() { 358 std::string KMLnode::getNameElement() 359 { 360 std::string sContent; 361 362 for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 363 { 364 if(this->pvpoChildren->at(nCount)->sName.compare("name") == 0) 365 { 366 sContent = this->pvpoChildren->at(nCount)->pvsContent->at(0); 367 for(unsigned short nCount2 = 1; nCount2 < this->pvpoChildren->at(nCount)->pvsContent->size(); nCount2++) 368 { 369 sContent += " " + this->pvpoChildren->at(nCount)->pvsContent->at(nCount2); 370 } 371 return sContent; 372 } 373 } 374 375 return sContent; 376 } 377 378 std::string KMLnode::getDescriptionElement() 379 { 319 380 std::string sContent; 320 381 for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 321 382 { 322 if(this->pvpoChildren->at(nCount)->sName.compare(" name") == 0)383 if(this->pvpoChildren->at(nCount)->sName.compare("description") == 0) 323 384 { 324 385 sContent = this->pvpoChildren->at(nCount)->pvsContent->at(0); 325 386 for(unsigned short nCount2 = 1; nCount2 < this->pvpoChildren->at(nCount)->pvsContent->size(); nCount2++) 387 { 326 388 sContent += " " + this->pvpoChildren->at(nCount)->pvsContent->at(nCount2); 389 } 327 390 return sContent; 328 391 } … … 331 394 } 332 395 333 std::string KMLnode::getDescriptionElement() { 334 std::string sContent; 335 for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 336 { 337 if(this->pvpoChildren->at(nCount)->sName.compare("description") == 0) 338 { 339 sContent = this->pvpoChildren->at(nCount)->pvsContent->at(0); 340 for(unsigned short nCount2 = 1; nCount2 < this->pvpoChildren->at(nCount)->pvsContent->size(); nCount2++) 341 sContent += " " + this->pvpoChildren->at(nCount)->pvsContent->at(nCount2); 342 return sContent; 343 } 344 } 345 return ""; 346 } 347 348 short KMLnode::getNumFeatures() { 396 short KMLnode::getNumFeatures() 397 { 349 398 short nNum = 0; 350 399 for(unsigned short z = 0; z < this->pvpoChildren->size();z++) … … 597 646 } 598 647 599 void KMLnode::calcExtent(KML *poKMLClass) { 648 void KMLnode::calcExtent(KML *poKMLClass) 649 { 600 650 KMLnode *poTmp; 601 651 Coordinate *psCoors; … … 604 654 return; 605 655 // Handle Features 606 if(poKMLClass->isFeature(this->sName)) { 656 if(poKMLClass->isFeature(this->sName)) 657 { 607 658 this->psExtent = new Extent; 608 659 this->psExtent->dfX1 = this->psExtent->dfX2 = this->psExtent->dfY1 = this->psExtent->dfY2 = 0.0; 609 660 // Special for Polygons 610 if(this->sName.compare("Polygon") == 0) { 611 for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) { 612 if(this->pvpoChildren->at(nCount)->sName.compare("outerBoundaryIs") == 0 || 613 this->pvpoChildren->at(nCount)->sName.compare("innerBoundaryIs") == 0) { 614 if(this->pvpoChildren->at(nCount)->pvpoChildren->size() == 1) { 661 if(this->sName.compare("Polygon") == 0) 662 { 663 for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 664 { 665 if(this->pvpoChildren->at(nCount)->sName.compare("outerBoundaryIs") == 0 666 || this->pvpoChildren->at(nCount)->sName.compare("innerBoundaryIs") == 0) 667 { 668 if(this->pvpoChildren->at(nCount)->pvpoChildren->size() == 1) 669 { 615 670 poTmp = this->pvpoChildren->at(nCount)->pvpoChildren->at(0); 616 for(unsigned short nCount3 = 0; nCount3 < poTmp->pvpoChildren->size(); nCount3++) { 617 if(poTmp->pvpoChildren->at(nCount3)->sName.compare("coordinates") == 0) { 618 for(unsigned short nCount2 = 0; nCount2 < 619 poTmp->pvpoChildren->at(nCount3)->pvsContent->size(); nCount2++) { 671 for(unsigned short nCount3 = 0; nCount3 < poTmp->pvpoChildren->size(); nCount3++) 672 { 673 if(poTmp->pvpoChildren->at(nCount3)->sName.compare("coordinates") == 0) 674 { 675 for(unsigned short nCount2 = 0; 676 nCount2 < poTmp->pvpoChildren->at(nCount3)->pvsContent->size(); nCount2++) 677 { 620 678 psCoors = ParseCoordinate(poTmp->pvpoChildren->at(nCount3)->pvsContent->at(nCount2)); 621 if(psCoors != NULL) { 679 if(psCoors != NULL) 680 { 622 681 if(psCoors->dfLongitude < this->psExtent->dfX1 || this->psExtent->dfX1 == 0) 623 682 this->psExtent->dfX1 = psCoors->dfLongitude; … … 637 696 } 638 697 // General for LineStrings and Points 639 } else { 640 for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) { 641 if(this->pvpoChildren->at(nCount)->sName.compare("coordinates") == 0) { 698 } 699 else 700 { 701 for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 702 { 703 if(this->pvpoChildren->at(nCount)->sName.compare("coordinates") == 0) 704 { 642 705 poTmp = this->pvpoChildren->at(nCount); 643 for(unsigned short nCount2 = 0; nCount2 < poTmp->pvsContent->size(); nCount2++) { 706 for(unsigned short nCount2 = 0; nCount2 < poTmp->pvsContent->size(); nCount2++) 707 { 644 708 psCoors = ParseCoordinate(poTmp->pvsContent->at(nCount2)); 645 if(psCoors != NULL) { 709 if(psCoors != NULL) 710 { 646 711 if(psCoors->dfLongitude < this->psExtent->dfX1 || this->psExtent->dfX1 == 0.0) 647 712 this->psExtent->dfX1 = psCoors->dfLongitude; … … 659 724 } 660 725 // Summarize Containers 661 } else if(poKMLClass->isFeatureContainer(this->sName) || 662 poKMLClass->isContainer(this->sName)) { 726 } 727 else if( poKMLClass->isFeatureContainer(this->sName) 728 || poKMLClass->isContainer(this->sName)) 729 { 663 730 this->psExtent = new Extent; 664 731 this->psExtent->dfX1 = this->psExtent->dfX2 = this->psExtent->dfY1 = this->psExtent->dfY2 = 0.0; 665 for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) { 732 for(unsigned short nCount = 0; nCount < this->pvpoChildren->size(); nCount++) 733 { 666 734 this->pvpoChildren->at(nCount)->calcExtent(poKMLClass); 667 if(this->pvpoChildren->at(nCount)->psExtent != NULL) { 735 if(this->pvpoChildren->at(nCount)->psExtent != NULL) 736 { 668 737 if(this->pvpoChildren->at(nCount)->psExtent->dfX1 < this->psExtent->dfX1 || 669 738 this->psExtent->dfX1 == 0) … … 683 752 } 684 753 685 Extent* KMLnode::getExtents() { 754 Extent* KMLnode::getExtents() 755 { 686 756 return this->psExtent; 687 757 } trunk/gdal/ogr/ogrsf_frmts/kml/kmlnode.h
r12150 r12152 43 43 { 44 44 private: 45 46 typedef std::vector<KMLnode*> kml_nodes_t; 47 kml_nodes_t* pvpoChildren; 48 49 typedef std::vector<std::string> kml_content_t; 50 kml_content_t* pvsContent; 51 52 typedef std::vector<Attribute*> kml_attributes_t; 53 kml_attributes_t* pvoAttributes; 54 55 KMLnode *poParent; 56 unsigned int nLevel; 45 57 std::string sName; 46 unsigned int nLevel; 47 KMLnode *poParent; 48 std::vector<KMLnode*> *pvpoChildren; 49 std::vector<std::string> *pvsContent; 50 std::vector<Attribute*> *pvoAttributes; 58 51 59 Nodetype eType; 52 60 // Layer number
