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.dev/sumo
3 // Copyright (C) 2001-2024 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 /****************************************************************************/
22 // Importer for networks stored in OpenStreetMap format
23 /****************************************************************************/
24 #pragma once
25 #include <config.h>
26 
27 #include <string>
28 #include <map>
32 #include <netbuild/NBPTPlatform.h>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class NBEdge;
39 class NBEdgeCont;
40 class NBNetBuilder;
41 class NBNode;
42 class NBNodeCont;
44 class NBTypeCont;
45 class OptionsCont;
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
57 public:
69  static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
70 
71 protected:
72 
76  enum WayType {
77  WAY_NONE = 0,
81  WAY_UNKNOWN = 4
82  };
83 
86  struct NIOSMNode : public Parameterised {
87  NIOSMNode(long long int _id, double _lon, double _lat)
88  :
89  id(_id), lon(_lon), lat(_lat), ele(0.),
90  tlsControlled(false),
91  pedestrianCrossing(false),
92  railwayCrossing(false),
93  railwaySignal(false),
94  railwayBufferStop(false),
95  ptStopPosition(false), ptStopLength(0), name(""),
97  positionMeters(std::numeric_limits<double>::max()),
99  node(nullptr) { }
100 
102  const long long int id;
104  const double lon;
106  const double lat;
108  double ele;
122  double ptStopLength;
124  std::string name;
128  std::string position;
135 
136  private:
138  NIOSMNode& operator=(const NIOSMNode& s) = delete;
139 
140 
141  };
142 
143 public:
145  static SUMOVehicleClass interpretTransportType(const std::string& type, NIOSMNode* toSet = nullptr);
146 
147 protected:
148 
149 
150  enum ParkingType {
158  PARKING_DIAGONAL = 32
159  };
160 
161  enum ChangeType {
165  CHANGE_NO = 3
166  };
167 
170  class Edge : public Parameterised {
171  public:
172  explicit Edge(long long int _id) :
173  id(_id), myNoLanes(-1), myNoLanesForward(0),
176  myExtraAllowed(0),
178  myCyclewayType(WAY_UNKNOWN), // building of extra lane depends on bikelaneWidth of loaded typemap
179  myBuswayType(WAY_NONE), // buslanes are always built when declared
180  mySidewalkType(WAY_UNKNOWN), // building of extra lanes depends on sidewalkWidth of loaded typemap
181  myRailDirection(WAY_UNKNOWN), // store direction(s) of railway usage
182  myParkingType(PARKING_NONE), // parking areas exported optionally
185  myLayer(0), // layer is non-zero only in conflict areas
186  myCurrentIsRoad(false),
187  myAmInRoundabout(false),
188  myWidth(-1)
189  { }
190 
191  virtual ~Edge() {}
192 
194  const long long int id;
196  std::string streetName;
198  std::string ref;
204  double myMaxSpeed;
212  std::string myHighWayType;
214  std::string myIsOneWay;
230  std::vector<bool> myDesignatedLaneForward;
232  std::vector<bool> myDesignatedLaneBackward;
234  std::vector<SVCPermissions> myAllowedLaneForward;
236  std::vector<SVCPermissions> myAllowedLaneBackward;
238  std::vector<SVCPermissions> myDisallowedLaneForward;
240  std::vector<SVCPermissions> myDisallowedLaneBackward;
242  int myLayer;
244  std::vector<long long int> myCurrentNodes;
250  std::map<std::string, std::string> myExtraTags;
252  std::vector<int> myTurnSignsForward;
253  std::vector<int> myTurnSignsBackward;
255  std::vector<double> myWidthLanesForward;
256  std::vector<double> myWidthLanesBackward;
257  double myWidth;
258 
259  private:
261  Edge& operator=(const Edge& s) = delete;
262  };
263 
264 
266 
268 
269  void load(const OptionsCont& oc, NBNetBuilder& nb);
270 
271 private:
275  class CompareNodes {
276  public:
277  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
278  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
279  }
280  };
281 
282 
284  static const std::string compoundTypeSeparator;
285 
286  class CompareEdges;
287 
291  std::map<long long int, NIOSMNode*> myOSMNodes;
292 
294  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
295 
296 
298  std::map<long long int, Edge*> myEdges;
299 
301  std::map<long long int, Edge*> myPlatformShapes;
302 
304  std::set<std::string> myUnusableTypes;
305 
307  std::map<std::string, std::string> myKnownCompoundTypes;
308 
311 
314 
317 
320 
323 
325  static bool myAllAttributes;
326 
328  static std::set<std::string> myExtraAttributes;
329 
344  NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
345 
346 
361  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
362  const std::vector<long long int>& passed, NBNetBuilder& nb,
363  const NBNode* first, const NBNode* last);
364 
366  void reconstructLayerElevation(double layerElevation, NBNetBuilder& nb);
367 
369  std::map<NBNode*, std::pair<double, double> >
370  getNeighboringNodes(NBNode* node, double maxDist, const std::set<NBNode*>& knownElevation);
371 
373  std::string usableType(const std::string& type, const std::string& id, NBTypeCont& tc);
374 
376  void extendRailwayDistances(Edge* e, NBTypeCont& tc);
377 
379  static double interpretDistance(NIOSMNode* node);
380 
381 protected:
382  static const double MAXSPEED_UNGIVEN;
383  static const long long int INVALID_ID;
384 
385  static void applyChangeProhibition(NBEdge* e, int changeProhibition);
396  void applyLaneUse(NBEdge* e, NIImporter_OpenStreetMap::Edge* nie, const bool forward);
397 
398  static void mergeTurnSigns(std::vector<int>& signs, std::vector<int> signs2);
399  void applyTurnSigns(NBEdge* e, const std::vector<int>& turnSigns);
400 
405  class NodesHandler : public SUMOSAXHandler {
406  public:
412  NodesHandler(std::map<long long int, NIOSMNode*>& toFill, std::set<NIOSMNode*,
413  CompareNodes>& uniqueNodes,
414  const OptionsCont& cont);
415 
416 
418  ~NodesHandler() override;
419 
420  int getDuplicateNodes() const {
421  return myDuplicateNodes;
422  }
423 
424  void resetHierarchy() {
425  myHierarchyLevel = 0;
426  }
427 
428  protected:
430 
431 
439  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
440 
441 
448  void myEndElement(int element) override;
450 
451 
452  private:
454  std::map<long long int, NIOSMNode*>& myToFill;
455 
457  std::string myLastNodeID;
458 
461 
464 
466  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
467 
469  const bool myImportElevation;
470 
473 
476 
479 
480  private:
483 
486 
487  };
488 
489 
494  class EdgesHandler : public SUMOSAXHandler {
495  public:
501  EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
502  std::map<long long int, Edge*>& toFill, std::map<long long int, Edge*>& platformShapes);
503 
504 
506  ~EdgesHandler() override;
507 
508 
509  protected:
511 
512 
520  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
521 
522 
529  void myEndElement(int element) override;
531 
532  double interpretSpeed(const std::string& key, std::string value);
533 
534  int interpretChangeType(const std::string& value) const;
535 
536  void interpretLaneUse(const std::string& value, SUMOVehicleClass svc, const bool forward) const;
537 
538 
539  private:
541  const std::map<long long int, NIOSMNode*>& myOSMNodes;
542 
544  std::map<long long int, Edge*>& myEdgeMap;
545 
547  std::map<long long int, Edge*>& myPlatformShapesMap;
548 
550  Edge* myCurrentEdge = nullptr;
551 
553  std::map<std::string, double> mySpeedMap;
554 
555  private:
558 
561 
562  };
563 
570  public:
576  RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
577  const std::map<long long int, Edge*>& osmEdges, NBPTStopCont* nbptStopCont,
578  const std::map<long long int, Edge*>& platfromShapes, NBPTLineCont* nbptLineCont,
579  const OptionsCont& oc);
580 
581 
583  ~RelationHandler() override;
584 
585  protected:
587 
588 
596  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
597 
598 
605  void myEndElement(int element) override;
607 
608 
609  private:
611  const std::map<long long int, NIOSMNode*>& myOSMNodes;
612 
614  const std::map<long long int, Edge*>& myOSMEdges;
615 
617  const std::map<long long int, Edge*>& myPlatformShapes;
618 
621 
624 
626  long long int myCurrentRelation;
627 
630 
633 
635  long long int myFromWay;
636 
638  long long int myToWay;
639 
641  long long int myViaNode;
642  long long int myViaWay;
643 
644 
647 
651  enum class RestrictionType {
653  ONLY,
655  NO,
657  UNKNOWN
658  };
660 
662  void resetValues();
663 
665  bool checkEdgeRef(long long int ref) const;
666 
668  bool applyRestriction() const;
669 
671  NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
672 
673  private:
676 
679 
681  std::vector<long long int> myStops;
682 
684  std::set<long long int> myPlatformStops;
685 
686 
687  struct NIIPTPlatform {
688  long long int ref;
689  bool isWay;
690  };
691 
693  std::vector<NIIPTPlatform> myPlatforms;
694 
696  std::vector<long long int> myWays;
697 
700 
702  bool myIsRoute;
703 
705  std::string myPTRouteType;
706 
709 
711  std::string myName;
712 
714  std::string myRef;
715 
718 
720  std::string myNightService;
721 
723  std::map<long long int, long long int > myStopAreas;
724 
725  };
726 
727 };
std::vector< std::string > StringVector
Definition of a vector of strings.
Definition: Option.h:42
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:59
The representation of a single edge during network building.
Definition: NBEdge.h:92
Instance responsible for building networks.
Definition: NBNetBuilder.h:107
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:57
Represents a single node (junction) during network building.
Definition: NBNode.h:66
Container for public transport stops during the net building process.
Definition: NBPTStopCont.h:44
A container for traffic light definitions and built programs.
A storage for available edgeTypes of edges.
Definition: NBTypeCont.h:52
Functor which compares two NIOSMNodes according to their coordinates.
bool operator()(const NIOSMNode *n1, const NIOSMNode *n2) const
An internal definition of a loaded edge.
std::vector< SVCPermissions > myDisallowedLaneBackward
(optional) information about additional disallowed SVCs on backward lane(s)
std::map< std::string, std::string > myExtraTags
Additionally tagged information.
std::vector< double > myWidthLanesForward
Information on lane width.
WayType mySidewalkType
Information about the kind of sidwalk along this road.
std::vector< SVCPermissions > myDisallowedLaneForward
(optional) information about additional disallowed SVCs on forward lane(s)
bool myCurrentIsRoad
Information whether this is a road.
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
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
std::string ref
The edge's track name.
std::vector< SVCPermissions > myAllowedLaneForward
(optional) information about additional allowed SVCs on forward lane(s)
std::string myHighWayType
The type, stored in "highway" key.
const long long int id
The edge's id.
bool myAmInRoundabout
Information whether this road is part of a roundabout.
int myLayer
Information about the relative z-ordering of ways.
Edge & operator=(const Edge &s)=delete
invalidated assignment operator
std::vector< bool > myDesignatedLaneBackward
(optional) information about whether the backward lanes are designated to some SVCs
SVCPermissions myExtraDisallowed
Extra permissions prohibited from tags instead of highway type.
std::vector< SVCPermissions > myAllowedLaneBackward
(optional) information about additional allowed SVCs on backward lane(s)
int myNoLanes
number of lanes, or -1 if unknown
std::vector< int > myTurnSignsForward
turning direction (arrows printed on the road)
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
int myParkingType
Information about road-side parking.
double myMaxSpeedBackward
maximum speed in km/h, or MAXSPEED_UNGIVEN
WayType myBuswayType
Information about the kind of busway along this road.
int myChangeForward
Information about change prohibitions (forward direction.
SVCPermissions myExtraAllowed
Extra permissions added from tags instead of highway type.
int myChangeBackward
Information about change prohibitions (backward direction.
std::string streetName
The edge's street name.
WayType myRailDirection
Information about the direction(s) of railway usage.
std::vector< bool > myDesignatedLaneForward
(optional) information about whether the forward lanes are designated to some SVCs
std::string myIsOneWay
Information whether this is an one-way road.
A class which extracts OSM-edges from a parsed OSM-file.
Edge * myCurrentEdge
The currently built edge.
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
void interpretLaneUse(const std::string &value, SUMOVehicleClass svc, const bool forward) const
EdgesHandler(const std::map< long long int, NIOSMNode * > &osmNodes, std::map< long long int, Edge * > &toFill, std::map< long long int, Edge * > &platformShapes)
Constructor.
int interpretChangeType(const std::string &value) const
void myEndElement(int element) override
Called when a closing tag occurs.
EdgesHandler & operator=(const EdgesHandler &s)
invalidated assignment operator
double interpretSpeed(const std::string &key, std::string value)
EdgesHandler(const EdgesHandler &s)
invalidated copy constructor
std::map< long long int, Edge * > & myEdgeMap
A map of built edges.
std::map< long long int, Edge * > & myPlatformShapesMap
A map of built edges.
std::map< std::string, double > mySpeedMap
A map of non-numeric speed descriptions to their numeric values.
void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
A class which extracts OSM-nodes from a parsed OSM-file.
int myHierarchyLevel
The current hierarchy level.
const bool myImportElevation
whether elevation data should be imported
std::string myLastNodeID
id of the currently parsed node
NodesHandler(const NodesHandler &s)
invalidated copy constructor
std::set< NIOSMNode *, CompareNodes > & myUniqueNodes
the set of unique nodes (used for duplicate detection/substitution)
void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
std::map< long long int, NIOSMNode * > & myToFill
The nodes container to fill.
NodesHandler(std::map< long long int, NIOSMNode * > &toFill, std::set< NIOSMNode *, CompareNodes > &uniqueNodes, const OptionsCont &cont)
Constructor.
const OptionsCont & myOptionsCont
the options
void myEndElement(int element) override
Called when a closing tag occurs.
NIOSMNode * myCurrentNode
the currently parsed node
StringVector myRailSignalRules
custom requirements for rail signal tagging
NodesHandler & operator=(const NodesHandler &s)
invalidated assignment operator
A class which extracts relevant relation information from a parsed OSM-file.
void myEndElement(int element) override
Called when a closing tag occurs.
const std::map< long long int, Edge * > & myPlatformShapes
The previously parsed platform shapes.
RelationHandler & operator=(const RelationHandler &s)
invalidated assignment operator
long long int myViaNode
the via node/way for the current restriction
bool myIsRestriction
whether the currently parsed relation is a restriction
std::vector< long long int > myWays
ways in pt line references
SVCPermissions myRestrictionException
exceptions to the restriction currenlty being parsed
long long int myCurrentRelation
The currently parsed relation.
std::set< long long int > myPlatformStops
myStops which are actually platforms (in case there is no stop_position)
void resetValues()
reset members to their defaults for parsing a new relation
void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
const OptionsCont & myOptionsCont
the options cont
RestrictionType
whether the only allowed or the only forbidden connection is defined
@ ONLY
The only valid connection is declared.
@ NO
The only invalid connection is declared.
std::string myNightService
night service information of the pt line
std::string myPTRouteType
indicates whether current relation is a pt route
std::vector< long long int > myStops
bus stop references
NBPTLineCont * myNBPTLineCont
PT Line container to be filled.
std::vector< NIIPTPlatform > myPlatforms
bus stop platforms
bool myIsStopArea
indicates whether current relation is a pt stop area
bool myIsRoute
indicates whether current relation is a route
RelationHandler(const std::map< long long int, NIOSMNode * > &osmNodes, const std::map< long long int, Edge * > &osmEdges, NBPTStopCont *nbptStopCont, const std::map< long long int, Edge * > &platfromShapes, NBPTLineCont *nbptLineCont, const OptionsCont &oc)
Constructor.
int myInterval
service interval of the pt line in minutes
RelationHandler(const RelationHandler &s)
invalidated copy constructor
std::map< long long int, long long int > myStopAreas
the map from stop area member to stop_area id
NBPTStopCont * myNBPTStopCont
The previously filled pt stop container.
bool checkEdgeRef(long long int ref) const
check whether a referenced way has a corresponding edge
long long int myFromWay
the origination way for the current restriction
long long int myToWay
the destination way for the current restriction
bool applyRestriction() const
try to apply the parsed restriction and return whether successful
NBEdge * findEdgeRef(long long int wayRef, const std::vector< NBEdge * > &candidates) const
try to find the way segment among candidates
const std::map< long long int, Edge * > & myOSMEdges
The previously parsed edges.
Importer for networks stored in OpenStreetMap format.
int insertEdge(Edge *e, int index, NBNode *from, NBNode *to, const std::vector< long long int > &passed, NBNetBuilder &nb, const NBNode *first, const NBNode *last)
Builds an NBEdge.
std::map< long long int, Edge * > myEdges
the map from OSM way ids to edge objects
bool myImportCrossings
import crossings
std::map< long long int, NIOSMNode * > myOSMNodes
the map from OSM node ids to actual nodes
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given OSM file.
static const long long int INVALID_ID
void applyLaneUse(NBEdge *e, NIImporter_OpenStreetMap::Edge *nie, const bool forward)
Applies lane use information from nie to e.
static const double MAXSPEED_UNGIVEN
std::map< long long int, Edge * > myPlatformShapes
the map from OSM way ids to platform shapes
void load(const OptionsCont &oc, NBNetBuilder &nb)
void applyTurnSigns(NBEdge *e, const std::vector< int > &turnSigns)
bool myImportSidewalks
import sidewalks
std::set< NIOSMNode *, CompareNodes > myUniqueNodes
the set of unique nodes used in NodesHandler, used when freeing memory
static bool myAllAttributes
whether additional way and node attributes shall be imported
void reconstructLayerElevation(double layerElevation, NBNetBuilder &nb)
reconstruct elevation from layer info
static SUMOVehicleClass interpretTransportType(const std::string &type, NIOSMNode *toSet=nullptr)
translate osm transport designations into sumo vehicle class
bool myImportLaneAccess
import lane specific access restrictions
bool myImportTurnSigns
import turning signals (turn:lanes) to guide connection building
std::map< std::string, std::string > myKnownCompoundTypes
The compound types that have already been mapped to other known types.
static const std::string compoundTypeSeparator
The separator within newly created compound type names.
std::set< std::string > myUnusableTypes
The compounds types that do not contain known types.
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...
static std::set< std::string > myExtraAttributes
extra attributes to import
bool myImportBikeAccess
import bike path specific permissions and directions
static double interpretDistance(NIOSMNode *node)
read distance value from node and return value in m
NBNode * insertNodeChecking(long long int id, NBNodeCont &nc, NBTrafficLightLogicCont &tlsc)
Builds an NBNode.
static void mergeTurnSigns(std::vector< int > &signs, std::vector< int > signs2)
void extendRailwayDistances(Edge *e, NBTypeCont &tc)
extend kilometrage data for all nodes along railway
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
static void applyChangeProhibition(NBEdge *e, int changeProhibition)
A storage for options typed value containers)
Definition: OptionsCont.h:89
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
Encapsulated SAX-Attributes.
SAX-handler base for SUMO-files.
Definition: json.hpp:4471
An internal representation of an OSM-node.
SVCPermissions permissions
type of pt stop
NBNode * node
the NBNode that was instantiated
double positionMeters
position converted to m (using highest precision available)
std::string position
kilometrage/mileage
const long long int id
The node's id.
bool pedestrianCrossing
Whether this is a pedestrian crossing.
NIOSMNode & operator=(const NIOSMNode &s)=delete
invalidated assignment operator
bool tlsControlled
Whether this is a tls controlled junction.
double ptStopLength
The length of the pt stop.
NIOSMNode(long long int _id, double _lon, double _lat)
bool ptStopPosition
Whether this is a public transport stop position.
std::string name
The name of the node.
bool railwayCrossing
Whether this is a railway crossing.
double ele
The elevation of this node.
bool railwayBufferStop
Whether this is a railway buffer stop.
const double lon
The longitude the node is located at.
const double lat
The latitude the node is located at.
bool railwaySignal
Whether this is a railway (main) signal.
WayType myRailDirection
Information about the direction(s) of railway usage.