KOSMIndoorMap

datatypes.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "datatypes.h"
8
9using namespace OSM;
10
11DataSet::DataSet() = default;
12DataSet::DataSet(DataSet &&) noexcept = default;
13DataSet::~DataSet() = default;
14
15DataSet& DataSet::operator=(DataSet &&) noexcept = default;
16
17TagKey DataSet::makeTagKey(const char *keyName, OSM::StringMemory keyMemOpt)
18{
19 return m_tagKeyRegistry.makeKey(keyName, keyMemOpt);
20}
21
22Role DataSet::makeRole(const char *roleName, OSM::StringMemory memOpt)
23{
24 return m_roleRegistry.makeKey(roleName, memOpt);
25}
26
27TagKey DataSet::tagKey(const char *keyName) const
28{
29 return m_tagKeyRegistry.key(keyName);
30}
31
32Role DataSet::role(const char *roleName) const
33{
34 return m_roleRegistry.key(roleName);
35}
36
37const 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
46const 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
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
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
73void 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
83void 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
93void 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
110template <typename T>
111static 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
117QString OSM::Node::url() const
118{
119 return QStringLiteral("https://openstreetmap.org/node/") + actualIdString(*this);
120}
121
122bool OSM::Way::isClosed() const
123{
124 return nodes.size() >= 2 && nodes.front() == nodes.back();
125}
126
127QString OSM::Way::url() const
128{
129 return QStringLiteral("https://openstreetmap.org/way/") + actualIdString(*this);
130}
131
132QString 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}
Bounding box, ie.
Definition datatypes.h:95
Coordinate, stored as 1e7 * degree to avoid floating point precision issues, and offset to unsigned v...
Definition datatypes.h:37
A set of nodes, ways and relations.
Definition datatypes.h:340
const Relation * relation(Id id) const
Find a relation by its id.
Definition datatypes.cpp:64
TagKey tagKey(const char *keyName) const
Look up a tag key for the given tag name, if it exists.
Definition datatypes.cpp:27
Role role(const char *roleName) const
Looks up a role name key.
Definition datatypes.cpp:32
const Way * way(Id id) const
Find a way by its id.
Definition datatypes.cpp:46
Id nextInternalId() const
Create a unique id for internal use (ie.
const Node * node(Id id) const
Find a node by its id.
Definition datatypes.cpp:37
Role makeRole(const char *roleName, StringMemory memOpt=StringMemory::Transient)
Creates a role name key.
Definition datatypes.cpp:22
An OSM node.
Definition datatypes.h:204
An OSM relation.
Definition datatypes.h:311
A relation role name key.
Definition datatypes.h:273
A key of an OSM tag.
Definition datatypes.h:179
An OSM way.
Definition datatypes.h:231
Low-level types and functions to work with raw OSM data as efficiently as possible.
int64_t Id
OSM element identifier.
Definition datatypes.h:30
QByteArray tagValue(const Elem &elem, TagKey key)
Returns the tag value for key of elem.
Definition datatypes.h:410
QDebug operator<<(QDebug dbg, const PerceptualColor::LchaDouble &value)
QDebug & nospace()
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.