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
11const char* OSM::typeName(Type type)
12{
13 switch(type) {
14 case OSM::Type::Null: Q_UNREACHABLE();
15 case OSM::Type::Node: return "node";
16 case OSM::Type::Way: return "way";
17 case OSM::Type::Relation: return "relation";
18 }
19 return nullptr;
20}
21
22DataSet::DataSet() = default;
23DataSet::DataSet(DataSet &&) noexcept = default;
24DataSet::~DataSet() = default;
25
26DataSet& DataSet::operator=(DataSet &&) noexcept = default;
27
28TagKey DataSet::makeTagKey(const char *keyName, OSM::StringMemory keyMemOpt)
29{
30 return m_tagKeyRegistry.makeKey(keyName, keyMemOpt);
31}
32
33Role DataSet::makeRole(const char *roleName, OSM::StringMemory memOpt)
34{
35 return m_roleRegistry.makeKey(roleName, memOpt);
36}
37
38TagKey DataSet::tagKey(const char *keyName) const
39{
40 return m_tagKeyRegistry.key(keyName);
41}
42
43Role DataSet::role(const char *roleName) const
44{
45 return m_roleRegistry.key(roleName);
46}
47
48const Node* DataSet::node(Id id) const
49{
50 if (const auto it = std::lower_bound(nodes.begin(), nodes.end(), id); it != nodes.end() && (*it).id == id) {
51 return &(*it);
52 }
53 if (transientNodes) {
54 if (const auto it = std::lower_bound(transientNodes->begin(), transientNodes->end(), id); it != transientNodes->end() && (*it).id == id) {
55 return &(*it);
56 }
57 }
58 return nullptr;
59}
60
61const Way* DataSet::way(Id id) const
62{
63 const auto it = std::lower_bound(ways.begin(), ways.end(), id);
64 if (it != ways.end() && (*it).id == id) {
65 return &(*it);
66 }
67 return nullptr;
68}
69
71{
72 const auto it = std::lower_bound(ways.begin(), ways.end(), id);
73 if (it != ways.end() && (*it).id == id) {
74 return &(*it);
75 }
76 return nullptr;
77}
78
80{
81 const auto it = std::lower_bound(relations.begin(), relations.end(), id);
82 if (it != relations.end() && (*it).id == id) {
83 return &(*it);
84 }
85 return nullptr;
86}
87
88void DataSet::addNode(Node &&node)
89{
90 const auto it = std::lower_bound(nodes.begin(), nodes.end(), node);
91 if (it != nodes.end() && (*it).id == node.id) {
92 // do we need to merge something here?
93 return;
94 }
95 nodes.insert(it, std::move(node));
96}
97
98void DataSet::addWay(Way &&way)
99{
100 const auto it = std::lower_bound(ways.begin(), ways.end(), way);
101 if (it != ways.end() && (*it).id == way.id) {
102 // already there?
103 return;
104 }
105 ways.insert(it, std::move(way));
106}
107
108void DataSet::addRelation(Relation &&rel)
109{
110 const auto it = std::lower_bound(relations.begin(), relations.end(), rel);
111 if (it != relations.end() && (*it).id == rel.id) {
112 // do we need to merge something here?
113 return;
114 }
115 relations.insert(it, std::move(rel));
116}
117
119{
120 static OSM::Id nextId = 0;
121 return --nextId;
122}
123
124// resolve ids for elements split in Marble vector tiles
125template <typename T>
126static QString actualIdString(const T &elem)
127{
128 const auto mxoid = OSM::tagValue(elem, "mx:oid");
129 return mxoid.isEmpty() ? QString::number(elem.id) : QString::fromUtf8(mxoid);
130}
131
132QString OSM::Node::url() const
133{
134 return QStringLiteral("https://openstreetmap.org/node/") + actualIdString(*this);
135}
136
137bool OSM::Way::isClosed() const
138{
139 return nodes.size() >= 2 && nodes.front() == nodes.back();
140}
141
142QString OSM::Way::url() const
143{
144 return QStringLiteral("https://openstreetmap.org/way/") + actualIdString(*this);
145}
146
147QString OSM::Relation::url() const
148{
149 return QStringLiteral("https://openstreetmap.org/relation/") + actualIdString(*this);
150}
151
153{
154 QDebugStateSaver saver(debug);
155 debug.nospace() << '(' << coord.latF() << ',' << coord.lonF() << ')';
156 return debug;
157}
158
160{
161 QDebugStateSaver saver(debug);
162 debug.nospace() << '[' << bbox.min.latF() << ',' << bbox.min.lonF() << '|' << bbox.max.latF() << ',' << bbox.max.lonF() << ']';
163 return debug;
164}
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:346
const Relation * relation(Id id) const
Find a relation by its id.
Definition datatypes.cpp:79
TagKey tagKey(const char *keyName) const
Look up a tag key for the given tag name, if it exists.
Definition datatypes.cpp:38
Role role(const char *roleName) const
Looks up a role name key.
Definition datatypes.cpp:43
const Way * way(Id id) const
Find a way by its id.
Definition datatypes.cpp:61
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:48
const std::vector< Node > * transientNodes
Dynamically created nodes for overlays with new geometry.
Definition datatypes.h:408
Role makeRole(const char *roleName, StringMemory memOpt=StringMemory::Transient)
Creates a role name key.
Definition datatypes.cpp:33
An OSM node.
Definition datatypes.h:204
An OSM relation.
Definition datatypes.h:316
A relation role name key.
Definition datatypes.h:278
A key of an OSM tag.
Definition datatypes.h:179
An OSM way.
Definition datatypes.h:232
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
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:420
KOSM_EXPORT const char * typeName(Type type)
Element type name.
Definition datatypes.cpp:11
Type
Element type.
Definition datatypes.h:264
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 Mon Nov 4 2024 16:36:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.