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 "GeoDataLinearRing.h"
10#include "GeoDataTypes.h"
11#include "GeoDataCoordinates.h"
12#include "GeoWriter.h"
13#include "KmlElementDictionary.h"
14#include "KmlObjectTagWriter.h"
15
16namespace Marble
17{
18
19static GeoTagWriterRegistrar s_writerLookAt(
20 GeoTagWriter::QualifiedName( GeoDataTypes::GeoDataLinearRingType,
21 kml::kmlTag_nameSpaceOgc22 ),
22 new KmlLinearRingTagWriter );
23
24bool KmlLinearRingTagWriter::write( const GeoNode *node, GeoWriter& writer ) const
25{
26 const GeoDataLinearRing *ring = static_cast<const GeoDataLinearRing*>( node );
27
28 if ( ring->size() > 1 )
29 {
30 writer.writeStartElement( kml::kmlTag_LinearRing );
31 KmlObjectTagWriter::writeIdentifiers( writer, ring );
32 writer.writeOptionalElement( kml::kmlTag_extrude, QString::number( ring->extrude() ), "0" );
33 writer.writeOptionalElement( kml::kmlTag_tessellate, QString::number( ring->tessellate() ), "0" );
34 writer.writeStartElement( "coordinates" );
35
36 int size = ring->size() >= 3 && ring->first() != ring->last() ? ring->size() + 1 : ring->size();
37
38 for ( int i = 0; i < size; ++i )
39 {
40 GeoDataCoordinates coordinates = ring->at( i % ring->size() );
41 if ( i > 0 )
42 {
43 writer.writeCharacters( " " );
44 }
45
46 qreal lon = coordinates.longitude( GeoDataCoordinates::Degree );
47 writer.writeCharacters( QString::number( lon, 'f', 10 ) );
48 writer.writeCharacters( "," );
49 qreal lat = coordinates.latitude( GeoDataCoordinates::Degree );
50 writer.writeCharacters( QString::number( lat, 'f', 10 ) );
51 }
52
53 writer.writeEndElement();
54 writer.writeEndElement();
55
56 return true;
57 }
58
59 return false;
60}
61
62}
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 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 Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.