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 /****************************************************************************/
18 // A reader of pois and polygons stored in OSM-format
19 /****************************************************************************/
20 #ifndef PCLoaderOSM_h
21 #define PCLoaderOSM_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <string>
30 #include "PCPolyContainer.h"
31 #include "PCTypeMap.h"
33 
34 
35 // ===========================================================================
36 // class definitions
37 // ===========================================================================
38 class OptionsCont;
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
50 class PCLoaderOSM : public SUMOSAXHandler {
51 public:
63  static void loadIfSet(OptionsCont& oc, PCPolyContainer& toFill,
64  PCTypeMap& tm);
65 
66 
67 protected:
68 
71  struct PCOSMNode {
73  long long int id;
75  double lon;
77  double lat;
79  std::string name;
81  std::map<std::string, std::string> myAttributes;
82  };
83 
84 
87  struct PCOSMRelation {
89  long long int id;
91  std::string name;
93  std::vector<long long int> myWays;
95  std::map<std::string, std::string> myAttributes;
97  bool keep;
98  };
99 
100 
103  struct PCOSMEdge {
105  long long int id;
107  std::string name;
111  std::vector<long long int> myCurrentNodes;
113  std::map<std::string, std::string> myAttributes;
114  // @brief Wether this way constitutes a complete polygon object
116  };
117 
118  typedef std::vector<PCOSMRelation*> Relations;
119  typedef std::map<long long int, PCOSMRelation*> RelationsMap;
120  typedef std::map<long long int, PCOSMEdge*> EdgeMap;
121 
122 protected:
124  static int addPolygon(const PCOSMEdge* edge, const PositionVector& vec, const PCTypeMap::TypeDef& def,
125  const std::string& fullType, int index, bool useName, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
126 
128  static int addPOI(const PCOSMNode* node, const Position& pos, const PCTypeMap::TypeDef& def,
129  const std::string& fullType, int index, bool useName, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
130 
131 
132 protected:
133  static const std::set<std::string> MyKeysToInclude;
134 
135 private:
136  static std::set<std::string> initMyKeysToInclude();
137 
140 
141 protected:
146  class NodesHandler : public SUMOSAXHandler {
147  public:
153  NodesHandler(std::map<long long int, PCOSMNode*>& toFill, bool withAttributes,
154  MsgHandler& errorHandler);
155 
156 
158  ~NodesHandler();
159 
160 
161  protected:
163 
164 
172  void myStartElement(int element, const SUMOSAXAttributes& attrs);
173 
174 
181  void myEndElement(int element);
183 
184 
185  private:
188 
191 
193  std::map<long long int, PCOSMNode*>& myToFill;
194 
196  std::vector<int> myParentElements;
197 
199  long long int myLastNodeID;
200 
201  private:
203  NodesHandler(const NodesHandler& s);
204 
207 
208  };
209 
215  public:
223  RelationsHandler(RelationsMap& additionalWays,
224  Relations& relations,
225  bool withAttributes,
226  MsgHandler& errorHandler);
227 
228 
231 
232 
233  protected:
235 
236 
244  void myStartElement(int element, const SUMOSAXAttributes& attrs);
245 
246 
253  void myEndElement(int element);
255 
256 
257  private:
260 
263 
266 
269 
272 
274  std::vector<long long int> myCurrentWays;
275 
277  std::vector<long long int> myParentElements;
278 
280  bool myKeep;
281 
282  private:
285 
288 
289  };
290 
291 
296  class EdgesHandler : public SUMOSAXHandler {
297  public:
306  EdgesHandler(const std::map<long long int, PCOSMNode*>& osmNodes,
307  EdgeMap& toFill,
308  const RelationsMap& additionalWays,
309  bool withAttributes,
310  MsgHandler& errorHandler);
311 
312 
314  ~EdgesHandler();
315 
316 
317  protected:
319 
320 
328  void myStartElement(int element, const SUMOSAXAttributes& attrs);
329 
330 
337  void myEndElement(int element);
339 
340 
341  private:
344 
347 
349  const std::map<long long int, PCOSMNode*>& myOSMNodes;
350 
353 
356 
359 
361  std::vector<int> myParentElements;
362 
364  bool myKeep;
365 
366  private:
368  EdgesHandler(const EdgesHandler& s);
369 
372 
373  };
374 
375 };
376 
377 
378 #endif
379 
380 /****************************************************************************/
381 
PCLoaderOSM::EdgesHandler::myEdgeMap
EdgeMap & myEdgeMap
A map of built edges.
Definition: PCLoaderOSM.h:352
PCLoaderOSM::NodesHandler::myLastNodeID
long long int myLastNodeID
The id of the last parsed node.
Definition: PCLoaderOSM.h:199
PCLoaderOSM::PCOSMNode::myAttributes
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:81
SUMOSAXHandler
SAX-handler base for SUMO-files.
Definition: SUMOSAXHandler.h:42
PCLoaderOSM::NodesHandler::operator=
NodesHandler & operator=(const NodesHandler &s)
Invalidated assignment operator.
PCLoaderOSM::RelationsHandler::myCurrentRelation
PCOSMRelation * myCurrentRelation
The currently parsed relation.
Definition: PCLoaderOSM.h:271
PCLoaderOSM::PCOSMEdge::myAttributes
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:113
PCLoaderOSM::RelationsHandler::myStartElement
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: PCLoaderOSM.cpp:487
PCLoaderOSM::PCOSMEdge
An internal definition of a loaded edge.
Definition: PCLoaderOSM.h:103
PCLoaderOSM::PCOSMEdge::myIsClosed
bool myIsClosed
Information whether this area is closed.
Definition: PCLoaderOSM.h:109
SUMOSAXHandler.h
PCLoaderOSM::RelationsHandler::~RelationsHandler
~RelationsHandler()
Destructor.
Definition: PCLoaderOSM.cpp:482
PCLoaderOSM::RelationsHandler::myRelations
Relations & myRelations
the loaded relations
Definition: PCLoaderOSM.h:262
PCTypeMap.h
PCLoaderOSM::EdgesHandler::~EdgesHandler
~EdgesHandler()
Destructor.
Definition: PCLoaderOSM.cpp:572
PCLoaderOSM::RelationsHandler
A class which extracts relevant way-ids from relations in a parsed OSM-file.
Definition: PCLoaderOSM.h:214
PCLoaderOSM::RelationsHandler::myAdditionalWays
RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:259
PositionVector
A list of positions.
Definition: PositionVector.h:46
PCLoaderOSM::PCOSMRelation
An internal definition of a loaded relation.
Definition: PCLoaderOSM.h:87
PCLoaderOSM::PCOSMRelation::myWays
std::vector< long long int > myWays
The list of ways this relation is made of.
Definition: PCLoaderOSM.h:93
PCLoaderOSM::NodesHandler::myStartElement
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: PCLoaderOSM.cpp:413
PCLoaderOSM::EdgeMap
std::map< long long int, PCOSMEdge * > EdgeMap
Definition: PCLoaderOSM.h:120
PCLoaderOSM::convertNodePosition
static Position convertNodePosition(PCOSMNode *n)
retrieve cartesian coordinate for given node
Definition: PCLoaderOSM.cpp:345
PCLoaderOSM::RelationsHandler::myParentElements
std::vector< long long int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:277
PCLoaderOSM::PCOSMNode::id
long long int id
The node's id.
Definition: PCLoaderOSM.h:73
PCLoaderOSM::PCOSMNode::name
std::string name
The nodes name (if any)
Definition: PCLoaderOSM.h:79
MsgHandler
Definition: MsgHandler.h:44
PCLoaderOSM::EdgesHandler::myCurrentEdge
PCOSMEdge * myCurrentEdge
The currently built edge.
Definition: PCLoaderOSM.h:358
PCLoaderOSM::NodesHandler::myEndElement
void myEndElement(int element)
Called when a closing tag occurs.
Definition: PCLoaderOSM.cpp:458
PCLoaderOSM::EdgesHandler::myErrorHandler
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
Definition: PCLoaderOSM.h:346
PCLoaderOSM::RelationsMap
std::map< long long int, PCOSMRelation * > RelationsMap
Definition: PCLoaderOSM.h:119
PCLoaderOSM::PCOSMEdge::id
long long int id
The edge's id.
Definition: PCLoaderOSM.h:105
PCLoaderOSM::initMyKeysToInclude
static std::set< std::string > initMyKeysToInclude()
Definition: PCLoaderOSM.cpp:59
PCLoaderOSM::EdgesHandler::operator=
EdgesHandler & operator=(const EdgesHandler &s)
Invalidated assignment operator.
PCLoaderOSM::MyKeysToInclude
static const std::set< std::string > MyKeysToInclude
Definition: PCLoaderOSM.h:133
PCLoaderOSM::PCOSMRelation::name
std::string name
The relation's name (if any)
Definition: PCLoaderOSM.h:91
PCLoaderOSM::EdgesHandler::myEndElement
void myEndElement(int element)
Called when a closing tag occurs.
Definition: PCLoaderOSM.cpp:631
PCLoaderOSM::NodesHandler
A class which extracts OSM-nodes from a parsed OSM-file.
Definition: PCLoaderOSM.h:146
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:377
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
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:364
PCLoaderOSM::EdgesHandler::myWithAttributes
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:343
PCLoaderOSM::PCOSMEdge::standalone
bool standalone
Definition: PCLoaderOSM.h:115
PCLoaderOSM::NodesHandler::myErrorHandler
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
Definition: PCLoaderOSM.h:190
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:353
PCLoaderOSM::EdgesHandler::myStartElement
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: PCLoaderOSM.cpp:577
PCLoaderOSM::RelationsHandler::myCurrentWays
std::vector< long long int > myCurrentWays
the ways within the current relation
Definition: PCLoaderOSM.h:274
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:280
PCLoaderOSM::PCOSMNode::lat
double lat
The latitude the node is located at.
Definition: PCLoaderOSM.h:77
PCLoaderOSM::Relations
std::vector< PCOSMRelation * > Relations
Definition: PCLoaderOSM.h:118
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:95
PCLoaderOSM::EdgesHandler::myParentElements
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:361
PCLoaderOSM::PCOSMEdge::myCurrentNodes
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
Definition: PCLoaderOSM.h:111
PCLoaderOSM::RelationsHandler::myWithAttributes
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:265
PCLoaderOSM::PCOSMNode::lon
double lon
The longitude the node is located at.
Definition: PCLoaderOSM.h:75
PCLoaderOSM::RelationsHandler::RelationsHandler
RelationsHandler(RelationsMap &additionalWays, Relations &relations, bool withAttributes, MsgHandler &errorHandler)
Constructor.
Definition: PCLoaderOSM.cpp:469
PCLoaderOSM::EdgesHandler
A class which extracts OSM-edges from a parsed OSM-file.
Definition: PCLoaderOSM.h:296
PCPolyContainer
A storage for loaded polygons and pois.
Definition: PCPolyContainer.h:51
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:559
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:45
PCLoaderOSM::NodesHandler::myParentElements
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:196
PCLoaderOSM::RelationsHandler::myEndElement
void myEndElement(int element)
Called when a closing tag occurs.
Definition: PCLoaderOSM.cpp:546
PCLoaderOSM::NodesHandler::myToFill
std::map< long long int, PCOSMNode * > & myToFill
The nodes container to fill.
Definition: PCLoaderOSM.h:193
PCLoaderOSM::PCOSMNode
An internal representation of an OSM-node.
Definition: PCLoaderOSM.h:71
PCLoaderOSM::EdgesHandler::myAdditionalWays
const RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:355
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:57
PCLoaderOSM::RelationsHandler::myErrorHandler
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
Definition: PCLoaderOSM.h:268
PCTypeMap::TypeDef
A single definition of values that shall be used for a given type.
Definition: PCTypeMap.h:59
PCLoaderOSM::NodesHandler::~NodesHandler
~NodesHandler()
Destructor.
Definition: PCLoaderOSM.cpp:409
PCLoaderOSM::NodesHandler::myWithAttributes
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:187
PCLoaderOSM::PCOSMEdge::name
std::string name
The edge's name (if any)
Definition: PCLoaderOSM.h:107
PCLoaderOSM
A reader of pois and polygons stored in OSM-format.
Definition: PCLoaderOSM.h:50
PCLoaderOSM::PCOSMRelation::id
long long int id
The relation's id.
Definition: PCLoaderOSM.h:89
PCLoaderOSM::EdgesHandler::myOSMNodes
const std::map< long long int, PCOSMNode * > & myOSMNodes
The previously parsed nodes.
Definition: PCLoaderOSM.h:349
PCLoaderOSM::NodesHandler::NodesHandler
NodesHandler(std::map< long long int, PCOSMNode * > &toFill, bool withAttributes, MsgHandler &errorHandler)
Contructor.
Definition: PCLoaderOSM.cpp:403
PCLoaderOSM::PCOSMRelation::keep
bool keep
whether this relation is a valid polygon
Definition: PCLoaderOSM.h:97