KOSMIndoorMap

datatypes.cpp
1 /*
2  SPDX-FileCopyrightText: 2020 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "datatypes.h"
8 
9 using namespace OSM;
10 
11 DataSet::DataSet() = default;
12 DataSet::DataSet(DataSet &&) = default;
13 DataSet::~DataSet() = default;
14 
15 DataSet& DataSet::operator=(DataSet &&) = default;
16 
17 TagKey DataSet::makeTagKey(const char *keyName, OSM::StringMemory keyMemOpt)
18 {
19  return m_tagKeyRegistry.makeKey(keyName, keyMemOpt);
20 }
21 
22 Role DataSet::makeRole(const char *roleName, OSM::StringMemory memOpt)
23 {
24  return m_roleRegistry.makeKey(roleName, memOpt);
25 }
26 
27 TagKey DataSet::tagKey(const char *keyName) const
28 {
29  return m_tagKeyRegistry.key(keyName);
30 }
31 
32 Role DataSet::role(const char *roleName) const
33 {
34  return m_roleRegistry.key(roleName);
35 }
36 
37 const Node* DataSet::node(Id id) const
38 {
39  const auto it = std::lower_bound(nodes.begin(), nodes.end(), id);
40  if (it != nodes.end() && (*it).id == id) {
41  return &(*it);
42  }
43  return nullptr;
44 }
45 
46 const Way* DataSet::way(Id id) const
47 {
48  const auto it = std::lower_bound(ways.begin(), ways.end(), id);
49  if (it != ways.end() && (*it).id == id) {
50  return &(*it);
51  }
52  return nullptr;
53 }
54 
55 Way* DataSet::way(Id id)
56 {
57  const auto it = std::lower_bound(ways.begin(), ways.end(), id);
58  if (it != ways.end() && (*it).id == id) {
59  return &(*it);
60  }
61  return nullptr;
62 }
63 
64 const Relation* DataSet::relation(Id id) const
65 {
66  const auto it = std::lower_bound(relations.begin(), relations.end(), id);
67  if (it != relations.end() && (*it).id == id) {
68  return &(*it);
69  }
70  return nullptr;
71 }
72 
73 void DataSet::addNode(Node &&node)
74 {
75  const auto it = std::lower_bound(nodes.begin(), nodes.end(), node);
76  if (it != nodes.end() && (*it).id == node.id) {
77  // do we need to merge something here?
78  return;
79  }
80  nodes.insert(it, std::move(node));
81 }
82 
83 void DataSet::addWay(Way &&way)
84 {
85  const auto it = std::lower_bound(ways.begin(), ways.end(), way);
86  if (it != ways.end() && (*it).id == way.id) {
87  // already there?
88  return;
89  }
90  ways.insert(it, std::move(way));
91 }
92 
93 void DataSet::addRelation(Relation &&rel)
94 {
95  const auto it = std::lower_bound(relations.begin(), relations.end(), rel);
96  if (it != relations.end() && (*it).id == rel.id) {
97  // do we need to merge something here?
98  return;
99  }
100  relations.insert(it, std::move(rel));
101 }
102 
104 {
105  static OSM::Id nextId = 0;
106  return --nextId;
107 }
108 
109 // resolve ids for elements split in Marble vector tiles
110 template <typename T>
111 static QString actualIdString(const T &elem)
112 {
113  const auto mxoid = OSM::tagValue(elem, "mx:oid");
114  return mxoid.isEmpty() ? QString::number(elem.id) : QString::fromUtf8(mxoid);
115 }
116 
117 QString OSM::Node::url() const
118 {
119  return QStringLiteral("https://openstreetmap.org/node/") + actualIdString(*this);
120 }
121 
122 bool OSM::Way::isClosed() const
123 {
124  return nodes.size() >= 2 && nodes.front() == nodes.back();
125 }
126 
127 QString OSM::Way::url() const
128 {
129  return QStringLiteral("https://openstreetmap.org/way/") + actualIdString(*this);
130 }
131 
132 QString OSM::Relation::url() const
133 {
134  return QStringLiteral("https://openstreetmap.org/relation/") + actualIdString(*this);
135 }
136 
138 {
139  QDebugStateSaver saver(debug);
140  debug.nospace() << '(' << coord.latF() << ',' << coord.lonF() << ')';
141  return debug;
142 }
143 
145 {
146  QDebugStateSaver saver(debug);
147  debug.nospace() << '[' << bbox.min.latF() << ',' << bbox.min.lonF() << '|' << bbox.max.latF() << ',' << bbox.max.lonF() << ']';
148  return debug;
149 }
QDebug & nospace()
Coordinate, stored as 1e7 * degree to avoid floating point precision issues, and offset to unsigned v...
Definition: datatypes.h:37
Id nextInternalId() const
Create a unique id for internal use (ie.
Definition: datatypes.cpp:103
Role role(const char *roleName) const
Looks up a role name key.
Definition: datatypes.cpp:32
QString number(int n, int base)
QString fromUtf8(const char *str, int size)
A key of an OSM tag.
Definition: datatypes.h:179
Role makeRole(const char *roleName, StringMemory memOpt=StringMemory::Transient)
Creates a role name key.
Definition: datatypes.cpp:22
QByteArray tagValue(const Elem &elem, TagKey key)
Returns the tag value for key of elem.
Definition: datatypes.h:353
An OSM node.
Definition: datatypes.h:194
TagKey tagKey(const char *keyName) const
Look up a tag key for the given tag name, if it exists.
Definition: datatypes.cpp:27
int64_t Id
OSM element identifier.
Definition: datatypes.h:27
An OSM way.
Definition: datatypes.h:206
TagKey makeTagKey(const char *keyName, StringMemory keyMemOpt=StringMemory::Transient)
Create a tag key for the given tag name.
Definition: datatypes.cpp:17
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
A relation role name key.
Definition: datatypes.h:231
An OSM relation.
Definition: datatypes.h:270
A set of nodes, ways and relations.
Definition: datatypes.h:283
const Way * way(Id id) const
Find a way by its id.
Definition: datatypes.cpp:46
Bounding box, ie.
Definition: datatypes.h:95
Low-level types and functions to work with raw OSM data as efficiently as possible.
const Relation * relation(Id id) const
Find a relation by its id.
Definition: datatypes.cpp:64
const Node * node(Id id) const
Find a node by its id.
Definition: datatypes.cpp:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Sep 27 2021 23:05:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.