Eclipse SUMO - Simulation of Urban MObility
PCLoaderOSM.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2008-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A reader of pois and polygons stored in OSM-format
18 /****************************************************************************/
19 #ifndef PCLoaderOSM_h
20 #define PCLoaderOSM_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include "PCPolyContainer.h"
30 #include "PCTypeMap.h"
32 
33 
34 // ===========================================================================
35 // class definitions
36 // ===========================================================================
37 class OptionsCont;
38 
39 
40 // ===========================================================================
41 // class declarations
42 // ===========================================================================
49 class PCLoaderOSM : public SUMOSAXHandler {
50 public:
62  static void loadIfSet(OptionsCont& oc, PCPolyContainer& toFill,
63  PCTypeMap& tm);
64 
65 
66 protected:
67 
70  struct PCOSMNode {
72  long long int id;
74  double lon;
76  double lat;
78  std::string name;
80  std::map<std::string, std::string> myAttributes;
81  };
82 
83 
86  struct PCOSMRelation {
88  long long int id;
90  std::string name;
92  std::vector<long long int> myWays;
94  std::map<std::string, std::string> myAttributes;
96  bool keep;
97  };
98 
99 
102  struct PCOSMEdge {
104  long long int id;
106  std::string name;
110  std::vector<long long int> myCurrentNodes;
112  std::map<std::string, std::string> myAttributes;
113  // @brief Wether this way constitutes a complete polygon object
115  };
116 
117  typedef std::vector<PCOSMRelation*> Relations;
118  typedef std::map<long long int, PCOSMRelation*> RelationsMap;
119  typedef std::map<long long int, PCOSMEdge*> EdgeMap;
120 
121 protected:
123  static int addPolygon(const PCOSMEdge* edge, const PositionVector& vec, const PCTypeMap::TypeDef& def,
124  const std::string& fullType, int index, bool useName, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
125 
127  static int addPOI(const PCOSMNode* node, const Position& pos, const PCTypeMap::TypeDef& def,
128  const std::string& fullType, int index, bool useName, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
129 
130 
131 protected:
132  static const std::set<std::string> MyKeysToInclude;
133 
134 private:
135  static std::set<std::string> initMyKeysToInclude();
136 
139 
140 protected:
145  class NodesHandler : public SUMOSAXHandler {
146  public:
152  NodesHandler(std::map<long long int, PCOSMNode*>& toFill, bool withAttributes,
153  MsgHandler& errorHandler);
154 
155 
157  ~NodesHandler();
158 
159 
160  protected:
162 
163 
171  void myStartElement(int element, const SUMOSAXAttributes& attrs);
172 
173 
180  void myEndElement(int element);
182 
183 
184  private:
187 
190 
192  std::map<long long int, PCOSMNode*>& myToFill;
193 
195  std::vector<int> myParentElements;
196 
198  long long int myLastNodeID;
199 
200  private:
202  NodesHandler(const NodesHandler& s);
203 
206 
207  };
208 
214  public:
222  RelationsHandler(RelationsMap& additionalWays,
223  Relations& relations,
224  bool withAttributes,
225  MsgHandler& errorHandler);
226 
227 
230 
231 
232  protected:
234 
235 
243  void myStartElement(int element, const SUMOSAXAttributes& attrs);
244 
245 
252  void myEndElement(int element);
254 
255 
256  private:
259 
262 
265 
268 
271 
273  std::vector<long long int> myCurrentWays;
274 
276  std::vector<long long int> myParentElements;
277 
279  bool myKeep;
280 
281  private:
284 
287 
288  };
289 
290 
295  class EdgesHandler : public SUMOSAXHandler {
296  public:
305  EdgesHandler(const std::map<long long int, PCOSMNode*>& osmNodes,
306  EdgeMap& toFill,
307  const RelationsMap& additionalWays,
308  bool withAttributes,
309  MsgHandler& errorHandler);
310 
311 
313  ~EdgesHandler();
314 
315 
316  protected:
318 
319 
327  void myStartElement(int element, const SUMOSAXAttributes& attrs);
328 
329 
336  void myEndElement(int element);
338 
339 
340  private:
343 
346 
348  const std::map<long long int, PCOSMNode*>& myOSMNodes;
349 
352 
355 
358 
360  std::vector<int> myParentElements;
361 
363  bool myKeep;
364 
365  private:
367  EdgesHandler(const EdgesHandler& s);
368 
371 
372  };
373 
374 };
375 
376 
377 #endif
378 
379 /****************************************************************************/
380 
PCLoaderOSM::EdgesHandler::myEdgeMap
EdgeMap & myEdgeMap
A map of built edges.
Definition: PCLoaderOSM.h:351
PCLoaderOSM::NodesHandler::myLastNodeID
long long int myLastNodeID
The id of the last parsed node.
Definition: PCLoaderOSM.h:198
PCLoaderOSM::PCOSMNode::myAttributes
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:80
SUMOSAXHandler
SAX-handler base for SUMO-files.
Definition: SUMOSAXHandler.h:41
PCLoaderOSM::NodesHandler::operator=
NodesHandler & operator=(const NodesHandler &s)
Invalidated assignment operator.
PCLoaderOSM::RelationsHandler::myCurrentRelation
PCOSMRelation * myCurrentRelation
The currently parsed relation.
Definition: PCLoaderOSM.h:270
PCLoaderOSM::PCOSMEdge::myAttributes
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:112
PCLoaderOSM::RelationsHandler::myStartElement
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: PCLoaderOSM.cpp:484
PCLoaderOSM::PCOSMEdge
An internal definition of a loaded edge.
Definition: PCLoaderOSM.h:102
PCLoaderOSM::PCOSMEdge::myIsClosed
bool myIsClosed
Information whether this area is closed.
Definition: PCLoaderOSM.h:108
SUMOSAXHandler.h
PCLoaderOSM::RelationsHandler::~RelationsHandler
~RelationsHandler()
Destructor.
Definition: PCLoaderOSM.cpp:479
PCLoaderOSM::RelationsHandler::myRelations
Relations & myRelations
the loaded relations
Definition: PCLoaderOSM.h:261
PCTypeMap.h
PCLoaderOSM::EdgesHandler::~EdgesHandler
~EdgesHandler()
Destructor.
Definition: PCLoaderOSM.cpp:569
PCLoaderOSM::RelationsHandler
A class which extracts relevant way-ids from relations in a parsed OSM-file.
Definition: PCLoaderOSM.h:213
PCLoaderOSM::RelationsHandler::myAdditionalWays
RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:258
PositionVector
A list of positions.
Definition: PositionVector.h:45
PCLoaderOSM::PCOSMRelation
An internal definition of a loaded relation.
Definition: PCLoaderOSM.h:86
PCLoaderOSM::PCOSMRelation::myWays
std::vector< long long int > myWays
The list of ways this relation is made of.
Definition: PCLoaderOSM.h:92
PCLoaderOSM::NodesHandler::myStartElement
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: PCLoaderOSM.cpp:410
PCLoaderOSM::EdgeMap
std::map< long long int, PCOSMEdge * > EdgeMap
Definition: PCLoaderOSM.h:119
PCLoaderOSM::convertNodePosition
static Position convertNodePosition(PCOSMNode *n)
retrieve cartesian coordinate for given node
Definition: PCLoaderOSM.cpp:342
PCLoaderOSM::RelationsHandler::myParentElements
std::vector< long long int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:276
PCLoaderOSM::PCOSMNode::id
long long int id
The node's id.
Definition: PCLoaderOSM.h:72
PCLoaderOSM::PCOSMNode::name
std::string name
The nodes name (if any)
Definition: PCLoaderOSM.h:78
MsgHandler
Definition: MsgHandler.h:38
PCLoaderOSM::EdgesHandler::myCurrentEdge
PCOSMEdge * myCurrentEdge
The currently built edge.
Definition: PCLoaderOSM.h:357
PCLoaderOSM::NodesHandler::myEndElement
void myEndElement(int element)
Called when a closing tag occurs.
Definition: PCLoaderOSM.cpp:455
PCLoaderOSM::EdgesHandler::myErrorHandler
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
Definition: PCLoaderOSM.h:345
PCLoaderOSM::RelationsMap
std::map< long long int, PCOSMRelation * > RelationsMap
Definition: PCLoaderOSM.h:118
PCLoaderOSM::PCOSMEdge::id
long long int id
The edge's id.
Definition: PCLoaderOSM.h:104
PCLoaderOSM::initMyKeysToInclude
static std::set< std::string > initMyKeysToInclude()
Definition: PCLoaderOSM.cpp:58
PCLoaderOSM::EdgesHandler::operator=
EdgesHandler & operator=(const EdgesHandler &s)
Invalidated assignment operator.
PCLoaderOSM::MyKeysToInclude
static const std::set< std::string > MyKeysToInclude
Definition: PCLoaderOSM.h:132
PCLoaderOSM::PCOSMRelation::name
std::string name
The relation's name (if any)
Definition: PCLoaderOSM.h:90
PCLoaderOSM::EdgesHandler::myEndElement
void myEndElement(int element)
Called when a closing tag occurs.
Definition: PCLoaderOSM.cpp:628
PCLoaderOSM::NodesHandler
A class which extracts OSM-nodes from a parsed OSM-file.
Definition: PCLoaderOSM.h:145
PCPolyContainer.h
PCLoaderOSM::addPOI
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
Definition: PCLoaderOSM.cpp:374
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
PCLoaderOSM::EdgesHandler::myKeep
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list
Definition: PCLoaderOSM.h:363
PCLoaderOSM::EdgesHandler::myWithAttributes
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:342
PCLoaderOSM::PCOSMEdge::standalone
bool standalone
Definition: PCLoaderOSM.h:114
PCLoaderOSM::NodesHandler::myErrorHandler
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
Definition: PCLoaderOSM.h:189
PCLoaderOSM::addPolygon
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
Definition: PCLoaderOSM.cpp:350
PCLoaderOSM::EdgesHandler::myStartElement
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: PCLoaderOSM.cpp:574
PCLoaderOSM::RelationsHandler::myCurrentWays
std::vector< long long int > myCurrentWays
the ways within the current relation
Definition: PCLoaderOSM.h:273
PCLoaderOSM::RelationsHandler::myKeep
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list
Definition: PCLoaderOSM.h:279
PCLoaderOSM::PCOSMNode::lat
double lat
The latitude the node is located at.
Definition: PCLoaderOSM.h:76
PCLoaderOSM::Relations
std::vector< PCOSMRelation * > Relations
Definition: PCLoaderOSM.h:117
PCLoaderOSM::RelationsHandler::operator=
RelationsHandler & operator=(const RelationsHandler &s)
Invalidated assignment operator.
PCLoaderOSM::PCOSMRelation::myAttributes
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:94
PCLoaderOSM::EdgesHandler::myParentElements
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:360
PCLoaderOSM::PCOSMEdge::myCurrentNodes
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
Definition: PCLoaderOSM.h:110
PCLoaderOSM::RelationsHandler::myWithAttributes
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:264
PCLoaderOSM::PCOSMNode::lon
double lon
The longitude the node is located at.
Definition: PCLoaderOSM.h:74
PCLoaderOSM::RelationsHandler::RelationsHandler
RelationsHandler(RelationsMap &additionalWays, Relations &relations, bool withAttributes, MsgHandler &errorHandler)
Constructor.
Definition: PCLoaderOSM.cpp:466
PCLoaderOSM::EdgesHandler
A class which extracts OSM-edges from a parsed OSM-file.
Definition: PCLoaderOSM.h:295
PCPolyContainer
A storage for loaded polygons and pois.
Definition: PCPolyContainer.h:50
config.h
PCLoaderOSM::EdgesHandler::EdgesHandler
EdgesHandler(const std::map< long long int, PCOSMNode * > &osmNodes, EdgeMap &toFill, const RelationsMap &additionalWays, bool withAttributes, MsgHandler &errorHandler)
Constructor.
Definition: PCLoaderOSM.cpp:556
PCLoaderOSM::loadIfSet
static void loadIfSet(OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Loads pois/polygons assumed to be stored as OSM-XML.
Definition: PCLoaderOSM.cpp:91
PCTypeMap
A storage for type mappings.
Definition: PCTypeMap.h:44
PCLoaderOSM::NodesHandler::myParentElements
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:195
PCLoaderOSM::RelationsHandler::myEndElement
void myEndElement(int element)
Called when a closing tag occurs.
Definition: PCLoaderOSM.cpp:543
PCLoaderOSM::NodesHandler::myToFill
std::map< long long int, PCOSMNode * > & myToFill
The nodes container to fill.
Definition: PCLoaderOSM.h:192
PCLoaderOSM::PCOSMNode
An internal representation of an OSM-node.
Definition: PCLoaderOSM.h:70
PCLoaderOSM::EdgesHandler::myAdditionalWays
const RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:354
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:56
PCLoaderOSM::RelationsHandler::myErrorHandler
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
Definition: PCLoaderOSM.h:267
PCTypeMap::TypeDef
A single definition of values that shall be used for a given type.
Definition: PCTypeMap.h:58
PCLoaderOSM::NodesHandler::~NodesHandler
~NodesHandler()
Destructor.
Definition: PCLoaderOSM.cpp:406
PCLoaderOSM::NodesHandler::myWithAttributes
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:186
PCLoaderOSM::PCOSMEdge::name
std::string name
The edge's name (if any)
Definition: PCLoaderOSM.h:106
PCLoaderOSM
A reader of pois and polygons stored in OSM-format.
Definition: PCLoaderOSM.h:49
PCLoaderOSM::PCOSMRelation::id
long long int id
The relation's id.
Definition: PCLoaderOSM.h:88
PCLoaderOSM::EdgesHandler::myOSMNodes
const std::map< long long int, PCOSMNode * > & myOSMNodes
The previously parsed nodes.
Definition: PCLoaderOSM.h:348
PCLoaderOSM::NodesHandler::NodesHandler
NodesHandler(std::map< long long int, PCOSMNode * > &toFill, bool withAttributes, MsgHandler &errorHandler)
Contructor.
Definition: PCLoaderOSM.cpp:400
PCLoaderOSM::PCOSMRelation::keep
bool keep
whether this relation is a valid polygon
Definition: PCLoaderOSM.h:96