void TrackLayer::extractLayer() { DrawingLayer* extL = new DrawingLayer(tr("Extract - %1").arg(name())); extL->setUploadable(false); TrackNode* P; QList<TrackNode*> PL; const qreal coordPer10M = (double(COORD_MAX) * 2 / 40080000) * 2; for (int i=0; i < size(); i++) { if (TrackSegment* S = dynamic_cast<TrackSegment*>(get(i))) { if (S->size() < 2) continue; // Cope with walking tracks qreal konstant = coordPer10M; qreal meanSpeed = S->distance() / S->duration() * 3600; if (meanSpeed < 10.) konstant /= 3.; PL.clear(); P = g_backend.allocTrackNode(extL, S->getNode(0)->position() ); P->setTime(S->getNode(0)->time()); P->setElevation(S->getNode(0)->elevation()); P->setSpeed(S->getNode(0)->speed()); PL.append(P); int startP = 0; P = g_backend.allocTrackNode(extL, S->getNode(1)->position() ); P->setTime(S->getNode(1)->time()); P->setElevation(S->getNode(1)->elevation()); P->setSpeed(S->getNode(1)->speed()); PL.append(P); int endP = 1; for (int j=2; j < S->size(); j++) { P = g_backend.allocTrackNode(extL, S->getNode(j)->position() ); P->setTime(S->getNode(j)->time()); P->setElevation(S->getNode(j)->elevation()); P->setSpeed(S->getNode(j)->speed()); PL.append(P); endP = PL.size()-1; LineF l(PL[startP]->position(), PL[endP]->position()); for (int k=startP+1; k < endP; k++) { qreal d = l.distance(PL[k]->position()); if (d < konstant) { Node* P = PL[k]; PL.removeAt(k); g_backend.deallocFeature(extL, P); endP--; } else startP = k; } } Way* R = g_backend.allocWay(extL); R->setLastUpdated(Feature::OSMServer); extL->add(R); for (int i=0; i < PL.size(); i++) { extL->add(PL[i]); R->add(PL[i]); } } } p->theDocument->add(extL); }
TrackNode * TrackNode::fromGPX(Document* d, Layer* L, QXmlStreamReader& stream) { qreal Lat = stream.attributes().value("lat").toString().toDouble(); qreal Lon = stream.attributes().value("lon").toString().toDouble(); QString sid = (stream.attributes().hasAttribute("id") ? stream.attributes().value("id").toString() : stream.attributes().value("xml:id").toString()); IFeature::FId id(IFeature::Point, sid.toLongLong()); TrackNode* Pt = CAST_TRACKNODE(d->getFeature(id)); if (!Pt) { Pt = g_backend.allocTrackNode(L, Coord(Lon,Lat)); Pt->setId(id); Pt->setLastUpdated(Feature::Log); L->add(Pt); } else { Pt->setPosition(Coord(Lon,Lat)); if (Pt->lastUpdated() == Feature::NotYetDownloaded) Pt->setLastUpdated(Feature::OSMServer); } if (stream.name() == "wpt") Pt->setTag("_waypoint_", "yes"); QDateTime time = QDateTime::currentDateTime(); stream.readNext(); while(!stream.atEnd() && !stream.isEndElement()) { if (stream.name() == "time") { stream.readNext(); QString dtm = stream.text().toString(); time = QDateTime::fromString(dtm.left(19), Qt::ISODate); stream.readNext(); } else if (stream.name() == "ele") { stream.readNext(); Pt->setElevation(stream.text().toString().toFloat()); stream.readNext(); } else if (stream.name() == "speed") { stream.readNext(); Pt->setSpeed(stream.text().toString().toFloat()); stream.readNext(); } else if (stream.name() == "name") { stream.readNext(); Pt->setTag("name", stream.text().toString()); stream.readNext(); } else if (stream.name() == "cmt") { stream.readNext(); Pt->setTag("_comment_", stream.text().toString()); stream.readNext(); } else if (stream.name() == "desc") { stream.readNext(); Pt->setTag("_description_", stream.text().toString()); stream.readNext(); } else if (stream.name() == "cmt") { stream.readNext(); Pt->setTag("_comment_", stream.text().toString()); stream.readNext(); } else if (stream.name() == "extensions") // for OpenStreetBugs { QString str = stream.readElementText(QXmlStreamReader::IncludeChildElements); QDomDocument doc; doc.setContent(str); QDomNodeList li = doc.elementsByTagName("id"); if (li.size()) { QString id = li.at(0).toElement().text(); Pt->setId(IFeature::FId(IFeature::Point | IFeature::Special, id.toLongLong())); Pt->setTag("_special_", "yes"); // Assumed to be OpenstreetBugs as they don't use their own namesoace Pt->setSpecial(true); } } stream.readNext(); } Pt->setTime(time); return Pt; }