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-2022 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 // ===========================================================================
35 class OptionsCont;
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
47 class PCLoaderOSM : public SUMOSAXHandler {
48 public:
60  static void loadIfSet(OptionsCont& oc, PCPolyContainer& toFill,
61  PCTypeMap& tm);
62 
63 
64 protected:
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 
84  struct PCOSMRelation {
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 
119 protected:
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 
129 protected:
130  static const std::set<std::string> MyKeysToInclude;
131 
132 private:
133  static std::set<std::string> initMyKeysToInclude();
134 
137 
138 protected:
143  class NodesHandler : public SUMOSAXHandler {
144  public:
150  NodesHandler(std::map<long long int, PCOSMNode*>& toFill, bool withAttributes,
151  MsgHandler& errorHandler);
152 
153 
155  ~NodesHandler();
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 
293  class EdgesHandler : public SUMOSAXHandler {
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 
311  ~EdgesHandler();
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.
Definition: PCLoaderOSM.h:293
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:340
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list
Definition: PCLoaderOSM.h:361
EdgeMap & myEdgeMap
A map of built edges.
Definition: PCLoaderOSM.h:349
const RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:352
EdgesHandler & operator=(const EdgesHandler &s)
Invalidated assignment operator.
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.
Definition: PCLoaderOSM.h:355
const std::map< long long int, PCOSMNode * > & myOSMNodes
The previously parsed nodes.
Definition: PCLoaderOSM.h:346
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:358
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
Definition: PCLoaderOSM.h:343
EdgesHandler(const std::map< long long int, PCOSMNode * > &osmNodes, EdgeMap &toFill, const RelationsMap &additionalWays, bool withAttributes, MsgHandler &errorHandler)
Constructor.
EdgesHandler(const EdgesHandler &s)
Invalidated copy constructor.
A class which extracts OSM-nodes from a parsed OSM-file.
Definition: PCLoaderOSM.h:143
std::map< long long int, PCOSMNode * > & myToFill
The nodes container to fill.
Definition: PCLoaderOSM.h:190
NodesHandler(const NodesHandler &s)
Invalidated copy constructor.
long long int myLastNodeID
The id of the last parsed node.
Definition: PCLoaderOSM.h:196
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:184
NodesHandler(std::map< long long int, PCOSMNode * > &toFill, bool withAttributes, MsgHandler &errorHandler)
Contructor.
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.
Definition: PCLoaderOSM.h:193
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)
Definition: PCLoaderOSM.h:187
NodesHandler & operator=(const NodesHandler &s)
Invalidated assignment operator.
A class which extracts relevant way-ids from relations in a parsed OSM-file.
Definition: PCLoaderOSM.h:211
Relations & myRelations
the loaded relations
Definition: PCLoaderOSM.h:259
std::vector< long long int > myCurrentWays
the ways within the current relation
Definition: PCLoaderOSM.h:271
std::vector< long long int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:274
PCOSMRelation * myCurrentRelation
The currently parsed relation.
Definition: PCLoaderOSM.h:268
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;.
RelationsHandler(RelationsMap &additionalWays, Relations &relations, bool withAttributes, MsgHandler &errorHandler)
Constructor.
RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:256
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
Definition: PCLoaderOSM.h:265
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:262
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list
Definition: PCLoaderOSM.h:277
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
Definition: PCLoaderOSM.h:117
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.
Definition: PCLoaderOSM.cpp:90
std::vector< PCOSMRelation * > Relations
Definition: PCLoaderOSM.h:115
static const std::set< std::string > MyKeysToInclude
Definition: PCLoaderOSM.h:130
std::map< long long int, PCOSMRelation * > RelationsMap
Definition: PCLoaderOSM.h:116
static std::set< std::string > initMyKeysToInclude()
Definition: PCLoaderOSM.cpp:57
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.
Definition: PCLoaderOSM.h:100
bool myIsClosed
Information whether this area is closed.
Definition: PCLoaderOSM.h:106
long long int id
The edge's id.
Definition: PCLoaderOSM.h:102
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:110
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
Definition: PCLoaderOSM.h:108
std::string name
The edge's name (if any)
Definition: PCLoaderOSM.h:104
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