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

osm_element.cpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8f7470c897ee79d690f0462ede7a35289483978e (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "generator/osm_element.hpp"

#include "base/string_utils.hpp"
#include "coding/parse_xml.hpp"

#include <algorithm>
#include <cstdio>
#include <sstream>

std::string DebugPrint(OsmElement::EntityType e)
{
  switch (e)
  {
    case OsmElement::EntityType::Unknown:
      return "unknown";
    case OsmElement::EntityType::Way:
      return "way";
    case OsmElement::EntityType::Tag:
      return "tag";
    case OsmElement::EntityType::Relation:
      return "relation";
    case OsmElement::EntityType::Osm:
      return "osm";
    case OsmElement::EntityType::Node:
      return "node";
    case OsmElement::EntityType::Nd:
      return "nd";
    case OsmElement::EntityType::Member:
      return "member";
  }
  CHECK_SWITCH();
}


void OsmElement::AddTag(std::string const & k, std::string const & v)
{
  // Seems like source osm data has empty values. They are useless for us.
  if (k.empty() || v.empty())
    return;

#define SKIP_KEY(key) if (strncmp(k.data(), key, sizeof(key)-1) == 0) return;
  // OSM technical info tags
  SKIP_KEY("created_by");
  SKIP_KEY("source");
  SKIP_KEY("odbl");
  SKIP_KEY("note");
  SKIP_KEY("fixme");
  SKIP_KEY("iemv");

  // Skip tags for speedup, now we don't use it
  SKIP_KEY("not:");
  SKIP_KEY("artist_name");
  SKIP_KEY("whitewater"); // https://wiki.openstreetmap.org/wiki/Whitewater_sports


  // In future we can use this tags for improve our search
  SKIP_KEY("old_name");
  SKIP_KEY("alt_name");
  SKIP_KEY("nat_name");
  SKIP_KEY("reg_name");
  SKIP_KEY("loc_name");
  SKIP_KEY("lock_name");
  SKIP_KEY("local_name");
  SKIP_KEY("short_name");
  SKIP_KEY("official_name");
#undef SKIP_KEY

  std::string value = v;
  strings::Trim(value);
  m_tags.emplace_back(k, value);
}

bool OsmElement::HasTagValue(std::string const & k, std::string const & v) const
{
  return std::any_of(m_tags.begin(), m_tags.end(), [&](auto const & t) {
    return t.key == k && t.value == v;
  });
}

std::string OsmElement::ToString(std::string const & shift) const
{
  std::stringstream ss;
  ss << (shift.empty() ? "\n" : shift);
  switch (type)
  {
    case EntityType::Node:
      ss << "Node: " << id << " (" << std::fixed << std::setw(7) << lat << ", " << lon << ")"
         << " tags: " << m_tags.size();
      break;
    case EntityType::Nd:
      ss << "Nd ref: " << ref;
      break;
    case EntityType::Way:
      ss << "Way: " << id << " nds: " << m_nds.size() << " tags: " << m_tags.size();
      if (!m_nds.empty())
      {
        std::string shift2 = shift;
        shift2 += shift2.empty() ? "\n  " : "  ";
        for (auto const & e : m_nds)
          ss << shift2 << e;
      }
      break;
    case EntityType::Relation:
      ss << "Relation: " << id << " members: " << m_members.size() << " tags: " << m_tags.size();
      if (!m_members.empty())
      {
        std::string shift2 = shift;
        shift2 += shift2.empty() ? "\n  " : "  ";
        for (auto const & e : m_members)
          ss << shift2 << e.ref << " " << DebugPrint(e.type) << " " << e.role;
      }
      break;
    case EntityType::Tag:
      ss << "Tag: " << k << " = " << v;
      break;
    case EntityType::Member:
      ss << "Member: " << ref << " type: " << DebugPrint(memberType) << " role: " << role;
      break;
    default:
      ss << "Unknown element";
  }
  if (!m_tags.empty())
  {
    std::string shift2 = shift;
    shift2 += shift2.empty() ? "\n  " : "  ";
    for (auto const & e : m_tags)
      ss << shift2 << e.key << " = " << e.value;
  }
  return ss.str();
}

std::string OsmElement::GetTag(std::string const & key) const
{
  auto const it = std::find_if(begin(m_tags), end(m_tags), [&key](Tag const & tag)
  {
    return tag.key == key;
  });

  if (it == end(m_tags))
    return {};

  return it->value;
}

std::string DebugPrint(OsmElement const & e)
{
  return e.ToString();
}

std::string DebugPrint(OsmElement::Tag const & tag)
{
  std::stringstream ss;
  ss << tag.key << '=' << tag.value;
  return ss.str();
}