Marble

KmlLinearRingTagWriter.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
4// SPDX-FileCopyrightText: 2014 Marek Hakala <hakala.marek@gmail.com>
5//
6
7#include "KmlLinearRingTagWriter.h"
8
9#include "GeoDataCoordinates.h"
10#include "GeoDataLinearRing.h"
11#include "GeoDataTypes.h"
12#include "GeoWriter.h"
13#include "KmlElementDictionary.h"
14#include "KmlObjectTagWriter.h"
15
16namespace Marble
17{
18
19static GeoTagWriterRegistrar s_writerLookAt(GeoTagWriter::QualifiedName(QString::fromLatin1(GeoDataTypes::GeoDataLinearRingType),
20 QString::fromLatin1(kml::kmlTag_nameSpaceOgc22)),
21 new KmlLinearRingTagWriter);
22
23bool KmlLinearRingTagWriter::write(const GeoNode *node, GeoWriter &writer) const
24{
25 const auto ring = static_cast<const GeoDataLinearRing *>(node);
26
27 if (ring->size() > 1) {
28 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_LinearRing));
29 KmlObjectTagWriter::writeIdentifiers(writer, ring);
30 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_extrude), QString::number(ring->extrude()), QStringLiteral("0"));
31 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_tessellate), QString::number(ring->tessellate()), QStringLiteral("0"));
32 writer.writeStartElement("coordinates");
33
34 int size = ring->size() >= 3 && ring->first() != ring->last() ? ring->size() + 1 : ring->size();
35
36 for (int i = 0; i < size; ++i) {
37 GeoDataCoordinates coordinates = ring->at(i % ring->size());
38 if (i > 0) {
39 writer.writeCharacters(" ");
40 }
41
42 qreal lon = coordinates.longitude(GeoDataCoordinates::Degree);
43 writer.writeCharacters(QString::number(lon, 'f', 10));
44 writer.writeCharacters(",");
45 qreal lat = coordinates.latitude(GeoDataCoordinates::Degree);
46 writer.writeCharacters(QString::number(lat, 'f', 10));
47 }
48
49 writer.writeEndElement();
50 writer.writeEndElement();
51
52 return true;
53 }
54
55 return false;
56}
57
58}
QPair< QString, QString > QualifiedName
Object Name and Namespace Pair This type is intended to be used in a similar way to.
Binds a QML item to a specific geodetic location in screen coordinates.
QString fromLatin1(QByteArrayView str)
QString fromUtf8(QByteArrayView str)
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:02:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.