Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 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 : /****************************************************************************/
14 : /// @file NIImporter_OpenStreetMap.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @author Walter Bamberger
19 : /// @author Gregor Laemmel
20 : /// @date Mon, 14.04.2008
21 : ///
22 : // Importer for networks stored in OpenStreetMap format
23 : /****************************************************************************/
24 : #pragma once
25 : #include <config.h>
26 :
27 : #include <string>
28 : #include <map>
29 : #include <utils/xml/SUMOSAXHandler.h>
30 : #include <utils/common/UtilExceptions.h>
31 : #include <utils/common/Parameterised.h>
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;
43 : class NBTrafficLightLogicCont;
44 : class NBTypeCont;
45 : class OptionsCont;
46 :
47 :
48 : // ===========================================================================
49 : // class definitions
50 : // ===========================================================================
51 : /**
52 : * @class NIImporter_OpenStreetMap
53 : * @brief Importer for networks stored in OpenStreetMap format
54 : *
55 : */
56 : class NIImporter_OpenStreetMap {
57 : public:
58 : /** @brief Loads content of the optionally given OSM file
59 : *
60 : * If the option "osm-files" is set, the file(s) stored therein is read and
61 : * the network definition stored therein is stored within the given network
62 : * builder.
63 : *
64 : * If the option "osm-files" is not set, this method simply returns.
65 : *
66 : * @param[in] oc The options to use
67 : * @param[in, out] nb The network builder to fill
68 : */
69 : static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
70 :
71 : protected:
72 :
73 : /** @enum WayType
74 : * @brief details on the kind of sidewalk, cycleway, busway along this road
75 : */
76 : enum WayType {
77 : WAY_NONE = 0,
78 : // technically possible
79 : WAY_FORWARD = 1,
80 : WAY_BACKWARD = 2,
81 : WAY_BOTH = WAY_FORWARD | WAY_BACKWARD,
82 : WAY_UNKNOWN = 4,
83 : // recommended for routing
84 : WAY_PREFER_FORWARD = 8,
85 : WAY_PREFER_BACKWARD = 16,
86 : };
87 :
88 : /** @brief An internal representation of an OSM-node
89 : */
90 : struct NIOSMNode : public Parameterised {
91 324094 : NIOSMNode(long long int _id, double _lon, double _lat)
92 324094 : :
93 324094 : id(_id), lon(_lon), lat(_lat), ele(0.),
94 324094 : tlsControlled(false),
95 324094 : pedestrianCrossing(false),
96 324094 : railwayCrossing(false),
97 324094 : railwaySignal(false),
98 324094 : railwayBufferStop(false),
99 648188 : ptStopPosition(false), ptStopLength(0), name(""),
100 324094 : permissions(SVC_IGNORING),
101 324094 : positionMeters(std::numeric_limits<double>::max()),
102 324094 : myRailDirection(WAY_UNKNOWN),
103 324094 : node(nullptr) { }
104 :
105 : /// @brief The node's id
106 : const long long int id;
107 : /// @brief The longitude the node is located at
108 : const double lon;
109 : /// @brief The latitude the node is located at
110 : const double lat;
111 : /// @brief The elevation of this node
112 : double ele;
113 : /// @brief Whether this is a tls controlled junction
114 : bool tlsControlled;
115 : /// @brief Whether this is a pedestrian crossing
116 : bool pedestrianCrossing;
117 : /// @brief Whether this is a railway crossing
118 : bool railwayCrossing;
119 : /// @brief Whether this is a railway (main) signal
120 : bool railwaySignal;
121 : /// @brief Whether this is a railway buffer stop
122 : bool railwayBufferStop;
123 : /// @brief Whether this is a public transport stop position
124 : bool ptStopPosition;
125 : /// @brief The length of the pt stop
126 : double ptStopLength;
127 : /// @brief The name of the node
128 : std::string name;
129 : /// @brief type of pt stop
130 : SVCPermissions permissions;
131 : /// @brief kilometrage/mileage
132 : std::string position;
133 : /// @brief position converted to m (using highest precision available)
134 : double positionMeters;
135 : /// @brief Information about the direction(s) of railway usage
136 : WayType myRailDirection;
137 : /// @brief the NBNode that was instantiated
138 : NBNode* node;
139 :
140 : private:
141 : /// invalidated assignment operator
142 : NIOSMNode& operator=(const NIOSMNode& s) = delete;
143 :
144 :
145 : };
146 :
147 : public:
148 : /// @brief translate osm transport designations into sumo vehicle class
149 : static SUMOVehicleClass interpretTransportType(const std::string& type, NIOSMNode* toSet = nullptr);
150 :
151 : protected:
152 :
153 :
154 : enum ParkingType {
155 : PARKING_NONE = 0,
156 : PARKING_LEFT = 1,
157 : PARKING_RIGHT = 2,
158 : PARKING_BOTH = WAY_FORWARD | WAY_BACKWARD,
159 : PARKING_UNKNOWN = 4,
160 : PARKING_FORBIDDEN = 8,
161 : PARKING_PERPENDICULAR = 16,
162 : PARKING_DIAGONAL = 32
163 : };
164 :
165 : enum ChangeType {
166 : CHANGE_YES = 0,
167 : CHANGE_NO_LEFT = 1,
168 : CHANGE_NO_RIGHT = 2,
169 : CHANGE_NO = 3
170 : };
171 :
172 : enum class PlacementType {
173 : NONE = 0,
174 : LEFT_OF = 1,
175 : RIGHT_OF = 2,
176 : MIDDLE_OF = 3
177 : };
178 :
179 : /** @brief An internal definition of a loaded edge
180 : */
181 : class Edge : public Parameterised {
182 : public:
183 43850 : explicit Edge(long long int _id) :
184 43850 : id(_id), myNoLanes(-1), myNoLanesForward(0),
185 43850 : myMaxSpeed(MAXSPEED_UNGIVEN),
186 43850 : myMaxSpeedBackward(MAXSPEED_UNGIVEN),
187 43850 : myExtraAllowed(0),
188 43850 : myExtraDisallowed(0),
189 43850 : myCyclewayType(WAY_UNKNOWN), // building of extra lane depends on bikelaneWidth of loaded typemap
190 43850 : myBuswayType(WAY_NONE), // buslanes are always built when declared
191 43850 : mySidewalkType(WAY_UNKNOWN), // building of extra lanes depends on sidewalkWidth of loaded typemap
192 43850 : myRailDirection(WAY_UNKNOWN), // store direction(s) of railway usage
193 43850 : myParkingType(PARKING_NONE), // parking areas exported optionally
194 43850 : myChangeForward(CHANGE_YES),
195 43850 : myChangeBackward(CHANGE_YES),
196 43850 : myLayer(0), // layer is non-zero only in conflict areas
197 43850 : myCurrentIsRoad(false),
198 43850 : myAmInRoundabout(false),
199 43850 : myPlacement(PlacementType::NONE),
200 43850 : myPlacementLane(-1),
201 43850 : myWidth(-1)
202 43850 : { }
203 :
204 175400 : virtual ~Edge() {}
205 :
206 : /// @brief The edge's id
207 : const long long int id;
208 : /// @brief The edge's street name
209 : std::string streetName;
210 : /// @brief The edge's track name
211 : std::string ref;
212 : /// @brief number of lanes, or -1 if unknown
213 : int myNoLanes;
214 : /// @brief number of lanes in forward direction or 0 if unknown, negative if backwards lanes are meant
215 : int myNoLanesForward;
216 : /// @brief maximum speed in km/h, or MAXSPEED_UNGIVEN
217 : double myMaxSpeed;
218 : /// @brief maximum speed in km/h, or MAXSPEED_UNGIVEN
219 : double myMaxSpeedBackward;
220 : /// @brief Extra permissions added from tags instead of highway type
221 : SVCPermissions myExtraAllowed;
222 : /// @brief Extra permissions prohibited from tags instead of highway type
223 : SVCPermissions myExtraDisallowed;
224 : /// @brief The type, stored in "highway" key
225 : std::string myHighWayType;
226 : /// @brief Information whether this is an one-way road
227 : std::string myIsOneWay;
228 : /// @brief Information about the kind of cycleway along this road
229 : WayType myCyclewayType;
230 : /// @brief Information about the kind of busway along this road
231 : WayType myBuswayType;
232 : /// @brief Information about the kind of sidwalk along this road
233 : WayType mySidewalkType;
234 : /// @brief Information about the direction(s) of railway usage
235 : int myRailDirection;
236 : /// @brief Information about road-side parking
237 : int myParkingType;
238 : /// @brief Information about change prohibitions (forward direction
239 : int myChangeForward;
240 : /// @brief Information about change prohibitions (backward direction
241 : int myChangeBackward;
242 : /// @brief (optional) information about whether the forward lanes are designated to some SVCs
243 : std::vector<bool> myDesignatedLaneForward;
244 : /// @brief (optional) information about whether the backward lanes are designated to some SVCs
245 : std::vector<bool> myDesignatedLaneBackward;
246 : /// @brief (optional) information about additional allowed SVCs on forward lane(s)
247 : std::vector<SVCPermissions> myAllowedLaneForward;
248 : /// @brief (optional) information about additional allowed SVCs on backward lane(s)
249 : std::vector<SVCPermissions> myAllowedLaneBackward;
250 : /// @brief (optional) information about additional disallowed SVCs on forward lane(s)
251 : std::vector<SVCPermissions> myDisallowedLaneForward;
252 : /// @brief (optional) information about additional disallowed SVCs on backward lane(s)
253 : std::vector<SVCPermissions> myDisallowedLaneBackward;
254 : /// @brief Information about the relative z-ordering of ways
255 : int myLayer;
256 : /// @brief The list of nodes this edge is made of
257 : std::vector<long long int> myCurrentNodes;
258 : /// @brief Information whether this is a road
259 : bool myCurrentIsRoad;
260 : /// @brief Information whether this road is part of a roundabout
261 : bool myAmInRoundabout;
262 : /// @brief Additionally tagged information
263 : std::map<std::string, std::string> myExtraTags;
264 : /// @brief turning direction (arrows printed on the road)
265 : std::vector<int> myTurnSignsForward;
266 : std::vector<int> myTurnSignsBackward;
267 : /// @brief placement of the OSM way geometry relative to lanes
268 : PlacementType myPlacement;
269 : /// @brief 1-based lane index for placement specification
270 : int myPlacementLane;
271 : /// @brief Information on lane width
272 : std::vector<double> myWidthLanesForward;
273 : std::vector<double> myWidthLanesBackward;
274 : double myWidth;
275 :
276 : private:
277 : /// invalidated assignment operator
278 : Edge& operator=(const Edge& s) = delete;
279 : };
280 :
281 :
282 : NIImporter_OpenStreetMap();
283 :
284 : ~NIImporter_OpenStreetMap();
285 :
286 : void load(const OptionsCont& oc, NBNetBuilder& nb);
287 :
288 : private:
289 : /** @brief Functor which compares two NIOSMNodes according
290 : * to their coordinates
291 : */
292 : class CompareNodes {
293 : public:
294 : bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
295 8773799 : return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
296 : }
297 : };
298 :
299 :
300 : /// @brief The separator within newly created compound type names
301 : static const std::string compoundTypeSeparator;
302 :
303 : class CompareEdges;
304 :
305 : /** @brief the map from OSM node ids to actual nodes
306 : * @note: NIOSMNodes may appear multiple times due to substition
307 : */
308 : std::map<long long int, NIOSMNode*> myOSMNodes;
309 :
310 : /// @brief the set of unique nodes used in NodesHandler, used when freeing memory
311 : std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
312 :
313 :
314 : /** @brief the map from OSM way ids to edge objects */
315 : std::map<long long int, Edge*> myEdges;
316 :
317 : /** @brief the map from OSM way ids to platform shapes */
318 : std::map<long long int, Edge*> myPlatformShapes;
319 :
320 : /// @brief The compounds types that do not contain known types
321 : std::set<std::string> myUnusableTypes;
322 :
323 : /// @brief The compound types that have already been mapped to other known types
324 : std::map<std::string, std::string> myKnownCompoundTypes;
325 :
326 : /// @brief import lane specific access restrictions
327 : bool myImportLaneAccess;
328 :
329 : /// @brief import sidewalks
330 : bool myImportSidewalks;
331 :
332 : /// @brief import sidewalks
333 : bool myOnewayDualSidewalk;
334 :
335 : /// @brief import bike path specific permissions and directions
336 : bool myImportBikeAccess;
337 :
338 : /// @brief import crossings
339 : bool myImportCrossings;
340 :
341 : /// @brief import turning signals (turn:lanes) to guide connection building
342 : bool myImportTurnSigns;
343 :
344 : /// @brief whether edges should carry information on the use of typemap defaults
345 : bool myAnnotateDefaults;
346 :
347 : /// @brief number of placement skips due to non-explicit oneway
348 : int myPlacementSkippedNonExplicitOneWay = 0;
349 :
350 : /// @brief number of placement skips due to generated opposite-direction auxiliary edges
351 : int myPlacementSkippedAuxOppositeDirection = 0;
352 :
353 : /// @brief whether additional way and node attributes shall be imported
354 : static bool myAllAttributes;
355 :
356 : /// @brief extra attributes to import
357 : static std::set<std::string> myExtraAttributes;
358 :
359 : /** @brief Builds an NBNode
360 : *
361 : * If a node with the given id is already known, nothing is done.
362 : * Otherwise, the position and other information of the node is retrieved from the
363 : * given node map, the node is built and added to the given node container.
364 : * If the node is controlled by a tls, the according tls is built and added
365 : * to the tls container.
366 : * @param[in] id The id of the node to build
367 : * @param[in] osmNodes Map of node ids to information about these
368 : * @param[in, out] nc The node container to add the built node to
369 : * @param[in, out] tlsc The traffic lights logic container to add the built tls to
370 : * @return The built/found node
371 : * @exception ProcessError If the tls could not be added to the container
372 : */
373 : NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
374 :
375 :
376 : /** @brief Builds an NBEdge
377 : *
378 : * @param[in] e The definition of the edge
379 : * @param[in] index The index of the edge (in the case it is split along her nodes)
380 : * @param[in] from The origin node of the edge
381 : * @param[in] to The destination node of the edge
382 : * @param[in] passed The list of passed nodes (geometry information)
383 : * @param[in] osmNodes Container of node definitions for getting information about nodes from
384 : * @param[in, out] The NetBuilder instance
385 : * @param[in] first The first node of the way
386 : * @param[in] last The last node of the way
387 : * @return the new index if the edge is split
388 : * @exception ProcessError If the edge could not be added to the container
389 : */
390 : int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
391 : const std::vector<long long int>& passed, NBNetBuilder& nb,
392 : const NBNode* first, const NBNode* last);
393 :
394 : /// @brief reconstruct elevation from layer info
395 : void reconstructLayerElevation(double layerElevation, NBNetBuilder& nb);
396 :
397 : /// @brief collect neighboring nodes with their road distance and maximum between-speed. Search does not continue beyond knownElevation-nodes
398 : std::map<NBNode*, std::pair<double, double> >
399 : getNeighboringNodes(NBNode* node, double maxDist, const std::set<NBNode*>& knownElevation);
400 :
401 : /// @brief check whether the type is known or consists of known type compounds. return empty string otherwise
402 : std::string usableType(const std::string& type, const std::string& id, NBTypeCont& tc);
403 :
404 : /// @brief extend kilometrage data for all nodes along railway
405 : void extendRailwayDistances(Edge* e, NBTypeCont& tc);
406 :
407 : /// @brief read distance value from node and return value in m
408 : static double interpretDistance(NIOSMNode* node);
409 :
410 : protected:
411 : static const double MAXSPEED_UNGIVEN;
412 : static const long long int INVALID_ID;
413 :
414 : static void applyChangeProhibition(NBEdge* e, int changeProhibition);
415 : /// Applies lane use information from `nie` to `e`. Uses the member values
416 : /// `myLaneAllowedForward`, `myLaneDisallowedForward` and `myLaneDesignatedForward`
417 : /// or the respective backward values to determine the ultimate lane uses.
418 : /// When a value of `e->myLaneDesignatedForward/Backward` is `true`, all permissions for the corresponding
419 : /// lane will be deleted before adding permissions from `e->myLaneAllowedForward/Backward`.
420 : /// SVCs from `e->myLaneAllowedForward/Backward` will be added to the existing permissions (for each lane).
421 : /// SVCs from `e->myLaneDisallowedForward/Backward` will be subtracted from the existing permissions.
422 : /// @brief Applies lane use information from `nie` to `e`.
423 : /// @param e The NBEdge that the new information will be written to.
424 : /// @param nie Ths Edge that the information comes from.
425 : void applyLaneUse(NBEdge* e, NIImporter_OpenStreetMap::Edge* nie, const bool forward);
426 :
427 : static void mergeTurnSigns(std::vector<int>& signs, std::vector<int> signs2);
428 : void applyTurnSigns(NBEdge* e, const std::vector<int>& turnSigns);
429 :
430 : /**
431 : * @class NodesHandler
432 : * @brief A class which extracts OSM-nodes from a parsed OSM-file
433 : */
434 : class NodesHandler : public SUMOSAXHandler {
435 : public:
436 : /** @brief Constructor
437 : * @param[in, out] toFill The nodes container to fill
438 : * @param[in, out] uniqueNodes The nodes container for ensuring uniqueness
439 : * @param[in] options The options to use
440 : */
441 : NodesHandler(std::map<long long int, NIOSMNode*>& toFill, std::set<NIOSMNode*,
442 : CompareNodes>& uniqueNodes,
443 : const OptionsCont& cont);
444 :
445 :
446 : /// @brief Destructor
447 : ~NodesHandler() override;
448 :
449 : int getDuplicateNodes() const {
450 534 : return myDuplicateNodes;
451 : }
452 :
453 : void resetHierarchy() {
454 518 : myHierarchyLevel = 0;
455 : }
456 :
457 : protected:
458 : /// @name inherited from GenericSAXHandler
459 : //@{
460 :
461 : /** @brief Called on the opening of a tag;
462 : *
463 : * @param[in] element ID of the currently opened element
464 : * @param[in] attrs Attributes within the currently opened element
465 : * @exception ProcessError If something fails
466 : * @see GenericSAXHandler::myStartElement
467 : */
468 : void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
469 :
470 :
471 : /** @brief Called when a closing tag occurs
472 : *
473 : * @param[in] element ID of the currently opened element
474 : * @exception ProcessError If something fails
475 : * @see GenericSAXHandler::myEndElement
476 : */
477 : void myEndElement(int element) override;
478 : //@}
479 :
480 :
481 : private:
482 : /// @brief The nodes container to fill
483 : std::map<long long int, NIOSMNode*>& myToFill;
484 :
485 : /// @brief id of the currently parsed node
486 : std::string myLastNodeID;
487 :
488 : /// @brief the currently parsed node
489 : NIOSMNode* myCurrentNode;
490 :
491 : bool myIsStation;
492 : std::string myRailwayRef;
493 :
494 : /// @brief The current hierarchy level
495 : int myHierarchyLevel;
496 :
497 : /// @brief the set of unique nodes (used for duplicate detection/substitution)
498 : std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
499 :
500 : /// @brief whether elevation data should be imported
501 : const bool myImportElevation;
502 :
503 : /// @brief custom requirements for rail signal tagging
504 : StringVector myRailSignalRules;
505 :
506 : /// @brief number of duplicate nodes
507 : int myDuplicateNodes;
508 :
509 : /// @brief the options
510 : const OptionsCont& myOptionsCont;
511 :
512 : private:
513 : /** @brief invalidated copy constructor */
514 : NodesHandler(const NodesHandler& s);
515 :
516 : /** @brief invalidated assignment operator */
517 : NodesHandler& operator=(const NodesHandler& s);
518 :
519 : };
520 :
521 :
522 : /**
523 : * @class EdgesHandler
524 : * @brief A class which extracts OSM-edges from a parsed OSM-file
525 : */
526 : class EdgesHandler : public SUMOSAXHandler {
527 : public:
528 : /** @brief Constructor
529 : *
530 : * @param[in] osmNodes The previously parsed (osm-)nodes
531 : * @param[in, out] toFill The edges container to fill with read edges
532 : */
533 : EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
534 : std::map<long long int, Edge*>& toFill, std::map<long long int, Edge*>& platformShapes,
535 : const NBTypeCont& tc);
536 :
537 :
538 : /// @brief Destructor
539 : ~EdgesHandler() override;
540 :
541 :
542 : protected:
543 : /// @name inherited from GenericSAXHandler
544 : //@{
545 :
546 : /** @brief Called on the opening of a tag;
547 : *
548 : * @param[in] element ID of the currently opened element
549 : * @param[in] attrs Attributes within the currently opened element
550 : * @exception ProcessError If something fails
551 : * @see GenericSAXHandler::myStartElement
552 : */
553 : void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
554 :
555 :
556 : /** @brief Called when a closing tag occurs
557 : *
558 : * @param[in] element ID of the currently opened element
559 : * @exception ProcessError If something fails
560 : * @see GenericSAXHandler::myEndElement
561 : */
562 : void myEndElement(int element) override;
563 : //@}
564 :
565 : double interpretSpeed(const std::string& key, std::string value);
566 :
567 : int interpretChangeType(const std::string& value) const;
568 :
569 : void interpretLaneUse(const std::string& value, SUMOVehicleClass svc, const bool forward) const;
570 :
571 : bool interpretPlacement(const std::string& value, NIImporter_OpenStreetMap::PlacementType& placement, int& laneIndex) const;
572 :
573 : void addType(const std::string& singleTypeID);
574 :
575 :
576 : private:
577 : /// @brief The previously parsed nodes
578 : const std::map<long long int, NIOSMNode*>& myOSMNodes;
579 :
580 : /// @brief A map of built edges
581 : std::map<long long int, Edge*>& myEdgeMap;
582 :
583 : /// @brief A map of built edges
584 : std::map<long long int, Edge*>& myPlatformShapesMap;
585 :
586 : /// @brief The currently built edge
587 : Edge* myCurrentEdge = nullptr;
588 :
589 : /// @brief A map of non-numeric speed descriptions to their numeric values
590 : std::map<std::string, double> mySpeedMap;
591 :
592 : const NBTypeCont& myTypeCont;
593 :
594 : private:
595 : /** @brief invalidated copy constructor */
596 : EdgesHandler(const EdgesHandler& s);
597 :
598 : /** @brief invalidated assignment operator */
599 : EdgesHandler& operator=(const EdgesHandler& s);
600 :
601 : };
602 :
603 : /**
604 : * @class RelationHandler
605 : * @brief A class which extracts relevant relation information from a parsed OSM-file
606 : * - turn restrictions
607 : */
608 : class RelationHandler : public SUMOSAXHandler {
609 : public:
610 : /** @brief Constructor
611 : *
612 : * @param[in] osmNodes The previously parsed OSM-nodes
613 : * @param[in] osmEdges The previously parse OSM-edges
614 : */
615 : RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
616 : const std::map<long long int, Edge*>& osmEdges, NBPTStopCont* nbptStopCont,
617 : const std::map<long long int, Edge*>& platfromShapes, NBPTLineCont* nbptLineCont,
618 : const OptionsCont& oc);
619 :
620 :
621 : /// @brief Destructor
622 : ~RelationHandler() override;
623 :
624 : protected:
625 : /// @name inherited from GenericSAXHandler
626 : //@{
627 :
628 : /** @brief Called on the opening of a tag;
629 : *
630 : * @param[in] element ID of the currently opened element
631 : * @param[in] attrs Attributes within the currently opened element
632 : * @exception ProcessError If something fails
633 : * @see GenericSAXHandler::myStartElement
634 : */
635 : void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
636 :
637 :
638 : /** @brief Called when a closing tag occurs
639 : *
640 : * @param[in] element ID of the currently opened element
641 : * @exception ProcessError If something fails
642 : * @see GenericSAXHandler::myEndElement
643 : */
644 : void myEndElement(int element) override;
645 : //@}
646 :
647 :
648 : private:
649 : /// @brief The previously parsed nodes
650 : const std::map<long long int, NIOSMNode*>& myOSMNodes;
651 :
652 : /// @brief The previously parsed edges
653 : const std::map<long long int, Edge*>& myOSMEdges;
654 :
655 : /// @brief The previously parsed platform shapes
656 : const std::map<long long int, Edge*>& myPlatformShapes;
657 :
658 : /// @brief The previously filled pt stop container
659 : NBPTStopCont* myNBPTStopCont;
660 :
661 : /// @brief PT Line container to be filled
662 : NBPTLineCont* myNBPTLineCont;
663 :
664 : /// @brief The currently parsed relation
665 : long long int myCurrentRelation;
666 :
667 : /// @brief whether the currently parsed relation is a restriction
668 : bool myIsRestriction;
669 :
670 : /// @brief exceptions to the restriction currenlty being parsed
671 : SVCPermissions myRestrictionException;
672 :
673 : /// @brief the origination way for the current restriction
674 : long long int myFromWay;
675 :
676 : /// @brief the destination way for the current restriction
677 : long long int myToWay;
678 :
679 : /// @brief the via node/way for the current restriction
680 : long long int myViaNode;
681 : long long int myViaWay;
682 :
683 : /// @brief the station node for the current stop_area
684 : long long int myStation;
685 :
686 : /// @brief the options cont
687 : const OptionsCont& myOptionsCont;
688 :
689 : /** @enum RestrictionType
690 : * @brief whether the only allowed or the only forbidden connection is defined
691 : */
692 : enum class RestrictionType {
693 : /// @brief The only valid connection is declared
694 : ONLY,
695 : /// @brief The only invalid connection is declared
696 : NO,
697 : /// @brief The relation tag was missing
698 : UNKNOWN
699 : };
700 : RestrictionType myRestrictionType;
701 :
702 : /// @brief reset members to their defaults for parsing a new relation
703 : void resetValues();
704 :
705 : /// @brief check whether a referenced way has a corresponding edge
706 : bool checkEdgeRef(long long int ref) const;
707 :
708 : /// @brief try to apply the parsed restriction and return whether successful
709 : bool applyRestriction() const;
710 :
711 : /// @brief try to find the way segment among candidates
712 : NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
713 :
714 : private:
715 : /** @brief invalidated copy constructor */
716 : RelationHandler(const RelationHandler& s);
717 :
718 : /** @brief invalidated assignment operator */
719 : RelationHandler& operator=(const RelationHandler& s);
720 :
721 : /// @brief bus stop references
722 : std::vector<long long int> myStops;
723 :
724 : /// @brief myStops which are actually platforms (in case there is no stop_position)
725 : std::set<long long int> myPlatformStops;
726 :
727 :
728 : struct NIIPTPlatform {
729 : long long int ref;
730 : bool isWay;
731 : };
732 :
733 : /// @brief bus stop platforms
734 : std::vector<NIIPTPlatform> myPlatforms;
735 :
736 : /// @brief ways in pt line references
737 : std::vector<long long int> myWays;
738 :
739 : /// @brief indicates whether current relation is a pt stop area
740 : bool myIsStopArea;
741 :
742 : /// @brief indicates whether current relation is a route
743 : bool myIsRoute;
744 :
745 : /// @brief indicates whether current relation is a pt route
746 : std::string myPTRouteType;
747 :
748 : /// @brief official route color
749 : RGBColor myRouteColor;
750 :
751 : /// @brief name of the relation
752 : std::string myName;
753 :
754 : /// @brief ref of the pt line
755 : std::string myRef;
756 :
757 : /// @brief service interval of the pt line in minutes
758 : int myInterval;
759 :
760 : /// @brief night service information of the pt line
761 : std::string myNightService;
762 :
763 : /** @brief the map from stop area member to stop_area id */
764 : std::map<long long int, long long int > myStopAreas;
765 :
766 : };
767 :
768 : };
|