Eclipse 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-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 /****************************************************************************/
19 // Importer for networks stored in OpenStreetMap format
20 /****************************************************************************/
21 #ifndef NIImporter_OpenStreetMap_h
22 #define NIImporter_OpenStreetMap_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include <string>
31 #include <map>
35 #include <netbuild/NBPTPlatform.h>
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class NBEdge;
42 class NBEdgeCont;
43 class NBNetBuilder;
44 class NBNode;
45 class NBNodeCont;
47 class NBTypeCont;
48 class OptionsCont;
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
60 public:
72  static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
73 
74 
75 protected:
78  struct NIOSMNode {
79  NIOSMNode(long long int _id, double _lon, double _lat)
80  :
81  id(_id), lon(_lon), lat(_lat), ele(0),
82  tlsControlled(false),
83  railwayCrossing(false),
84  railwaySignal(false),
85  railwayBufferStop(false),
86  ptStopPosition(false), ptStopLength(0), name(""),
88  positionMeters(std::numeric_limits<double>::max()),
89  node(0) { }
90 
92  const long long int id;
94  const double lon;
96  const double lat;
98  double ele;
110  double ptStopLength;
112  std::string name;
116  std::string position;
121 
122  private:
124  NIOSMNode& operator=(const NIOSMNode& s) = delete;
125 
126 
127  };
128 
132  enum WayType {
133  WAY_NONE = 0,
138  };
139 
140  enum ParkingType {
149  };
150 
151 
154  struct Edge : public Parameterised {
155 
156  explicit Edge(long long int _id)
157  :
158  id(_id), myNoLanes(-1), myNoLanesForward(0), myMaxSpeed(MAXSPEED_UNGIVEN),
159  myCyclewayType(WAY_UNKNOWN), // building of extra lane depends on bikelaneWidth of loaded typemap
160  myBuswayType(WAY_NONE), // buslanes are always built when declared
161  mySidewalkType(WAY_UNKNOWN), // building of extra lanes depends on sidewalkWidth of loaded typemap
162  myRailDirection(WAY_UNKNOWN), // store direction(s) of railway usage
163  myParkingType(PARKING_NONE), // parking areas exported optionally
164  myLayer(0), // layer is non-zero only in conflict areas
165  myCurrentIsRoad(false),
166  myCurrentIsPlatform(false),
167  myCurrentIsElectrified(false)
168  { }
169 
170 
172  const long long int id;
174  std::string streetName;
176  std::string ref;
182  double myMaxSpeed;
184  std::string myHighWayType;
186  std::string myIsOneWay;
198  int myLayer;
200  std::vector<long long int> myCurrentNodes;
207 
208  private:
210  Edge& operator=(const Edge& s) = delete;
211 
212 
213  };
214 
215 
217 
219 
220  void load(const OptionsCont& oc, NBNetBuilder& nb);
221 
222 private:
226  class CompareNodes {
227  public:
228  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
229  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
230  }
231  };
232 
233 
235  static const std::string compoundTypeSeparator;
236 
238 
242  std::map<long long int, NIOSMNode*> myOSMNodes;
243 
245  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
246 
247 
249  std::map<long long int, Edge*> myEdges;
250 
252  std::map<long long int, Edge*> myPlatformShapes;
253 
255  std::set<std::string> myUnusableTypes;
256 
258  std::map<std::string, std::string> myKnownCompoundTypes;
259 
274  NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
275 
276 
289  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
290  const std::vector<long long int>& passed, NBNetBuilder& nb);
291 
293  void reconstructLayerElevation(double layerElevation, NBNetBuilder& nb);
294 
296  std::map<NBNode*, std::pair<double, double> >
297  getNeighboringNodes(NBNode* node, double maxDist, const std::set<NBNode*>& knownElevation);
298 
300  std::string usableType(const std::string& type, const std::string& id, NBTypeCont& tc);
301 
303  void extendRailwayDistances(Edge* e, NBTypeCont& tc);
304 
306  static double interpretDistance(NIOSMNode* node);
307 
308 
309 protected:
310  static const double MAXSPEED_UNGIVEN;
311  static const long long int INVALID_ID;
312 
317  friend class NodesHandler;
318  class NodesHandler : public SUMOSAXHandler {
319  public:
325  NodesHandler(std::map<long long int, NIOSMNode*>& toFill, std::set<NIOSMNode*,
326  CompareNodes>& uniqueNodes,
327  const OptionsCont& cont);
328 
329 
331  ~NodesHandler() override;
332 
333 
334  protected:
336 
337 
345  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
346 
347 
354  void myEndElement(int element) override;
356 
357 
358  private:
359 
361  std::map<long long int, NIOSMNode*>& myToFill;
362 
364  long long int myLastNodeID;
365 
368 
371 
373  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
374 
376  const bool myImportElevation;
377 
380 
381 
382  private:
384  NodesHandler(const NodesHandler& s);
385 
388 
389  };
390 
391 
396  class EdgesHandler : public SUMOSAXHandler {
397  public:
403  EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
404  std::map<long long int, Edge*>& toFill, std::map<long long int, Edge*>& platformShapes);
405 
406 
408  ~EdgesHandler() override;
409 
410 
411  protected:
413 
414 
422  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
423 
424 
431  void myEndElement(int element) override;
433 
434 
435  private:
437  const std::map<long long int, NIOSMNode*>& myOSMNodes;
438 
440  std::map<long long int, Edge*>& myEdgeMap;
441 
443  std::map<long long int, Edge*>& myPlatformShapesMap;
444 
447 
449  std::vector<int> myParentElements;
450 
452  std::map<std::string, double> mySpeedMap;
453 
456 
457  private:
459  EdgesHandler(const EdgesHandler& s);
460 
463 
464  };
465 
472  public:
478  RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
479  const std::map<long long int, Edge*>& osmEdges, NBPTStopCont* nbptStopCont,
480  const std::map<long long int, Edge*>& platfromShapes, NBPTLineCont* nbptLineCont,
481  const OptionsCont& oc);
482 
483 
485  ~RelationHandler() override;
486 
487 
488  protected:
490 
491 
499  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
500 
501 
508  void myEndElement(int element) override;
510 
511 
512  private:
514  const std::map<long long int, NIOSMNode*>& myOSMNodes;
515 
517  const std::map<long long int, Edge*>& myOSMEdges;
518 
520  const std::map<long long int, Edge*>& myPlatformShapes;
521 
524 
527 
529  long long int myCurrentRelation;
530 
532  std::vector<int> myParentElements;
533 
536 
538  long long int myFromWay;
539 
541  long long int myToWay;
542 
544  long long int myViaNode;
545  long long int myViaWay;
546 
547 
550 
560  RESTRICTION_UNKNOWN
561  };
563 
565  void resetValues();
566 
568  bool checkEdgeRef(long long int ref) const;
569 
571  bool applyRestriction() const;
572 
574  NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
575 
576  private:
579 
582 
584  std::vector<long long int> myStops;
585 
586 
587  struct NIIPTPlatform {
588  long long int ref;
589  bool isWay;
590  };
591 
593  std::vector<NIIPTPlatform> myPlatforms;
594 
596  std::vector<long long int> myWays;
597 
600 
602  bool myIsRoute;
603 
605  std::string myPTRouteType;
606 
608  std::string myName;
609 
611  std::string myRef;
612 
615 
617  std::string myNightService;
618  };
619 
620 };
621 
622 
623 #endif
624 
625 /****************************************************************************/
626 
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...
void extendRailwayDistances(Edge *e, NBTypeCont &tc)
extend kilometrage data for all nodes along railway
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:86
bool myCurrentIsElectrified
Information whether this is railway is electrified.
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
std::string usableType(const std::string &type, const std::string &id, NBTypeCont &tc)
check whether the type is known or consists of known type compounds. return empty string otherwise ...
SAX-handler base for SUMO-files.
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
bool railwaySignal
Whether this is a railway (main) signal.
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)
bool myAllAttributes
whether additional way attributes shall be added to the edge
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:61
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:43
bool railwayCrossing
Whether this is a railway crossing.
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
std::string position
kilometrage/mileage
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.
std::string ref
The edge&#39;s track name.
int myNoLanes
number of lanes, or -1 if unknown
bool railwayBufferStop
Whether this is a railway buffer stop.
vehicle is a bus
double positionMeters
position converted to m (using highest precision available)
bool tlsControlled
Whether this is a tls controlled junction.
WayType mySidewalkType
Information about the kind of sidwalk along this road.
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:110
std::string myPTRouteType
indicates whether current relation is a pt route
static const std::string compoundTypeSeparator
The separator within newly created compound type names.
static double interpretDistance(NIOSMNode *node)
read distance value from node and return value in m
A storage for options typed value containers)
Definition: OptionsCont.h:90
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.
int myInterval
service interval of the pt line in minutes
Represents a single node (junction) during network building.
Definition: NBNode.h:68
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.
std::string myNightService
night service information of the pt line
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:60
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.
WayType myRailDirection
Information about the direction(s) of railway usage.
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:55
NBPTStopCont * myNBPTStopCont
The previously filled pt stop container.