File indexing completed on 2025-01-05 03:59:14

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2011 Guillaume Martres <smarter@ubuntu.com>
0004 //
0005 
0006 #include "KmlTrackWriter.h"
0007 
0008 #include "GeoDataCoordinates.h"
0009 #include "GeoDataTrack.h"
0010 #include "GeoDataTypes.h"
0011 #include "GeoWriter.h"
0012 #include "KmlElementDictionary.h"
0013 #include "KmlObjectTagWriter.h"
0014 
0015 #include <QDateTime>
0016 
0017 using namespace Marble;
0018 
0019 static GeoTagWriterRegistrar s_writerPoint(GeoTagWriter::QualifiedName(
0020                                            QString::fromUtf8(GeoDataTypes::GeoDataTrackType),
0021                                            QString::fromUtf8(kml::kmlTag_nameSpaceOgc22)),
0022                                            new KmlTrackWriter() );
0023 
0024 bool KmlTrackWriter::write( const GeoNode *node, GeoWriter &writer ) const
0025 {
0026     const GeoDataTrack *track = static_cast<const GeoDataTrack *>( node );
0027 
0028     writer.writeStartElement( QString::fromUtf8("gx:Track") );
0029     KmlObjectTagWriter::writeIdentifiers( writer, track );
0030 
0031     int points = track->size();
0032     for ( int i = 0; i < points; i++ ) {
0033         writer.writeElement( QString::fromUtf8("when"), track->whenList().at( i ).toString( Qt::ISODate ) );
0034 
0035         qreal lon, lat, alt;
0036         track->coordinatesList().at( i ).geoCoordinates( lon, lat, alt, GeoDataCoordinates::Degree );
0037         const QString coord = QString::number(lon, 'f', 10) + QLatin1Char(' ') +
0038                               QString::number(lat, 'f', 10) + QLatin1Char(' ') +
0039                               QString::number(alt, 'f', 10);
0040 
0041         writer.writeElement( QString::fromUtf8("gx:coord"), coord );
0042     }
0043     writer.writeEndElement();
0044 
0045     return true;
0046 }