From 58b8af888afd9f904716dd3057ca80bb6f3aef00 Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Thu, 12 Mar 2020 17:14:28 +0300 Subject: [PATCH] [bookmarks][pykmlib] Support invalid altitude in tracks. --- kml/pykmlib/bindings.cpp | 1 + kml/pykmlib/bindings_test.py | 2 +- kml/serdes.cpp | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kml/pykmlib/bindings.cpp b/kml/pykmlib/bindings.cpp index 8678ebdfc6..602cefb08e 100644 --- a/kml/pykmlib/bindings.cpp +++ b/kml/pykmlib/bindings.cpp @@ -679,6 +679,7 @@ std::string IndexToClassificatorType(uint32_t index) BOOST_PYTHON_MODULE(pykmlib) { scope().attr("__version__") = PYBINDINGS_VERSION; + scope().attr("invalid_altitude") = geometry::kInvalidAltitude; register_exception_translator(&TranslateRuntimeError); TimestampConverter(); LatLonConverter(); diff --git a/kml/pykmlib/bindings_test.py b/kml/pykmlib/bindings_test.py index c1bd1d67a5..8f4c2aa568 100644 --- a/kml/pykmlib/bindings_test.py +++ b/kml/pykmlib/bindings_test.py @@ -79,7 +79,7 @@ class PyKmlibAdsTest(unittest.TestCase): pt2.set_altitude(110) pt3 = pykmlib.PointWithAltitude() pt3.set_point(pykmlib.LatLon(45.1964, 56.9832)) - pt3.set_altitude(120) + pt3.set_altitude(pykmlib.invalid_altitude) track.points_with_altitudes.set_list([pt1, pt2, pt3]) track.visible = True track.nearest_toponyms.set_list(['12345', '54321', '98765']) diff --git a/kml/serdes.cpp b/kml/serdes.cpp index e1025db868..8fbab5efa6 100644 --- a/kml/serdes.cpp +++ b/kml/serdes.cpp @@ -78,7 +78,9 @@ std::string PointToString(m2::PointD const & org) std::string PointToString(geometry::PointWithAltitude const & pt) { - return PointToString(pt.GetPoint()) + "," + strings::to_string(pt.GetAltitude()); + if (pt.GetAltitude() != geometry::kInvalidAltitude) + return PointToString(pt.GetPoint()) + "," + strings::to_string(pt.GetAltitude()); + return PointToString(pt.GetPoint()); } std::string GetLocalizableString(LocalizableString const & s, int8_t lang) @@ -549,7 +551,7 @@ bool ParsePoint(std::string const & s, char const * delim, m2::PointD & pt) bool ParsePointWithAltitude(std::string const & s, char const * delim, geometry::PointWithAltitude & point) { - geometry::Altitude altitude = geometry::kDefaultAltitudeMeters; + geometry::Altitude altitude = geometry::kInvalidAltitude; m2::PointD pt; auto result = ParsePoint(s, delim, pt, altitude); point.SetPoint(std::move(pt));