SUMO - Simulation of Urban MObility
NIImporter_OpenStreetMap.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // Importer for networks stored in OpenStreetMap format
22 /****************************************************************************/
23 #ifndef NIImporter_OpenStreetMap_h
24 #define NIImporter_OpenStreetMap_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <string>
37 #include <map>
41 #include <netbuild/NBPTPlatform.h>
42 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class NBEdge;
48 class NBEdgeCont;
49 class NBNetBuilder;
50 class NBNode;
51 class NBNodeCont;
53 class NBTypeCont;
54 class OptionsCont;
55 
56 
57 // ===========================================================================
58 // class definitions
59 // ===========================================================================
66 public:
78  static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
79 
80 
81 protected:
84  struct NIOSMNode {
85  NIOSMNode(long long int _id, double _lon, double _lat)
86  :
87  id(_id), lon(_lon), lat(_lat), ele(0), tlsControlled(false), railwayCrossing(false),
88  ptStopPosition(false), ptStopLength(0), name(""),
90  node(0) { }
91 
93  const long long int id;
95  const double lon;
97  const double lat;
99  double ele;
107  double ptStopLength;
109  std::string name;
114 
115  private:
117  NIOSMNode& operator=(const NIOSMNode& s) = delete;
118 
119 
120  };
121 
125  enum WayType {
126  WAY_NONE = 0,
131  };
132 
133  enum ParkingType {
142  };
143 
144 
147  struct Edge : public Parameterised {
148 
149  explicit Edge(long long int _id)
150  :
151  id(_id), myNoLanes(-1), myNoLanesForward(0), myMaxSpeed(MAXSPEED_UNGIVEN),
152  myCyclewayType(WAY_UNKNOWN), // building of extra lane depends on bikelaneWidth of loaded typemap
153  myBuswayType(WAY_NONE), // buslanes are always built when declared
154  myParkingType(PARKING_NONE), // parking areas exported optionally
155  myLayer(0), // layer is non-zero only in conflict areas
156  myCurrentIsRoad(false),
157  myCurrentIsPlatform(false) { }
158 
159 
161  const long long int id;
163  std::string streetName;
169  double myMaxSpeed;
171  std::string myHighWayType;
173  std::string myIsOneWay;
181  int myLayer;
183  std::vector<long long int> myCurrentNodes;
188 
189  private:
191  Edge& operator=(const Edge& s) = delete;
192 
193 
194  };
195 
196 
198 
200 
201  void load(const OptionsCont& oc, NBNetBuilder& nb);
202 
203 private:
207  class CompareNodes {
208  public:
209  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
210  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
211  }
212  };
213 
214 
216  static const std::string compoundTypeSeparator;
217 
219 
223  std::map<long long int, NIOSMNode*> myOSMNodes;
224 
226  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
227 
228 
230  std::map<long long int, Edge*> myEdges;
231 
233  std::map<long long int, Edge*> myPlatformShapes;
234 
236  std::set<std::string> myUnusableTypes;
237 
239  std::map<std::string, std::string> myKnownCompoundTypes;
240 
255  NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
256 
257 
270  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
271  const std::vector<long long int>& passed, NBNetBuilder& nb);
272 
274  void reconstructLayerElevation(double layerElevation, NBNetBuilder& nb);
275 
277  std::map<NBNode*, std::pair<double, double> >
278  getNeighboringNodes(NBNode* node, double maxDist, const std::set<NBNode*>& knownElevation);
279 
280 protected:
281  static const double MAXSPEED_UNGIVEN;
282  static const long long int INVALID_ID;
283 
288  friend class NodesHandler;
289  class NodesHandler : public SUMOSAXHandler {
290  public:
296  NodesHandler(std::map<long long int, NIOSMNode*>& toFill, std::set<NIOSMNode*,
297  CompareNodes>& uniqueNodes,
298  const OptionsCont& cont);
299 
300 
302  ~NodesHandler() override;
303 
304 
305  protected:
307 
308 
316  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
317 
318 
325  void myEndElement(int element) override;
327 
328 
329  private:
330 
332  std::map<long long int, NIOSMNode*>& myToFill;
333 
335  long long int myLastNodeID;
336 
339 
342 
344  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
345 
347  const bool myImportElevation;
348 
351 
352 
353  private:
355  NodesHandler(const NodesHandler& s);
356 
359 
360  };
361 
362 
367  class EdgesHandler : public SUMOSAXHandler {
368  public:
374  EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
375  std::map<long long int, Edge*>& toFill, std::map<long long int, Edge*>& platformShapes);
376 
377 
379  ~EdgesHandler() override;
380 
381 
382  protected:
384 
385 
393  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
394 
395 
402  void myEndElement(int element) override;
404 
405 
406  private:
408  const std::map<long long int, NIOSMNode*>& myOSMNodes;
409 
411  std::map<long long int, Edge*>& myEdgeMap;
412 
414  std::map<long long int, Edge*>& myPlatformShapesMap;
415 
418 
420  std::vector<int> myParentElements;
421 
423  std::map<std::string, double> mySpeedMap;
424 
425  private:
427  EdgesHandler(const EdgesHandler& s);
428 
431 
432  };
433 
440  public:
446  RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
447  const std::map<long long int, Edge*>& osmEdges, NBPTStopCont* nbptStopCont,
448  const std::map<long long int, Edge*>& platfromShapes, NBPTLineCont* nbptLineCont,
449  const OptionsCont& oc);
450 
451 
453  ~RelationHandler() override;
454 
455 
456  protected:
458 
459 
467  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
468 
469 
476  void myEndElement(int element) override;
478 
479 
480  private:
482  const std::map<long long int, NIOSMNode*>& myOSMNodes;
483 
485  const std::map<long long int, Edge*>& myOSMEdges;
486 
488  const std::map<long long int, Edge*>& myPlatformShapes;
489 
492 
495 
497  long long int myCurrentRelation;
498 
500  std::vector<int> myParentElements;
501 
504 
506  long long int myFromWay;
507 
509  long long int myToWay;
510 
512  long long int myViaNode;
513  long long int myViaWay;
514 
515 
518 
528  RESTRICTION_UNKNOWN
529  };
531 
533  void resetValues();
534 
536  bool checkEdgeRef(long long int ref) const;
537 
539  bool applyRestriction() const;
540 
542  NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
543 
544  private:
547 
550 
552  std::vector<long long int> myStops;
553 
554 
555  struct NIIPTPlatform {
556  long long int ref;
557  bool isWay;
558  };
559 
561  std::vector<NIIPTPlatform> myPlatforms;
562 
564  std::vector<long long int> myWays;
565 
568 
570  bool myIsRoute;
571 
573  std::string myPTRouteType;
574 
576  std::string myName;
577 
579  std::string myRef;
580  };
581 
582 };
583 
584 
585 #endif
586 
587 /****************************************************************************/
588 
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
An internal definition of a loaded edge.
const bool myImportElevation
whether elevation data should be imported
const std::map< long long int, Edge * > & myOSMEdges
The previously parsed edges.
std::map< long long int, Edge * > & myPlatformShapesMap
A map of built edges.
An internal representation of an OSM-node.
const long long int id
The edge&#39;s id.
std::string streetName
The edge&#39;s street name.
NBPTLineCont * myNBPTLineCont
PT Line container to be filled.
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
const long long int id
The node&#39;s id.
WayType myBuswayType
Information about the kind of busway along this road.
long long int myFromWay
the origination way for the current restriction
vehicle is a not electrified rail
A container for traffic light definitions and built programs.
std::map< NBNode *, std::pair< double, double > > getNeighboringNodes(NBNode *node, double maxDist, const std::set< NBNode *> &knownElevation)
collect neighboring nodes with their road distance and maximum between-speed. Search does not continu...
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
The representation of a single edge during network building.
Definition: NBEdge.h:70
vehicle is a light rail
long long int myCurrentRelation
The currently parsed relation.
NIOSMNode(long long int _id, double _lon, double _lat)
std::vector< NIIPTPlatform > myPlatforms
bus stop platforms
std::vector< long long int > myStops
bus stop references
SAX-handler base for SUMO-files.
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
RestrictionType
whether the only allowed or the only forbidden connection is defined
std::set< NIOSMNode *, CompareNodes > & myUniqueNodes
the set of unique nodes (used for duplicate detection/substitution)
NBNode * node
the NBNode that was instantiated
std::vector< long long int > myWays
ways in pt line references
const OptionsCont & myOptionsCont
the options cont
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given OSM file.
Functor which compares two Edges.
WayType myCyclewayType
Information about the kind of cycleway along this road.
int myNoLanesForward
number of lanes in forward direction or 0 if unknown, negative if backwards lanes are meant ...
const std::map< long long int, Edge * > & myPlatformShapes
The previously parsed platform shapes.
void load(const OptionsCont &oc, NBNetBuilder &nb)
A class which extracts OSM-edges from a parsed OSM-file.
int insertEdge(Edge *e, int index, NBNode *from, NBNode *to, const std::vector< long long int > &passed, NBNetBuilder &nb)
Builds an NBEdge.
double ele
The elevation of this node.
std::vector< int > myParentElements
The element stack.
bool ptStopPosition
Whether this is a public transport stop position.
Encapsulated SAX-Attributes.
bool operator()(const NIOSMNode *n1, const NIOSMNode *n2) const
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
NIOSMNode & operator=(const NIOSMNode &s)=delete
invalidated assignment operator
int myParkingType
Information about road-side parking.
long long int myLastNodeID
ID of the currently parsed node, for reporting mainly.
std::map< long long int, NIOSMNode * > & myToFill
The nodes container to fill.
bool myIsRestriction
whether the currently parsed relation is a restriction
An upper class for objects with additional parameters.
Definition: Parameterised.h:50
bool railwayCrossing
Whether this is a railway crossing.
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
bool myIsInValidNodeTag
Hierarchy helper for parsing a node&#39;s tags.
std::map< long long int, Edge * > myEdges
the map from OSM way ids to edge objects
const double lat
The latitude the node is located at.
int myNoLanes
number of lanes, or -1 if unknown
vehicle is a bus
bool tlsControlled
Whether this is a tls controlled junction.
std::map< std::string, std::string > myKnownCompoundTypes
The compound types that have already been mapped to other known types.
std::map< long long int, Edge * > & myEdgeMap
A map of built edges.
bool myCurrentIsPlatform
Information whether this is a pt platform.
long long int myToWay
the destination way for the current restriction
bool myIsRoute
indicates whether current relation is a route
int myLayer
Information about the relative z-ordering of ways.
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
std::string myPTRouteType
indicates whether current relation is a pt route
static const std::string compoundTypeSeparator
The separator within newly created compound type names.
A storage for options typed value containers)
Definition: OptionsCont.h:98
long long int myViaNode
the via node/way for the current restriction
void reconstructLayerElevation(double layerElevation, NBNetBuilder &nb)
reconstruct elevation from layer info
std::string name
The name of the node.
A class which extracts OSM-nodes from a parsed OSM-file.
Represents a single node (junction) during network building.
Definition: NBNode.h:74
NBNode * insertNodeChecking(long long int id, NBNodeCont &nc, NBTrafficLightLogicCont &tlsc)
Builds an NBNode.
int myHierarchyLevel
The current hierarchy level.
std::string myHighWayType
The type, stored in "highway" key.
const double lon
The longitude the node is located at.
Importer for networks stored in OpenStreetMap format.
bool myIsStopArea
indicates whether current relation is a pt stop area
static const long long int INVALID_ID
bool myCurrentIsRoad
Information whether this is a road.
Edge * myCurrentEdge
The currently built edge.
std::map< long long int, Edge * > myPlatformShapes
the map from OSM way ids to platform shapes
std::set< std::string > myUnusableTypes
The compounds types that do not contain known types.
SVCPermissions permissions
type of pt stop
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:66
double ptStopLength
The length of the pt stop.
std::map< long long int, NIOSMNode * > myOSMNodes
the map from OSM node ids to actual nodes
std::vector< int > myParentElements
The element stack.
Functor which compares two NIOSMNodes according to their coordinates.
std::set< NIOSMNode *, CompareNodes > myUniqueNodes
the set of unique nodes used in NodesHandler, used when freeing memory
static const double MAXSPEED_UNGIVEN
const OptionsCont & myOptionsCont
the options
A class which extracts relevant relation information from a parsed OSM-file.
std::string myIsOneWay
Information whether this is an one-way road.
std::map< std::string, double > mySpeedMap
A map of non-numeric speed descriptions to their numeric values.
A storage for available types of edges.
Definition: NBTypeCont.h:61
NBPTStopCont * myNBPTStopCont
The previously filled pt stop container.