From 7c4f2b7d1ff32cd18c99b6a0a685c443307eea84 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 31 May 2010 15:51:59 +0000 Subject: [PATCH] Added support for a wider range of gpx files --- examples/osggpx/osggpx.cpp | 56 +++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/examples/osggpx/osggpx.cpp b/examples/osggpx/osggpx.cpp index 4cde32493..747be6e58 100644 --- a/examples/osggpx/osggpx.cpp +++ b/examples/osggpx/osggpx.cpp @@ -134,7 +134,57 @@ Track* readTrack(const std::string& filename) itr != root->children.end(); ++itr) { - if ((*itr)->name=="trk") + if ((*itr)->name=="rte") + { + osg::ref_ptr track = new Track; + track->setName(filename); + + osg::ref_ptr trackSegment = new TrackSegment; + for(osgDB::XmlNode::Children::iterator sitr = (*itr)->children.begin(); + sitr != (*itr)->children.end(); + ++sitr) + { + if ((*sitr)->name=="rtept" ) + { + osgDB::XmlNode* trkpt = sitr->get(); + TrackSegment::TrackPoint point; + bool valid = false; + if (trkpt->properties.count(latitude)!=0) + { + valid = true; + point.latitude = osg::asciiToDouble(trkpt->properties[latitude].c_str()); + } + if (trkpt->properties.count(longitude)!=0) + { + valid = true; + point.longitude = osg::asciiToDouble(trkpt->properties[longitude].c_str()); + } + + for(osgDB::XmlNode::Children::iterator pitr = trkpt->children.begin(); + pitr != trkpt->children.end(); + ++pitr) + { + if ((*pitr)->name=="ele") point.elevation = osg::asciiToDouble((*pitr)->contents.c_str()); + else if ((*pitr)->name=="time") point.time = convertTime((*pitr)->contents); + } + + if (valid) + { + osg::notify(osg::NOTICE)<<" point.latitude="< track = new Track; track->setName(filename); @@ -150,7 +200,7 @@ Track* readTrack(const std::string& filename) sitr != (*citr)->children.end(); ++sitr) { - if ((*sitr)->name=="trkpt") + if ((*sitr)->name=="trkpt" || (*sitr)->name=="rtept" ) { osgDB::XmlNode* trkpt = sitr->get(); TrackSegment::TrackPoint point; @@ -187,8 +237,6 @@ Track* readTrack(const std::string& filename) } } } - - return track.release(); } }