Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
PCLoaderOSM.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2008-2023 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// A reader of pois and polygons stored in OSM-format
22/****************************************************************************/
23#pragma once
24#include <config.h>
25
26#include <string>
27#include "PCPolyContainer.h"
28#include "PCTypeMap.h"
30
31
32// ===========================================================================
33// class definitions
34// ===========================================================================
35class OptionsCont;
36
37
38// ===========================================================================
39// class declarations
40// ===========================================================================
48public:
60 static void loadIfSet(OptionsCont& oc, PCPolyContainer& toFill,
61 PCTypeMap& tm);
62
63
64protected:
65
68 struct PCOSMNode {
70 long long int id;
72 double lon;
74 double lat;
76 std::string name;
78 std::map<std::string, std::string> myAttributes;
79 };
80
81
86 long long int id;
88 std::string name;
90 std::vector<long long int> myWays;
92 std::map<std::string, std::string> myAttributes;
94 bool keep;
95 };
96
97
100 struct PCOSMEdge {
102 long long int id;
104 std::string name;
108 std::vector<long long int> myCurrentNodes;
110 std::map<std::string, std::string> myAttributes;
111 // @brief Wether this way constitutes a complete polygon object
113 };
114
115 typedef std::vector<PCOSMRelation*> Relations;
116 typedef std::map<long long int, PCOSMRelation*> RelationsMap;
117 typedef std::map<long long int, PCOSMEdge*> EdgeMap;
118
119protected:
121 static int addPolygon(const PCOSMEdge* edge, const PositionVector& vec, const PCTypeMap::TypeDef& def,
122 const std::string& fullType, int index, bool useName, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
123
125 static int addPOI(const PCOSMNode* node, const Position& pos, const PCTypeMap::TypeDef& def,
126 const std::string& fullType, int index, bool useName, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
127
128
129protected:
130 static const std::set<std::string> MyKeysToInclude;
131
132private:
133 static std::set<std::string> initMyKeysToInclude();
134
137
138protected:
144 public:
150 NodesHandler(std::map<long long int, PCOSMNode*>& toFill, bool withAttributes,
151 MsgHandler& errorHandler);
152
153
156
157
158 protected:
160
161
169 void myStartElement(int element, const SUMOSAXAttributes& attrs);
170
171
178 void myEndElement(int element);
180
181
182 private:
185
188
190 std::map<long long int, PCOSMNode*>& myToFill;
191
193 std::vector<int> myParentElements;
194
196 long long int myLastNodeID;
197
198 private:
201
204
205 };
206
212 public:
220 RelationsHandler(RelationsMap& additionalWays,
221 Relations& relations,
222 bool withAttributes,
223 MsgHandler& errorHandler);
224
225
228
229
230 protected:
232
233
241 void myStartElement(int element, const SUMOSAXAttributes& attrs);
242
243
250 void myEndElement(int element);
252
253
254 private:
257
260
263
266
269
271 std::vector<long long int> myCurrentWays;
272
274 std::vector<long long int> myParentElements;
275
277 bool myKeep;
278
279 private:
282
285
286 };
287
288
294 public:
303 EdgesHandler(const std::map<long long int, PCOSMNode*>& osmNodes,
304 EdgeMap& toFill,
305 const RelationsMap& additionalWays,
306 bool withAttributes,
307 MsgHandler& errorHandler);
308
309
312
313
314 protected:
316
317
325 void myStartElement(int element, const SUMOSAXAttributes& attrs);
326
327
334 void myEndElement(int element);
336
337
338 private:
341
344
346 const std::map<long long int, PCOSMNode*>& myOSMNodes;
347
350
353
356
358 std::vector<int> myParentElements;
359
361 bool myKeep;
362
363 private:
366
369
370 };
371
372};
A storage for options typed value containers)
Definition OptionsCont.h:89
A class which extracts OSM-edges from a parsed OSM-file.
bool myWithAttributes
Whether all attributes shall be stored.
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list
EdgeMap & myEdgeMap
A map of built edges.
const RelationsMap & myAdditionalWays
additional ways which are reference by relations
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
void myEndElement(int element)
Called when a closing tag occurs.
PCOSMEdge * myCurrentEdge
The currently built edge.
EdgesHandler & operator=(const EdgesHandler &s)
Invalidated assignment operator.
const std::map< long long int, PCOSMNode * > & myOSMNodes
The previously parsed nodes.
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
EdgesHandler(const EdgesHandler &s)
Invalidated copy constructor.
A class which extracts OSM-nodes from a parsed OSM-file.
NodesHandler & operator=(const NodesHandler &s)
Invalidated assignment operator.
std::map< long long int, PCOSMNode * > & myToFill
The nodes container to fill.
NodesHandler(const NodesHandler &s)
Invalidated copy constructor.
long long int myLastNodeID
The id of the last parsed node.
bool myWithAttributes
Whether all attributes shall be stored.
void myEndElement(int element)
Called when a closing tag occurs.
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
A class which extracts relevant way-ids from relations in a parsed OSM-file.
Relations & myRelations
the loaded relations
std::vector< long long int > myCurrentWays
the ways within the current relation
std::vector< long long int > myParentElements
Current path in order to know to what occuring values belong.
PCOSMRelation * myCurrentRelation
The currently parsed relation.
void myEndElement(int element)
Called when a closing tag occurs.
RelationsHandler & operator=(const RelationsHandler &s)
Invalidated assignment operator.
RelationsHandler(const RelationsHandler &s)
Invalidated copy constructor.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
RelationsMap & myAdditionalWays
additional ways which are reference by relations
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
bool myWithAttributes
Whether all attributes shall be stored.
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list
A reader of pois and polygons stored in OSM-format.
Definition PCLoaderOSM.h:47
static int addPolygon(const PCOSMEdge *edge, const PositionVector &vec, const PCTypeMap::TypeDef &def, const std::string &fullType, int index, bool useName, PCPolyContainer &toFill, bool ignorePruning, bool withAttributes)
try add the polygon and return the next index on success
std::map< long long int, PCOSMEdge * > EdgeMap
static Position convertNodePosition(PCOSMNode *n)
retrieve cartesian coordinate for given node
static int addPOI(const PCOSMNode *node, const Position &pos, const PCTypeMap::TypeDef &def, const std::string &fullType, int index, bool useName, PCPolyContainer &toFill, bool ignorePruning, bool withAttributes)
try add the POI and return the next index on success
static void loadIfSet(OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Loads pois/polygons assumed to be stored as OSM-XML.
std::vector< PCOSMRelation * > Relations
static const std::set< std::string > MyKeysToInclude
std::map< long long int, PCOSMRelation * > RelationsMap
static std::set< std::string > initMyKeysToInclude()
A storage for loaded polygons and pois.
A storage for type mappings.
Definition PCTypeMap.h:42
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
Encapsulated SAX-Attributes.
SAX-handler base for SUMO-files.
An internal definition of a loaded edge.
bool myIsClosed
Information whether this area is closed.
long long int id
The edge's id.
std::map< std::string, std::string > myAttributes
Additional attributes.
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
std::string name
The edge's name (if any)
An internal representation of an OSM-node.
Definition PCLoaderOSM.h:68
double lat
The latitude the node is located at.
Definition PCLoaderOSM.h:74
double lon
The longitude the node is located at.
Definition PCLoaderOSM.h:72
std::string name
The nodes name (if any)
Definition PCLoaderOSM.h:76
long long int id
The node's id.
Definition PCLoaderOSM.h:70
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition PCLoaderOSM.h:78
An internal definition of a loaded relation.
Definition PCLoaderOSM.h:84
std::vector< long long int > myWays
The list of ways this relation is made of.
Definition PCLoaderOSM.h:90
std::string name
The relation's name (if any)
Definition PCLoaderOSM.h:88
bool keep
whether this relation is a valid polygon
Definition PCLoaderOSM.h:94
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition PCLoaderOSM.h:92
long long int id
The relation's id.
Definition PCLoaderOSM.h:86
A single definition of values that shall be used for a given type.
Definition PCTypeMap.h:56