Marble

KmlTrackWriter.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2011 Guillaume Martres <[email protected]>
4 //
5 
6 #include "KmlTrackWriter.h"
7 
8 #include "GeoDataCoordinates.h"
9 #include "GeoDataTrack.h"
10 #include "GeoDataTypes.h"
11 #include "GeoWriter.h"
12 #include "KmlElementDictionary.h"
13 #include "KmlObjectTagWriter.h"
14 
15 #include <QDateTime>
16 
17 using namespace Marble;
18 
19 static GeoTagWriterRegistrar s_writerPoint( GeoTagWriter::QualifiedName(GeoDataTypes::GeoDataTrackType,
20  kml::kmlTag_nameSpaceOgc22),
21  new KmlTrackWriter() );
22 
23 bool KmlTrackWriter::write( const GeoNode *node, GeoWriter &writer ) const
24 {
25  const GeoDataTrack *track = static_cast<const GeoDataTrack *>( node );
26 
27  writer.writeStartElement( "gx:Track" );
28  KmlObjectTagWriter::writeIdentifiers( writer, track );
29 
30  int points = track->size();
31  for ( int i = 0; i < points; i++ ) {
32  writer.writeElement( "when", track->whenList().at( i ).toString( Qt::ISODate ) );
33 
34  qreal lon, lat, alt;
35  track->coordinatesList().at( i ).geoCoordinates( lon, lat, alt, GeoDataCoordinates::Degree );
36  const QString coord = QString::number(lon, 'f', 10) + QLatin1Char(' ') +
37  QString::number(lat, 'f', 10) + QLatin1Char(' ') +
38  QString::number(alt, 'f', 10);
39 
40  writer.writeElement( "gx:coord", coord );
41  }
42  writer.writeEndElement();
43 
44  return true;
45 }
void writeElement(const QString &namespaceUri, const QString &key, const QString &value)
Convenience method to write <key>value</key> with key prefixed format namespaceUri.
Definition: GeoWriter.cpp:78
QString number(int n, int base)
void writeEndElement()
QVector< GeoDataCoordinates > coordinatesList() const
Returns the coordinates of all the points in the map, sorted by their time value.
QVector< QDateTime > whenList() const
Returns the time value of all the points in the map, in chronological order.
A shared base class for all classes that are mapped to a specific tag (ie.
Definition: GeoDocument.h:34
int size() const
Returns the number of points in the track.
const T & at(int i) const const
Binds a QML item to a specific geodetic location in screen coordinates.
A geometry for tracking objects made of (time, coordinates) pairs.
Definition: GeoDataTrack.h:50
Standard Marble way of writing XML This class is intended to be a standardised way of writing XML for...
Definition: GeoWriter.h:25
void writeStartElement(const QString &qualifiedName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:27 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.