Ref T668, KML utils

This commit is contained in:
Klaus Basan
2019-05-16 14:30:41 +02:00
parent 0b4427e39d
commit 01ba89ce0e
2 changed files with 152 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
/* Copyright (C) 2019
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
* or distributed except according to the terms contained in the LICENSE file.
*/
#include "kmlutils.h"
#include <QStringBuilder>
using namespace BlackMisc;
using namespace BlackMisc::Geo;
using namespace BlackMisc::PhysicalQuantities;
namespace BlackMisc
{
namespace Simulation
{
const CLogCategoryList &CKmlUtils::getLogCategories()
{
static const CLogCategoryList cats { CLogCategory::interpolator() };
return cats;
}
QString CKmlUtils::wrapAsKmlDocument(const QString &content)
{
return u"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
u"<kml xmlns=\"http://www.opengis.net/kml/2.2\" "
u"xmlns:gx=\"http://www.google.com/kml/ext/2.2\">\n"
u"<Document>\n"
% content %
u"</Document>\n"
u"</kml>\n";
}
QString CKmlUtils::wrapAsKmlCoordinates(const QString &content)
{
return u"<coordinates>" % content % u"</coordinates>";
}
QString CKmlUtils::asRawCoordinates(const ICoordinateGeodetic &coordinate, bool withAltitude)
{
return
coordinate.longitude().valueRoundedAsString(CAngleUnit::deg(), 8) % u"," %
coordinate.latitude().valueRoundedAsString(CAngleUnit::deg(), 8) %
(withAltitude ? (u"," % coordinate.geodeticHeight().valueRoundedAsString(CLengthUnit::m())) : QString());
}
QString CKmlUtils::asPoint(const ICoordinateGeodetic &coordinate, const KMLSettings &settings)
{
return
u"<Point><coordinates>" %
CKmlUtils::asRawCoordinates(coordinate, settings.withAltitude) %
u"</coordinates>" %
(settings.extrude ? u"<extrude>1</extrude>" : u"") %
(settings.withAltitude && !settings.altitudeMode.isEmpty() ? u"<altitudeMode>" % settings.altitudeMode % "</altitudeMode>" : QString()) %
u"</Point>";
}
QString CKmlUtils::asPlacemark(
const QString &name, const QString &description,
const ICoordinateGeodetic &coordinate, const KMLSettings &settings)
{
return
u"<Placemark>" %
asPoint(coordinate, settings) %
(name.isEmpty() ? QString() : u"<name>" % name.toHtmlEscaped() % u"</name>") %
(description.isEmpty() ? QString() : u"<description>" % description.toHtmlEscaped() % u"</description>") %
u"</Placemark>";
}
QString CKmlUtils::asLineString(const QString &coordinatesRaw, const CKmlUtils::KMLSettings &settings)
{
return
u"<LineString>" %
(settings.withAltitude && !settings.altitudeMode.isEmpty() ? u"<altitudeMode>" % settings.altitudeMode % "</altitudeMode>" : QString()) %
(settings.tessellate ? u"<tessellate>1</tessellate>" : u"") %
(settings.extrude ? u"<extrude>1</extrude>" : u"") %
CKmlUtils::wrapAsKmlCoordinates(coordinatesRaw) %
u"</LineString>";
}
} // ns
} // ns

View File

@@ -0,0 +1,68 @@
/* Copyright (C) 2019
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
* or distributed except according to the terms contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_SIMULATION_KMLUTILS_H
#define BLACKMISC_SIMULATION_KMLUTILS_H
#include "blackmisc/geo/coordinategeodetic.h"
#include "blackmisc/logcategorylist.h"
#include "blackmisc/blackmiscexport.h"
namespace BlackMisc
{
namespace Simulation
{
/*!
* KML utils
*/
class BLACKMISC_EXPORT CKmlUtils
{
public:
//! Log categories
static const BlackMisc::CLogCategoryList &getLogCategories();
//! KML settings
struct KMLSettings
{
//! Ctor
KMLSettings(bool withAltitude, bool extrude) :
withAltitude(withAltitude), extrude(extrude)
{ }
//! Setting members @{
bool withAltitude = true;
bool extrude = false;
bool tessellate = true;
QString altitudeMode = "absolute";
//! @}
};
//! Wrap as KML document
static QString wrapAsKmlDocument(const QString &content);
//! Wrap as KML coordinates
static QString wrapAsKmlCoordinates(const QString &content);
//! As raw coordinates
static QString asRawCoordinates(const Geo::ICoordinateGeodetic &coordinate, bool withAltitude);
//! As KML point
static QString asPoint(const Geo::ICoordinateGeodetic &coordinate, const KMLSettings &settings);
//! As KML placemark
static QString asPlacemark(const QString &name, const QString &description, const Geo::ICoordinateGeodetic &coordinate, const KMLSettings &settings);
//! As KML line
static QString asLineString(const QString &coordinatesRaw, const KMLSettings &settings);
};
} // ns
} // ns
#endif // guard