KOSMIndoorMap

osmaddress.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 "osmaddress.h"
8
9#include <KCountry>
10#include <KCountrySubdivision>
11
12using namespace KOSMIndoorMap;
13
14OSMAddress::OSMAddress() = default;
15OSMAddress::OSMAddress(OSM::Element elem)
16 : m_element(elem)
17{
18}
19
20OSMAddress::~OSMAddress() = default;
21
22QString OSMAddress::street() const
23{
24 return QString::fromUtf8(m_element.tagValue("addr:street", "contact:street", "addr:housename"));
25}
26
27QString OSMAddress::houseNumber() const
28{
29 return QString::fromUtf8(m_element.tagValue("addr:housenumber", "contact:housenumber"));
30}
31
32QString OSMAddress::postalCode() const
33{
34 return QString::fromUtf8(m_element.tagValue("addr:postcode", "contact:postcode"));
35}
36
37QString OSMAddress::city() const
38{
39 return QString::fromUtf8(m_element.tagValue("addr:city", "contact:city"));
40}
41
42QString OSMAddress::state() const
43{
44 const auto state = QString::fromUtf8(m_element.tagValue("addr:state"));
45 if (!state.isEmpty()) {
46 return state;
47 }
48
49 const auto s = KCountrySubdivision::fromLocation(m_element.center().latF(), m_element.center().lonF());
50 return s.isValid() ? s.code().mid(3) : QString();
51}
52
53QString OSMAddress::country() const
54{
55 const auto country = QString::fromUtf8(m_element.tagValue("addr:country", "contact:country"));
56 if (!country.isEmpty()) {
57 return country;
58 }
59
60 const auto c = KCountry::fromLocation(m_element.center().latF(), m_element.center().lonF());
61 return c.alpha2();
62}
63
64#include "moc_osmaddress.cpp"
static KCountrySubdivision fromLocation(float latitude, float longitude)
static KCountry fromLocation(float latitude, float longitude)
A reference to any of OSM::Node/OSM::Way/OSM::Relation.
Definition element.h:24
OSM-based multi-floor indoor maps for buildings.
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.