From 01ba89ce0eee4b04058bbc54c2e279094e84ee39 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 16 May 2019 14:30:41 +0200 Subject: [PATCH] Ref T668, KML utils --- src/blackmisc/simulation/kmlutils.cpp | 84 +++++++++++++++++++++++++++ src/blackmisc/simulation/kmlutils.h | 68 ++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 src/blackmisc/simulation/kmlutils.cpp create mode 100644 src/blackmisc/simulation/kmlutils.h diff --git a/src/blackmisc/simulation/kmlutils.cpp b/src/blackmisc/simulation/kmlutils.cpp new file mode 100644 index 000000000..c1a4c5d8e --- /dev/null +++ b/src/blackmisc/simulation/kmlutils.cpp @@ -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 + +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"\n" + u"\n" + u"\n" + % content % + u"\n" + u"\n"; + } + + QString CKmlUtils::wrapAsKmlCoordinates(const QString &content) + { + return u"" % content % u""; + } + + 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"" % + CKmlUtils::asRawCoordinates(coordinate, settings.withAltitude) % + u"" % + (settings.extrude ? u"1" : u"") % + (settings.withAltitude && !settings.altitudeMode.isEmpty() ? u"" % settings.altitudeMode % "" : QString()) % + u""; + } + + QString CKmlUtils::asPlacemark( + const QString &name, const QString &description, + const ICoordinateGeodetic &coordinate, const KMLSettings &settings) + { + return + u"" % + asPoint(coordinate, settings) % + (name.isEmpty() ? QString() : u"" % name.toHtmlEscaped() % u"") % + (description.isEmpty() ? QString() : u"" % description.toHtmlEscaped() % u"") % + u""; + } + + QString CKmlUtils::asLineString(const QString &coordinatesRaw, const CKmlUtils::KMLSettings &settings) + { + return + u"" % + (settings.withAltitude && !settings.altitudeMode.isEmpty() ? u"" % settings.altitudeMode % "" : QString()) % + (settings.tessellate ? u"1" : u"") % + (settings.extrude ? u"1" : u"") % + CKmlUtils::wrapAsKmlCoordinates(coordinatesRaw) % + u""; + } + } // ns +} // ns diff --git a/src/blackmisc/simulation/kmlutils.h b/src/blackmisc/simulation/kmlutils.h new file mode 100644 index 000000000..3fe9745ee --- /dev/null +++ b/src/blackmisc/simulation/kmlutils.h @@ -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