Welcome to mirror list, hosted at ThFree Co, Russian Federation.

elevation_info.cpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f2b23db98a43e1029bf122950b1ddef751404312 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "map/elevation_info.hpp"

#include "base/string_utils.hpp"

namespace
{
static uint8_t constexpr kMaxDifficulty = ElevationInfo::Difficulty::Hard;

std::string const kAscentKey = "ascent";
std::string const kDescentKey = "descent";
std::string const kLowestPointKey = "lowest_point";
std::string const kHighestPointKey = "highest_point";
std::string const kDifficultyKey = "difficulty";
std::string const kDurationKey = "duration";

template <typename T>
void FillProperty(kml::Properties const & properties, std::string const & key, T & value)
{
  auto const it = properties.find(key);
  if (it != properties.cend() && !strings::to_any(it->second, value))
    LOG(LERROR, ("Conversion is not possible for key", key, "string representation is", it->second));
}
}  // namespace

ElevationInfo::ElevationInfo(Track const & track)
  : m_id(track.GetId())
  , m_name(track.GetName())
{
  auto const & points = track.GetPointsWithAltitudes();

  if (points.empty())
    return;

  m_points.reserve(points.size());
  m_points.emplace_back(0, points[0].GetAltitude());
  double distance = 0.0;
  for (size_t i = 1; i < points.size(); ++i)
  {
    distance += mercator::DistanceOnEarth(points[i - 1].GetPoint(), points[i].GetPoint());
    m_points.emplace_back(distance, points[i].GetAltitude());
  }

  auto const & properties = track.GetData().m_properties;

  FillProperty(properties, kAscentKey, m_ascent);
  FillProperty(properties, kDescentKey, m_descent);
  FillProperty(properties, kLowestPointKey, m_minAltitude);
  FillProperty(properties, kHighestPointKey, m_maxAltitude);

  uint8_t difficulty;
  FillProperty(properties, kDifficultyKey, difficulty);

  if (difficulty > kMaxDifficulty)
  {
    LOG(LWARNING, ("Invalid difficulty value", m_difficulty, "in track", track.GetName()));
    m_difficulty = Difficulty ::Unknown;
  }
  else
  {
    m_difficulty = static_cast<Difficulty>(difficulty);
  }

  FillProperty(properties, kDurationKey, m_duration);
}