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-2018 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 
230  ~RelationsHandler();
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:
259  RelationsMap& myAdditionalWays;
260 
262  Relations& myRelations;
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 
352  EdgeMap& myEdgeMap;
353 
355  const RelationsMap& myAdditionalWays;
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 
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:95
An internal definition of a loaded edge.
Definition: PCLoaderOSM.h:103
static void loadIfSet(OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Loads pois/polygons assumed to be stored as OSM-XML.
Definition: PCLoaderOSM.cpp:88
EdgeMap & myEdgeMap
A map of built edges.
Definition: PCLoaderOSM.h:352
A single definition of values that shall be used for a given type.
Definition: PCTypeMap.h:59
PCOSMRelation * myCurrentRelation
The currently parsed relation.
Definition: PCLoaderOSM.h:271
An internal definition of a loaded relation.
Definition: PCLoaderOSM.h:87
RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:259
static Position convertNodePosition(PCOSMNode *n)
retrieve cartesian coordinate for given node
std::vector< long long int > myCurrentWays
the ways within the current relation
Definition: PCLoaderOSM.h:274
long long int myLastNodeID
The id of the last parsed node.
Definition: PCLoaderOSM.h:199
Relations & myRelations
the loaded relations
Definition: PCLoaderOSM.h:262
long long int id
The node&#39;s id.
Definition: PCLoaderOSM.h:73
static std::set< std::string > initMyKeysToInclude()
Definition: PCLoaderOSM.cpp:59
SAX-handler base for SUMO-files.
A storage for loaded polygons and pois.
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set) ...
Definition: PCLoaderOSM.h:346
double lon
The longitude the node is located at.
Definition: PCLoaderOSM.h:75
bool keep
whether this relation is a valid polygon
Definition: PCLoaderOSM.h:97
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
std::map< long long int, PCOSMEdge * > EdgeMap
Definition: PCLoaderOSM.h:120
long long int id
The edge&#39;s id.
Definition: PCLoaderOSM.h:105
A class which extracts relevant way-ids from relations in a parsed OSM-file.
Definition: PCLoaderOSM.h:214
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list ...
Definition: PCLoaderOSM.h:280
static const std::set< std::string > MyKeysToInclude
Definition: PCLoaderOSM.h:133
double lat
The latitude the node is located at.
Definition: PCLoaderOSM.h:77
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:113
A storage for type mappings.
Definition: PCTypeMap.h:45
PCOSMEdge * myCurrentEdge
The currently built edge.
Definition: PCLoaderOSM.h:358
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set) ...
Definition: PCLoaderOSM.h:190
std::string name
The relation&#39;s name (if any)
Definition: PCLoaderOSM.h:91
Encapsulated SAX-Attributes.
A reader of pois and polygons stored in OSM-format.
Definition: PCLoaderOSM.h:50
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:81
bool myIsClosed
Information whether this area is closed.
Definition: PCLoaderOSM.h:109
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set) ...
Definition: PCLoaderOSM.h:268
A class which extracts OSM-edges from a parsed OSM-file.
Definition: PCLoaderOSM.h:296
std::map< long long int, PCOSMRelation * > RelationsMap
Definition: PCLoaderOSM.h:119
long long int id
The relation&#39;s id.
Definition: PCLoaderOSM.h:89
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list ...
Definition: PCLoaderOSM.h:364
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:361
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:343
A class which extracts OSM-nodes from a parsed OSM-file.
Definition: PCLoaderOSM.h:146
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Callback method for an opening tag to implement by derived classes.
std::vector< long long int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:277
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:196
std::vector< PCOSMRelation * > Relations
Definition: PCLoaderOSM.h:118
const SUMOSAXHandler & operator=(const SUMOSAXHandler &s)
invalidated assignment operator
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
Definition: PCLoaderOSM.h:111
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
A storage for options typed value containers)
Definition: OptionsCont.h:92
std::string name
The edge&#39;s name (if any)
Definition: PCLoaderOSM.h:107
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:265
std::vector< long long int > myWays
The list of ways this relation is made of.
Definition: PCLoaderOSM.h:93
std::string name
The nodes name (if any)
Definition: PCLoaderOSM.h:79
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:187
const std::map< long long int, PCOSMNode * > & myOSMNodes
The previously parsed nodes.
Definition: PCLoaderOSM.h:349
std::map< long long int, PCOSMNode * > & myToFill
The nodes container to fill.
Definition: PCLoaderOSM.h:193
const RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:355
An internal representation of an OSM-node.
Definition: PCLoaderOSM.h:71
virtual void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.