Added triangulation routine
This commit is contained in:
parent
045f3a8439
commit
6ea55594ab
25 changed files with 891530 additions and 171 deletions
|
@ -1,7 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(osmp)
|
||||
|
||||
find_package(tinyxml2 CONFIG REQUIRED)
|
||||
|
||||
file(GLOB_RECURSE CPP_FILES
|
||||
|
@ -15,7 +13,7 @@ file(GLOB_RECURSE HPP_FILES
|
|||
get_target_property(TINYXML2_INCLUDE_DIR tinyxml2::tinyxml2 INTERFACE_INCLUDE_DIRECTORIES)
|
||||
|
||||
add_library(osmp STATIC
|
||||
${CPP_FILES} ${HPP_FILES}
|
||||
${CPP_FILES}
|
||||
)
|
||||
|
||||
target_include_directories(osmp PUBLIC
|
||||
|
|
51
lib/osmparser/include/osmimember.hpp
Normal file
51
lib/osmparser/include/osmimember.hpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <util.hpp>
|
||||
#include <osmtag.hpp>
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
class Object;
|
||||
|
||||
class IMember
|
||||
{
|
||||
public:
|
||||
enum class Type {
|
||||
NODE, WAY, RELATION
|
||||
};
|
||||
|
||||
public:
|
||||
IMember(const IMember& other) = delete;
|
||||
virtual ~IMember() {}
|
||||
|
||||
IMember::Type GetType() const;
|
||||
|
||||
const std::vector<Tag>& GetTags() const;
|
||||
size_t GetTagsSize() const;
|
||||
const Tag& GetTag(size_t index) const;
|
||||
std::string GetTag(const std::string& key) const;
|
||||
|
||||
protected:
|
||||
IMember(const tinyxml2::XMLElement* element, Object* parent, IMember::Type type);
|
||||
|
||||
protected:
|
||||
IMember::Type type;
|
||||
Object* parent;
|
||||
|
||||
std::vector<Tag> tags;
|
||||
// std::map<std::string, std::string> tags;
|
||||
|
||||
public:
|
||||
unsigned int id;
|
||||
std::string user;
|
||||
unsigned int uid;
|
||||
bool visible;
|
||||
std::string version;
|
||||
unsigned int changeset;
|
||||
std::string timestamp;
|
||||
};
|
||||
}
|
|
@ -2,33 +2,19 @@
|
|||
#include <vector>
|
||||
|
||||
#include "util.hpp"
|
||||
#include <osmimember.hpp>
|
||||
#include <osmtag.hpp>
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
class Object;
|
||||
|
||||
class Node
|
||||
class Node : public IMember
|
||||
{
|
||||
public:
|
||||
Node(const tinyxml2::XMLElement* xml, Object* parent);
|
||||
|
||||
const std::vector<Tag>& GetTags() const;
|
||||
size_t GetTagsSize() const;
|
||||
const Tag& GetTag(size_t index) const;
|
||||
|
||||
private:
|
||||
Object* parent;
|
||||
|
||||
std::vector<Tag> tags;
|
||||
|
||||
public:
|
||||
unsigned int id;
|
||||
float lat, lon;
|
||||
std::string user;
|
||||
unsigned int uid;
|
||||
bool visible;
|
||||
std::string version;
|
||||
unsigned int changeset;
|
||||
std::string timestamp;
|
||||
};
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
|
@ -9,6 +10,7 @@ namespace osmp
|
|||
{
|
||||
class Node;
|
||||
class Way;
|
||||
class Relation;
|
||||
|
||||
class Object
|
||||
{
|
||||
|
@ -16,13 +18,17 @@ namespace osmp
|
|||
Object(const std::string& file);
|
||||
~Object();
|
||||
|
||||
std::vector<Node*> GetNodes() const;
|
||||
std::vector<std::shared_ptr<Node>> GetNodes() const;
|
||||
size_t GetNodesSize() const;
|
||||
const Node* GetNode(unsigned int id) const;
|
||||
std::shared_ptr<Node> GetNode(unsigned int id) const;
|
||||
|
||||
std::vector<Way*> GetWays() const;
|
||||
std::vector<std::shared_ptr<Way>> GetWays() const;
|
||||
size_t GetWaysSize() const;
|
||||
const Way* GetWay(unsigned int id) const;
|
||||
std::shared_ptr<Way> GetWay(unsigned int id) const;
|
||||
|
||||
std::vector<std::shared_ptr<Relation>> GetRelations() const;
|
||||
size_t GetRelationsSize() const;
|
||||
std::shared_ptr<Relation> GetRelation(unsigned int id) const;
|
||||
|
||||
public:
|
||||
const std::string version;
|
||||
|
@ -31,7 +37,8 @@ namespace osmp
|
|||
Bounds bounds;
|
||||
|
||||
private:
|
||||
std::map<unsigned int, Node*> nodes;
|
||||
std::map<unsigned int, Way*> ways;
|
||||
std::map<unsigned int, std::shared_ptr<Node>> nodes;
|
||||
std::map<unsigned int, std::shared_ptr<Way>> ways;
|
||||
std::map<unsigned int, std::shared_ptr<Relation>> relations;
|
||||
};
|
||||
}
|
|
@ -2,4 +2,7 @@
|
|||
|
||||
#include <osmobject.hpp>
|
||||
#include <osmnode.hpp>
|
||||
#include <osmway.hpp>
|
||||
#include <osmway.hpp>
|
||||
#include <osmtag.hpp>
|
||||
#include <osmrelation.hpp>
|
||||
#include <osmimember.hpp>
|
43
lib/osmparser/include/osmrelation.hpp
Normal file
43
lib/osmparser/include/osmrelation.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include <util.hpp>
|
||||
#include <osmtag.hpp>
|
||||
#include <osmimember.hpp>
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
class Object;
|
||||
|
||||
class Relation : public IMember
|
||||
{
|
||||
public:
|
||||
typedef struct sMember {
|
||||
std::shared_ptr<IMember> member;
|
||||
std::string role;
|
||||
} Member;
|
||||
|
||||
public:
|
||||
Relation(const tinyxml2::XMLElement* xml, Object* parent);
|
||||
|
||||
std::string GetRelationType();
|
||||
|
||||
const std::vector<Member>& GetNodes() const;
|
||||
size_t GetNodesSize() const;
|
||||
const Member& GetNode(size_t index) const;
|
||||
|
||||
const std::vector<Member>& GetWays() const;
|
||||
size_t GetWaysSize() const;
|
||||
const Member& GetWay(size_t index) const;
|
||||
|
||||
bool HasNullMembers() const { return hasNullMembers; }
|
||||
|
||||
private:
|
||||
std::string relationType;
|
||||
bool hasNullMembers;
|
||||
|
||||
std::vector<Member> nodes;
|
||||
std::vector<Member> ways;
|
||||
};
|
||||
}
|
36
lib/osmparser/include/osmtag.hpp
Normal file
36
lib/osmparser/include/osmtag.hpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
enum class TagKey {
|
||||
NONE,
|
||||
AERIALWAY, AEROWAY, AMENITY, BARRIER, BOUNDARY,
|
||||
BUILDING, CRAFT, EMERGENCY, GEOLOGICAL, HEALTHCARE,
|
||||
HIGHWAY, HISTORIC, LANDUSE, LEISURE, MANMADE, MILITARY,
|
||||
NATURAL, OFFICE, PLACE, POWER, PUBLIC_TRANSPORT,
|
||||
RAILWAY, ROUTE, SHOP, SPORT, TELECOM, TOURISM, WATER, WATERWAY
|
||||
};
|
||||
|
||||
/*
|
||||
enum class TagValue {
|
||||
NONE,
|
||||
|
||||
BUILDING_APARTMENTS, BUILDING_BUNGALOW, BUILDING_CABIN, BUILDING_DETACHED, BUILDING_DORMITORY, BUILDING_FARM, BUILDING_GER,
|
||||
BUILDING_HOTEL, BUILDING_HOUSE, BUILDING_HOUSEBOAT, BUILDING_RESIDENTIAL, BUILDING_SEMIDETACHED_HOUSE, BUILDING_STATIC_CARAVAN,
|
||||
BUILDING_TERRACE, BUILDING_COMMERCIAL, BUILDING_INDUSTRIAL, BUILDING_KIOSK, BUILDING_OFFICE, BUILDING_RETAIL, BUILDING_SUPERMARKET,
|
||||
BUILDING_WAREHOUSE, BUILDING_CATHEDRAL, BUILDING_CHAPEL, BUILDING_CHURCH, BUILDING_MONASTERY, BUILDING_MOSQUE, BUILDING_PRESBYTERY,
|
||||
BUILDING_RELIGIOUS, BUILDING_SHRINE, BUILDING_SYNAGOGUE, BUILDING_TEMPLE, BUILDING_BAKEHOUSE, BUILDING_CIVIC, BUILDING_FIRE_STATION,
|
||||
BUILDING_GOVERNMENT, BUILDING_HOSPITAL, BUILDING_PUBLIC, BUILDING_TOILETS, BUILDING_TRAIN_STATION, BUILDING_TRANSPORTATION,
|
||||
BUILDING_KINDERGARTEN, BUILDING_SCHOOL, BUILDING_UNIVERSITY
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
typedef struct sTag
|
||||
{
|
||||
std::string k; // TODO: Should/could be an enum
|
||||
std::string v;
|
||||
} Tag;
|
||||
}
|
|
@ -1,39 +1,29 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include <util.hpp>
|
||||
#include <osmtag.hpp>
|
||||
#include <osmimember.hpp>
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
class Object;
|
||||
class Node;
|
||||
|
||||
class Way
|
||||
class Way : public IMember
|
||||
{
|
||||
public:
|
||||
Way(const tinyxml2::XMLElement* way_elem, Object* parent);
|
||||
|
||||
const std::vector<Tag>& GetTags() const;
|
||||
size_t GetTagsSize() const;
|
||||
const Tag& GetTag(size_t index) const;
|
||||
|
||||
const std::vector<const Node*>& GetNodes() const;
|
||||
const std::vector<std::shared_ptr<Node>>& GetNodes() const;
|
||||
size_t GetNodesSize() const;
|
||||
const Node& GetNode(size_t index) const;
|
||||
const std::shared_ptr<Node>& GetNode(size_t index) const;
|
||||
|
||||
public:
|
||||
unsigned int id;
|
||||
std::string user;
|
||||
unsigned int uid;
|
||||
bool visible;
|
||||
std::string version;
|
||||
unsigned int changeset;
|
||||
std::string timestamp;
|
||||
bool area, closed; // Closed := Startpoint = endpoint, Area := Closed AND certain conditions are not met
|
||||
|
||||
private:
|
||||
Object* parent;
|
||||
|
||||
std::vector<const Node*> nodes;
|
||||
std::vector<Tag> tags;
|
||||
std::vector<std::shared_ptr<Node>> nodes;
|
||||
};
|
||||
}
|
|
@ -14,12 +14,6 @@ namespace osmp
|
|||
float minlat, minlon, maxlat, maxlon;
|
||||
} Bounds;
|
||||
|
||||
typedef struct sTag
|
||||
{
|
||||
std::string k; // TODO: Should/could be an enum
|
||||
std::string v;
|
||||
} Tag;
|
||||
|
||||
std::string GetSafeAttributeString(const tinyxml2::XMLElement* elem, const std::string& name);
|
||||
float GetSafeAttributeFloat(const tinyxml2::XMLElement* elem, const std::string& name);
|
||||
unsigned int GetSafeAttributeUint(const tinyxml2::XMLElement* elem, const std::string& name);
|
||||
|
|
66
lib/osmparser/src/osmimember.cpp
Normal file
66
lib/osmparser/src/osmimember.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include <osmimember.hpp>
|
||||
|
||||
#include <osmobject.hpp>
|
||||
#include <tinyxml2.h>
|
||||
|
||||
namespace xml = tinyxml2;
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
IMember::IMember(const xml::XMLElement* element, Object* parent, IMember::Type type) :
|
||||
type(type), parent(parent)
|
||||
{
|
||||
// Get Attribute
|
||||
id = GetSafeAttributeUint(element, "id");
|
||||
user = GetSafeAttributeString(element, "user");
|
||||
uid = GetSafeAttributeUint(element, "uid");
|
||||
visible = GetSafeAttributeBool(element, "visible");
|
||||
version = GetSafeAttributeString(element, "version");
|
||||
changeset = GetSafeAttributeUint(element, "changeset");
|
||||
timestamp = GetSafeAttributeString(element, "timestamp");
|
||||
|
||||
const xml::XMLElement* tag_element = element->FirstChildElement("tag");
|
||||
while (tag_element != nullptr)
|
||||
{
|
||||
tags.push_back({
|
||||
GetSafeAttributeString(tag_element, "k"),
|
||||
GetSafeAttributeString(tag_element, "v"),
|
||||
});
|
||||
|
||||
tag_element = tag_element->NextSiblingElement("tag");
|
||||
}
|
||||
}
|
||||
|
||||
IMember::Type IMember::GetType() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
const std::vector<Tag>& IMember::GetTags() const
|
||||
{
|
||||
return tags;
|
||||
}
|
||||
|
||||
size_t IMember::GetTagsSize() const
|
||||
{
|
||||
return tags.size();
|
||||
}
|
||||
|
||||
const Tag& IMember::GetTag(size_t index) const
|
||||
{
|
||||
return tags[index];
|
||||
}
|
||||
|
||||
std::string IMember::GetTag(const std::string& key) const
|
||||
{
|
||||
for (const Tag& tag : tags)
|
||||
{
|
||||
if (tag.k == key)
|
||||
{
|
||||
return tag.v;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -7,43 +7,10 @@ namespace xml = tinyxml2;
|
|||
namespace osmp
|
||||
{
|
||||
Node::Node(const tinyxml2::XMLElement* node_elem, Object* parent) :
|
||||
parent(parent)
|
||||
IMember(node_elem, parent, IMember::Type::NODE)
|
||||
{
|
||||
// Get Attribute
|
||||
id = GetSafeAttributeUint(node_elem, "id");
|
||||
lat = GetSafeAttributeFloat(node_elem, "lat");
|
||||
lon = GetSafeAttributeFloat(node_elem, "lon");
|
||||
user = GetSafeAttributeString(node_elem, "user");
|
||||
uid = GetSafeAttributeUint(node_elem, "uid");
|
||||
visible = GetSafeAttributeBool(node_elem, "visible");
|
||||
version = GetSafeAttributeString(node_elem, "version");
|
||||
changeset = GetSafeAttributeUint(node_elem, "changeset");
|
||||
timestamp = GetSafeAttributeString(node_elem, "timestamp");
|
||||
|
||||
const xml::XMLElement* tag_element = node_elem->FirstChildElement("tag");
|
||||
while (tag_element != nullptr)
|
||||
{
|
||||
tags.push_back({
|
||||
GetSafeAttributeString(tag_element, "k"),
|
||||
GetSafeAttributeString(tag_element, "v")
|
||||
});
|
||||
|
||||
tag_element = tag_element->NextSiblingElement("tag");
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<Tag>& Node::GetTags() const
|
||||
{
|
||||
return tags;
|
||||
}
|
||||
|
||||
size_t Node::GetTagsSize() const
|
||||
{
|
||||
return tags.size();
|
||||
}
|
||||
|
||||
const Tag& Node::GetTag(size_t index) const
|
||||
{
|
||||
return tags[index];
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <osmnode.hpp>
|
||||
#include <osmway.hpp>
|
||||
#include <osmrelation.hpp>
|
||||
|
||||
namespace xml = tinyxml2;
|
||||
|
||||
|
@ -38,7 +39,7 @@ namespace osmp
|
|||
xml::XMLElement* node_elem = root->FirstChildElement("node");
|
||||
while (node_elem != nullptr)
|
||||
{
|
||||
Node* new_node = new Node(node_elem, this);
|
||||
std::shared_ptr<Node> new_node = std::make_shared<Node>(node_elem, this);
|
||||
nodes.insert(std::make_pair(new_node->id, new_node));
|
||||
|
||||
node_elem = node_elem->NextSiblingElement("node");
|
||||
|
@ -48,32 +49,32 @@ namespace osmp
|
|||
xml::XMLElement* way_elem = root->FirstChildElement("way");
|
||||
while (way_elem != nullptr)
|
||||
{
|
||||
Way* new_way = new Way(way_elem, this);
|
||||
std::shared_ptr<Way> new_way = std::make_shared<Way>(way_elem, this);
|
||||
ways.insert(std::make_pair(new_way->id, new_way));
|
||||
|
||||
way_elem = way_elem->NextSiblingElement("way");
|
||||
}
|
||||
|
||||
// Get relations
|
||||
xml::XMLElement* relation_elem = root->FirstChildElement("relation");
|
||||
while (relation_elem != nullptr)
|
||||
{
|
||||
std::shared_ptr<Relation> new_way = std::make_shared<Relation>(relation_elem, this);
|
||||
relations.insert(std::make_pair(new_way->id, new_way));
|
||||
|
||||
relation_elem = relation_elem->NextSiblingElement("relation");
|
||||
}
|
||||
}
|
||||
|
||||
Object::~Object()
|
||||
{
|
||||
for (std::map<unsigned int, Way*>::iterator it = ways.begin(); it != ways.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
ways.clear();
|
||||
|
||||
for (std::map<unsigned int, Node*>::iterator it = nodes.begin(); it != nodes.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
nodes.clear();
|
||||
}
|
||||
|
||||
std::vector<Node*> Object::GetNodes() const
|
||||
std::vector<std::shared_ptr<Node>> Object::GetNodes() const
|
||||
{
|
||||
std::vector<Node*> vecNodes;
|
||||
for (std::map<unsigned int, Node*>::const_iterator it = nodes.begin(); it != nodes.end(); it++)
|
||||
std::vector<std::shared_ptr<Node>> vecNodes;
|
||||
for (std::map<unsigned int, std::shared_ptr<Node>>::const_iterator it = nodes.begin(); it != nodes.end(); it++)
|
||||
vecNodes.push_back(it->second);
|
||||
|
||||
return vecNodes;
|
||||
|
@ -84,19 +85,19 @@ namespace osmp
|
|||
return nodes.size();
|
||||
}
|
||||
|
||||
const Node* Object::GetNode(unsigned int id) const
|
||||
std::shared_ptr<Node> Object::GetNode(unsigned int id) const
|
||||
{
|
||||
std::map<unsigned int, Node*>::const_iterator node = nodes.find(id);
|
||||
std::map<unsigned int, std::shared_ptr<Node>>::const_iterator node = nodes.find(id);
|
||||
if (node != nodes.end())
|
||||
return node->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<Way*> Object::GetWays() const
|
||||
std::vector<std::shared_ptr<Way>> Object::GetWays() const
|
||||
{
|
||||
std::vector<Way*> vecWays;
|
||||
for (std::map<unsigned int, Way*>::const_iterator it = ways.begin(); it != ways.end(); it++)
|
||||
std::vector<std::shared_ptr<Way>> vecWays;
|
||||
for (std::map<unsigned int, std::shared_ptr<Way>>::const_iterator it = ways.begin(); it != ways.end(); it++)
|
||||
vecWays.push_back(it->second);
|
||||
|
||||
return vecWays;
|
||||
|
@ -107,12 +108,35 @@ namespace osmp
|
|||
return ways.size();
|
||||
}
|
||||
|
||||
const Way* Object::GetWay(unsigned int id) const
|
||||
std::shared_ptr<Way> Object::GetWay(unsigned int id) const
|
||||
{
|
||||
std::map<unsigned int, Way*>::const_iterator way = ways.find(id);
|
||||
std::map<unsigned int, std::shared_ptr<Way>>::const_iterator way = ways.find(id);
|
||||
if (way != ways.end())
|
||||
return way->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Relation>> Object::GetRelations() const
|
||||
{
|
||||
std::vector<std::shared_ptr<Relation>> vecRelations;
|
||||
for (std::map<unsigned int, std::shared_ptr<Relation>>::const_iterator it = relations.begin(); it != relations.end(); it++)
|
||||
vecRelations.push_back(it->second);
|
||||
|
||||
return vecRelations;
|
||||
}
|
||||
|
||||
size_t Object::GetRelationsSize() const
|
||||
{
|
||||
return relations.size();
|
||||
}
|
||||
|
||||
std::shared_ptr<Relation> Object::GetRelation(unsigned int id) const
|
||||
{
|
||||
std::map<unsigned int, std::shared_ptr<Relation>>::const_iterator relation = relations.find(id);
|
||||
if (relation != relations.end())
|
||||
return relation->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
75
lib/osmparser/src/osmrelation.cpp
Normal file
75
lib/osmparser/src/osmrelation.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include <osmrelation.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <tinyxml2.h>
|
||||
#include <osmobject.hpp>
|
||||
#include <osmnode.hpp>
|
||||
#include <osmway.hpp>
|
||||
|
||||
namespace xml = tinyxml2;
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
Relation::Relation(const xml::XMLElement* xml, Object* parent) :
|
||||
IMember(xml, parent, IMember::Type::RELATION), hasNullMembers(false)
|
||||
{
|
||||
const xml::XMLElement* member_element = xml->FirstChildElement("member");
|
||||
while (member_element != nullptr)
|
||||
{
|
||||
std::string memberType = GetSafeAttributeString(member_element, "type");
|
||||
unsigned int ref = GetSafeAttributeUint(member_element, "ref");
|
||||
std::string role = GetSafeAttributeString(member_element, "role");
|
||||
|
||||
std::shared_ptr<IMember> member = nullptr;
|
||||
if (memberType == "node") {
|
||||
member = parent->GetNode(ref);
|
||||
nodes.push_back({ member, role });
|
||||
}
|
||||
else if (memberType == "way") {
|
||||
member = parent->GetWay(ref);
|
||||
if (member == nullptr) {
|
||||
hasNullMembers = true;
|
||||
}
|
||||
ways.push_back({ member, role });
|
||||
}
|
||||
|
||||
member_element = member_element->NextSiblingElement("member");
|
||||
}
|
||||
}
|
||||
|
||||
std::string Relation::GetRelationType()
|
||||
{
|
||||
return GetTag("type");
|
||||
}
|
||||
|
||||
const std::vector<Relation::Member>& Relation::GetNodes() const
|
||||
{
|
||||
return nodes;
|
||||
}
|
||||
|
||||
size_t Relation::GetNodesSize() const
|
||||
{
|
||||
return nodes.size();
|
||||
}
|
||||
|
||||
const Relation::Member& Relation::GetNode(size_t index) const
|
||||
{
|
||||
return nodes[index];
|
||||
}
|
||||
|
||||
const std::vector<Relation::Member>& Relation::GetWays() const
|
||||
{
|
||||
return ways;
|
||||
}
|
||||
|
||||
size_t Relation::GetWaysSize() const
|
||||
{
|
||||
return ways.size();
|
||||
}
|
||||
|
||||
const Relation::Member& Relation::GetWay(size_t index) const
|
||||
{
|
||||
return ways[index];
|
||||
}
|
||||
}
|
|
@ -1,23 +1,20 @@
|
|||
#include <osmway.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <tinyxml2.h>
|
||||
#include <osmobject.hpp>
|
||||
#include <osmtag.hpp>
|
||||
|
||||
namespace xml = tinyxml2;
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
Way::Way(const tinyxml2::XMLElement* way_elem, Object* parent) :
|
||||
parent(parent)
|
||||
IMember(way_elem, parent, IMember::Type::WAY)
|
||||
{
|
||||
// Attributes
|
||||
id = GetSafeAttributeUint(way_elem, "id");
|
||||
user = GetSafeAttributeString(way_elem, "user");
|
||||
uid = GetSafeAttributeUint(way_elem, "uid");
|
||||
visible = GetSafeAttributeBool(way_elem, "visible");
|
||||
version = GetSafeAttributeString(way_elem, "version");
|
||||
changeset = GetSafeAttributeUint(way_elem, "changeset");
|
||||
timestamp = GetSafeAttributeString(way_elem, "timestamp");
|
||||
area = GetSafeAttributeBool(way_elem, "area");
|
||||
closed = false;
|
||||
|
||||
const xml::XMLElement* nd_elem = way_elem->FirstChildElement("nd");
|
||||
while (nd_elem != nullptr)
|
||||
|
@ -28,35 +25,17 @@ namespace osmp
|
|||
|
||||
nd_elem = nd_elem->NextSiblingElement("nd");
|
||||
}
|
||||
|
||||
const xml::XMLElement* tag_elem = way_elem->FirstChildElement("tag");
|
||||
while (tag_elem != nullptr)
|
||||
|
||||
if (nodes.front() == nodes.back())
|
||||
{
|
||||
tags.push_back({
|
||||
GetSafeAttributeString(tag_elem, "k"),
|
||||
GetSafeAttributeString(tag_elem, "v")
|
||||
});
|
||||
closed = true;
|
||||
|
||||
tag_elem = tag_elem->NextSiblingElement("tag");
|
||||
if (!area && GetTag("barrier") == "" && GetTag("highway") == "") // this code sucks, it can be done better
|
||||
area = true;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<Tag>& Way::GetTags() const
|
||||
{
|
||||
return tags;
|
||||
}
|
||||
|
||||
size_t Way::GetTagsSize() const
|
||||
{
|
||||
return tags.size();
|
||||
}
|
||||
|
||||
const Tag& Way::GetTag(size_t index) const
|
||||
{
|
||||
return tags[index];
|
||||
}
|
||||
|
||||
const std::vector<const Node*>& Way::GetNodes() const
|
||||
const std::vector<std::shared_ptr<Node>>& Way::GetNodes() const
|
||||
{
|
||||
return nodes;
|
||||
}
|
||||
|
@ -66,8 +45,8 @@ namespace osmp
|
|||
return nodes.size();
|
||||
}
|
||||
|
||||
const Node& Way::GetNode(size_t index) const
|
||||
const std::shared_ptr<Node>& Way::GetNode(size_t index) const
|
||||
{
|
||||
return *(nodes[index]);
|
||||
return nodes[index];
|
||||
}
|
||||
}
|
|
@ -15,10 +15,7 @@ namespace osmp
|
|||
|
||||
xml::XMLError result = elem->QueryStringAttribute(name.c_str(), &buffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
std::cerr << "Failed to fetch string attribute \"" << name << "\"" << std::endl;
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string returnStr(buffer);
|
||||
return returnStr;
|
||||
|
@ -29,8 +26,6 @@ namespace osmp
|
|||
float returnVal = 0.0f;
|
||||
|
||||
xml::XMLError result = elem->QueryFloatAttribute(name.c_str(), &returnVal);
|
||||
if (FAILED(result))
|
||||
std::cerr << "Failed to fetch float attribute \"" << name << "\"" << std::endl;
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
@ -40,8 +35,6 @@ namespace osmp
|
|||
unsigned int returnVal = 0;
|
||||
|
||||
xml::XMLError result = elem->QueryUnsignedAttribute(name.c_str(), &returnVal);
|
||||
if (FAILED(result))
|
||||
std::cerr << "Failed to fetch uint attribute \"" << name << "\"" << std::endl;
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
@ -51,8 +44,6 @@ namespace osmp
|
|||
bool returnVal = false;
|
||||
|
||||
xml::XMLError result = elem->QueryBoolAttribute(name.c_str(), &returnVal);
|
||||
if (FAILED(result))
|
||||
std::cerr << "Failed to fetch bool attribute \"" << name << "\"" << std::endl;
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue