Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NIImporter_OpenStreetMap.cpp
Go to the documentation of this file.
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/****************************************************************************/
24// Importer for networks stored in OpenStreetMap format
25/****************************************************************************/
26#include <config.h>
27#include <algorithm>
28#include <set>
29#include <functional>
30#include <sstream>
31#include <limits>
45#include <utils/xml/XMLSubSys.h>
46#include <netbuild/NBEdge.h>
47#include <netbuild/NBEdgeCont.h>
48#include <netbuild/NBNode.h>
49#include <netbuild/NBNodeCont.h>
51#include <netbuild/NBOwnTLDef.h>
52#include <netbuild/NBPTLine.h>
55#include <netbuild/NBPTStop.h>
56#include "NILoader.h"
58
59//#define DEBUG_LAYER_ELEVATION
60//#define DEBUG_RAIL_DIRECTION
61
62// ---------------------------------------------------------------------------
63// static members
64// ---------------------------------------------------------------------------
66
67const long long int NIImporter_OpenStreetMap::INVALID_ID = std::numeric_limits<long long int>::max();
70
71// ===========================================================================
72// Private classes
73// ===========================================================================
74
78public:
79 bool operator()(const Edge* e1, const Edge* e2) const {
80 if (e1->myHighWayType != e2->myHighWayType) {
81 return e1->myHighWayType > e2->myHighWayType;
82 }
83 if (e1->myNoLanes != e2->myNoLanes) {
84 return e1->myNoLanes > e2->myNoLanes;
85 }
86 if (e1->myDirForward.lanes != e2->myDirForward.lanes) {
87 return e1->myDirForward.lanes > e2->myDirForward.lanes;
88 }
89 if (e1->myDirBackward.lanes != e2->myDirBackward.lanes) {
90 return e1->myDirBackward.lanes > e2->myDirBackward.lanes;
91 }
92 if (e1->myMaxSpeed != e2->myMaxSpeed) {
93 return e1->myMaxSpeed > e2->myMaxSpeed;
94 }
95 if (e1->myIsOneWay != e2->myIsOneWay) {
96 return e1->myIsOneWay > e2->myIsOneWay;
97 }
98 if (e1->myPlacement != e2->myPlacement) {
99 return (int)e1->myPlacement > (int)e2->myPlacement;
100 }
101 if (e1->myPlacementLane != e2->myPlacementLane) {
102 return e1->myPlacementLane > e2->myPlacementLane;
103 }
104 return e1->myCurrentNodes > e2->myCurrentNodes;
105 }
106};
107
108// ===========================================================================
109// method definitions
110// ===========================================================================
111// ---------------------------------------------------------------------------
112// static methods
113// ---------------------------------------------------------------------------
114const std::string NIImporter_OpenStreetMap::compoundTypeSeparator("|"); //clang-tidy says: "compundTypeSeparator with
115// static storage duration my throw an exception that cannot be caught
116
117void
120 importer.load(oc, nb);
121}
122
124
126 // delete nodes
127 for (auto myUniqueNode : myUniqueNodes) {
128 delete myUniqueNode;
129 }
130 // delete edges
131 for (auto& myEdge : myEdges) {
132 delete myEdge.second;
133 }
134 // delete platform shapes
135 for (auto& myPlatformShape : myPlatformShapes) {
136 delete myPlatformShape.second;
137 }
138}
139
140void
142 if (!oc.isSet("osm-files")) {
143 return;
144 }
145 const std::vector<std::string> files = oc.getStringVector("osm-files");
146 std::vector<SUMOSAXReader*> readers;
147
148 myImportLaneAccess = oc.getBool("osm.lane-access");
149 myImportTurnSigns = oc.getBool("osm.turn-lanes");
150 myImportSidewalks = oc.getBool("osm.sidewalks");
151 myImportBikeAccess = oc.getBool("osm.bike-access");
152 myImportCrossings = oc.getBool("osm.crossings");
153 myOnewayDualSidewalk = oc.getBool("osm.oneway-reverse-sidewalk");
154 myAnnotateDefaults = oc.getBool("osm.annotate-defaults");
155 myETCS_movingBlock = oc.getBool("osm.etcs-moving-block");
158
159 myAllAttributes = OptionsCont::getOptions().getBool("osm.all-attributes");
160 std::vector<std::string> extra = OptionsCont::getOptions().getStringVector("osm.extra-attributes");
161 myExtraAttributes.insert(extra.begin(), extra.end());
162 if (myExtraAttributes.count("all") != 0) {
163 // import all
164 myExtraAttributes.clear();
165 }
166
167 // load nodes, first
168 NodesHandler nodesHandler(myOSMNodes, myUniqueNodes, oc);
169 for (const std::string& file : files) {
170 if (!FileHelpers::isReadable(file)) {
171 WRITE_ERRORF(TL("Could not open osm-file '%'."), file);
172 return;
173 }
174 nodesHandler.setFileName(file);
175 nodesHandler.resetHierarchy();
176 const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing nodes from osm-file '" + file + "'");
177 readers.push_back(XMLSubSys::getSAXReader(nodesHandler));
178 if (!readers.back()->parseFirst(file) || !readers.back()->parseSection(SUMO_TAG_NODE) ||
180 return;
181 }
182 if (nodesHandler.getDuplicateNodes() > 0) {
183 WRITE_MESSAGEF(TL("Found and substituted % osm nodes."), toString(nodesHandler.getDuplicateNodes()));
184 }
185 PROGRESS_TIME_MESSAGE(before);
186 }
187
188 // load edges, then
190 int idx = 0;
191 for (const std::string& file : files) {
192 edgesHandler.setFileName(file);
193 readers[idx]->setHandler(edgesHandler);
194 const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing edges from osm-file '" + file + "'");
195 if (!readers[idx]->parseSection(SUMO_TAG_WAY)) {
196 // eof already reached, no relations
197 delete readers[idx];
198 readers[idx] = nullptr;
199 }
200 PROGRESS_TIME_MESSAGE(before);
201 idx++;
202 }
203
204 /* Remove duplicate edges with the same shape and attributes */
205 if (!oc.getBool("osm.skip-duplicates-check")) {
206 int numRemoved = 0;
207 PROGRESS_BEGIN_MESSAGE(TL("Removing duplicate edges"));
208 if (myEdges.size() > 1) {
209 std::set<const Edge*, CompareEdges> dupsFinder;
210 for (auto it = myEdges.begin(); it != myEdges.end();) {
211 if (dupsFinder.count(it->second) > 0) {
212 numRemoved++;
213 delete it->second;
214 myEdges.erase(it++);
215 } else {
216 dupsFinder.insert(it->second);
217 it++;
218 }
219 }
220 }
221 if (numRemoved > 0) {
222 WRITE_MESSAGEF(TL("Removed % duplicate osm edges."), toString(numRemoved));
223 }
225 }
226
227 /* Mark which nodes are used (by edges or traffic lights).
228 * This is necessary to detect which OpenStreetMap nodes are for
229 * geometry only */
230 std::map<long long int, int> nodeUsage;
231 // Mark which nodes are used by edges (begin and end)
232 for (const auto& edgeIt : myEdges) {
233 assert(edgeIt.second->myCurrentIsRoad);
234 for (const long long int node : edgeIt.second->myCurrentNodes) {
235 nodeUsage[node]++;
236 }
237 }
238 // Mark which nodes are used by traffic lights or are pedestrian crossings
239 for (const auto& nodesIt : myOSMNodes) {
240 if (nodesIt.second->tlsControlled || nodesIt.second->railwaySignal != SIGNAL_NONE || (nodesIt.second->pedestrianCrossing && myImportCrossings) /* || nodesIt->second->railwayCrossing*/) {
241 // If the key is not found in the map, the value is automatically
242 // initialized with 0.
243 nodeUsage[nodesIt.first]++;
244 }
245 }
246
247 /* Instantiate edges
248 * Only those nodes in the middle of an edge which are used by more than
249 * one edge are instantiated. Other nodes are considered as geometry nodes. */
250 NBNodeCont& nc = nb.getNodeCont();
252 for (const auto& edgeIt : myEdges) {
253 Edge* const e = edgeIt.second;
254 if (!e->myCurrentIsRoad) {
255 continue;
256 }
257 if (e->myCurrentNodes.size() < 2) {
258 WRITE_WARNINGF(TL("Discarding way '%' because it has only % node(s)"), e->id, e->myCurrentNodes.size());
259 continue;
260 }
262 // build nodes;
263 // - the from- and to-nodes must be built in any case
264 // - the in-between nodes are only built if more than one edge references them
265 NBNode* first = insertNodeChecking(e->myCurrentNodes.front(), nc, tlsc);
266 NBNode* last = insertNodeChecking(e->myCurrentNodes.back(), nc, tlsc);
267 NBNode* currentFrom = first;
268 int running = 0;
269 std::vector<long long int> passed;
270 for (auto j = e->myCurrentNodes.begin(); j != e->myCurrentNodes.end(); ++j) {
271 passed.push_back(*j);
272 if (nodeUsage[*j] > 1 && j != e->myCurrentNodes.end() - 1 && j != e->myCurrentNodes.begin()) {
273 NBNode* currentTo = insertNodeChecking(*j, nc, tlsc);
274 running = insertEdge(e, running, currentFrom, currentTo, passed, nb, first, last);
275 currentFrom = currentTo;
276 passed.clear();
277 passed.push_back(*j);
278 }
279 }
280 if (running == 0) {
281 running = -1;
282 }
283 insertEdge(e, running, currentFrom, last, passed, nb, first, last);
284 }
286 WRITE_MESSAGEF(TL("Skipped applying OSM placement on % edge(s): % due to non-explicit one-way and % due to opposite-direction auxiliary edges."),
290 }
291
292 /* Collect edges which explicitly are part of a roundabout and store the edges of each
293 * detected roundabout */
295
296 if (myImportCrossings) {
297 /* After edges are instantiated
298 * nodes are parsed again to add pedestrian crossings to them
299 * This is only executed if crossings are imported and not guessed */
300 const double crossingWidth = OptionsCont::getOptions().getFloat("default.crossing-width");
301
302 for (auto item : nodeUsage) {
303 NIOSMNode* osmNode = myOSMNodes.find(item.first)->second;
304 if (osmNode->pedestrianCrossing) {
305 NBNode* n = osmNode->node;
306 EdgeVector incomingEdges = n->getIncomingEdges();
307 EdgeVector outgoingEdges = n->getOutgoingEdges();
308 size_t incomingEdgesNo = incomingEdges.size();
309 size_t outgoingEdgesNo = outgoingEdges.size();
310
311 for (size_t i = 0; i < incomingEdgesNo; i++) {
312 /* Check if incoming edge has driving lanes(and sidewalks)
313 * if not, ignore
314 * if yes, check if there is a corresponding outgoing edge for the opposite direction
315 * -> if yes, check if it has driving lanes
316 * --> if yes, do the crossing
317 * --> if no, only do the crossing with the incoming edge (usually one lane roads with two sidewalks)
318 * -> if not, do nothing as we don't have a sidewalk in the opposite direction */
319 auto const iEdge = incomingEdges[i];
320
321 if (iEdge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD) > -1
322 && iEdge->getSpecialLane(SVC_PEDESTRIAN) > -1) {
323 std::string const& iEdgeId = iEdge->getID();
324 std::size_t const m = iEdgeId.find_first_of("#");
325 std::string const& iWayId = iEdgeId.substr(0, m);
326 for (size_t j = 0; j < outgoingEdgesNo; j++) {
327 auto const oEdge = outgoingEdges[j];
328 // Searching for a corresponding outgoing edge (based on OSM way identifier)
329 // with at least a pedestrian lane, going in the opposite direction
330 if (oEdge->getID().find(iWayId) != std::string::npos
331 && oEdge->getSpecialLane(SVC_PEDESTRIAN) > -1
332 && oEdge->getID().rfind(iWayId, 0) != 0) {
333 EdgeVector edgeVector = EdgeVector{ iEdge };
334 if (oEdge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD) > -1) {
335 edgeVector.push_back(oEdge);
336 }
337
338 if (!n->checkCrossingDuplicated(edgeVector)) {
339 n->addCrossing(edgeVector, crossingWidth, false);
340 }
341 }
342 }
343 }
344 }
345 for (size_t i = 0; i < outgoingEdgesNo; i++) {
346 // Same checks as above for loop, but for outgoing edges
347 auto const oEdge = outgoingEdges[i];
348
349 if (oEdge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD) > -1
350 && oEdge->getSpecialLane(SVC_PEDESTRIAN) > -1) {
351 std::string const& oEdgeId = oEdge->getID();
352 std::size_t const m = oEdgeId.find_first_of("#");
353 std::string const& iWayId = oEdgeId.substr(0, m);
354 for (size_t j = 0; j < incomingEdgesNo; j++) {
355 auto const iEdge = incomingEdges[j];
356 if (iEdge->getID().find(iWayId) != std::string::npos
357 && iEdge->getSpecialLane(SVC_PEDESTRIAN) > -1
358 && iEdge->getID().rfind(iWayId, 0) != 0) {
359 EdgeVector edgeVector = EdgeVector{ oEdge };
360 if (iEdge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD) > -1) {
361 edgeVector.push_back(iEdge);
362 }
363
364 if (!n->checkCrossingDuplicated(edgeVector)) {
365 n->addCrossing(edgeVector, crossingWidth, false);
366 }
367 }
368 }
369 }
370 }
371 }
372 }
373 }
374
375 const double layerElevation = oc.getFloat("osm.layer-elevation");
376 if (layerElevation > 0) {
377 reconstructLayerElevation(layerElevation, nb);
378 }
379
380 // revise pt stops; remove stops on deleted edges (but assign them to the
381 // opposite direction if possible
383
384 // load relations (after edges are built since we want to apply
385 // turn-restrictions directly to NBEdges)
387 &nb.getPTLineCont(), oc);
388 idx = 0;
389 for (const std::string& file : files) {
390 if (readers[idx] != nullptr) {
391 relationHandler.setFileName(file);
392 readers[idx]->setHandler(relationHandler);
393 const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing relations from osm-file '" + file + "'");
394 readers[idx]->parseSection(SUMO_TAG_RELATION);
395 PROGRESS_TIME_MESSAGE(before);
396 delete readers[idx];
397 }
398 idx++;
399 }
400
401 // declare additional stops that are not anchored to a (road)-way or route relation
402 std::set<std::string> stopNames;
403 for (const auto& item : nb.getPTStopCont().getStops()) {
404 stopNames.insert(item.second->getName());
405 }
406 for (const auto& item : myOSMNodes) {
407 const NIOSMNode* n = item.second;
408 if (n->ptStopPosition && stopNames.count(n->name) == 0) {
409 Position ptPos(n->lon, n->lat, n->ele);
411 WRITE_ERRORF("Unable to project coordinates for node '%'.", n->id);
412 }
414 std::shared_ptr<NBPTStop> ptStop = std::make_shared<NBPTStop>(element, toString(n->id), ptPos, "", "", n->ptStopLength, n->name, n->permissions);
415 nb.getPTStopCont().insert(ptStop, true);
416 }
417 }
418}
419
420// ---------------------------------------------------------------------------
421// definitions of NIImporter_OpenStreetMap-methods
422// ---------------------------------------------------------------------------
423
424NBNode*
426 NBNode* node = nc.retrieve(toString(id));
427 if (node == nullptr) {
428 NIOSMNode* n = myOSMNodes.find(id)->second;
429 Position pos(n->lon, n->lat, n->ele);
430 if (!NBNetBuilder::transformCoordinate(pos, true)) {
431 WRITE_ERRORF("Unable to project coordinates for junction '%'.", id);
432 return nullptr;
433 }
434 node = new NBNode(toString(id), pos);
435 if (!nc.insert(node)) {
436 WRITE_ERRORF(TL("Could not insert junction '%'."), toString(id));
437 delete node;
438 return nullptr;
439 }
440 n->node = node;
441 if (n->railwayCrossing) {
442 if (n->getParameter("crossing:barrier", "no") != "no"
443 || n->getParameter("crossing.light") == "yes"
444 || n->tlsControlled) {
446 }
447 } else if (n->railwaySignal != SIGNAL_NONE) {
449 if ((n->railwaySignal & SIGNAL_MAIN) == 0) {
450 node->setParameter("virtual", "true");
451 }
453 node->setParameter("moving-block", "true");
454 }
455 } else if (n->tlsControlled) {
456 // ok, this node is a traffic light node where no other nodes
457 // participate
458 // @note: The OSM-community has not settled on a schema for differentiating between fixed and actuated lights
460 OptionsCont::getOptions().getString("tls.default-type"));
461 NBOwnTLDef* tlDef = new NBOwnTLDef(toString(id), node, 0, type);
462 if (!tlsc.insert(tlDef)) {
463 // actually, nothing should fail here
464 delete tlDef;
465 throw ProcessError(TLF("Could not allocate tls '%'.", toString(id)));
466 }
467 }
468 if (n->railwayBufferStop) {
469 node->setParameter("buffer_stop", "true");
470 node->setFringeType(FringeType::INNER);
471 }
472 if (n->railwaySignal != SIGNAL_NONE) {
473 if (n->myRailDirection == WAY_FORWARD) {
475 } else if (n->myRailDirection == WAY_BACKWARD) {
476 node->setParameter(NBTrafficLightDefinition::OSM_SIGNAL_DIRECTION, "backward");
477 }
478 }
479 node->updateParameters(n->getParametersMap());
480 }
481 return node;
482}
483
484
485int
487 const std::vector<long long int>& passed, NBNetBuilder& nb,
488 const NBNode* first, const NBNode* last) {
489 NBNodeCont& nc = nb.getNodeCont();
490 NBEdgeCont& ec = nb.getEdgeCont();
491 NBTypeCont& tc = nb.getTypeCont();
492 NBPTStopCont& sc = nb.getPTStopCont();
493
495 // patch the id
496 std::string id = toString(e->id);
497 if (from == nullptr || to == nullptr) {
498 WRITE_ERRORF("Discarding edge '%' because the nodes could not be built.", id);
499 return index;
500 }
501 if (index >= 0) {
502 id = id + "#" + toString(index);
503 } else {
504 index = 0;
505 }
506 if (from == to) {
507 assert(passed.size() >= 2);
508 if (passed.size() == 2) {
509 WRITE_WARNINGF(TL("Discarding edge '%' which connects two identical nodes without geometry."), id);
510 return index;
511 }
512 // in the special case of a looped way split again using passed
513 int intermediateIndex = (int) passed.size() / 2;
514 NBNode* intermediate = insertNodeChecking(passed[intermediateIndex], nc, tlsc);
515 std::vector<long long int> part1(passed.begin(), passed.begin() + intermediateIndex + 1);
516 std::vector<long long int> part2(passed.begin() + intermediateIndex, passed.end());
517 index = insertEdge(e, index, from, intermediate, part1, nb, first, last);
518 return insertEdge(e, index, intermediate, to, part2, nb, first, last);
519 }
520 const int newIndex = index + 1;
521 const std::string type = usableType(e->myHighWayType, id, tc);
522 if (type == "") { // we do not want to import it
523 return newIndex;
524 }
525 std::string routingType = "";
526 int numLanesForward = tc.getEdgeTypeNumLanes(type);
527 int numLanesBackward = tc.getEdgeTypeNumLanes(type);
528 double speed = tc.getEdgeTypeSpeed(type);
529 bool defaultsToOneWay = tc.getEdgeTypeIsOneWay(type);
530 const SVCPermissions defaultPermissions = tc.getEdgeTypePermissions(type);
531 SVCPermissions extra = myImportBikeAccess ? e->myExtraAllowed : (e->myExtraAllowed & ~SVC_BICYCLE);
532 const SVCPermissions extraDis = myImportBikeAccess ? e->myExtraDisallowed : (e->myExtraDisallowed & ~SVC_BICYCLE);
533 std::vector<SumoXMLAttr> defaults;
534 // extra permissions are more specific than extra prohibitions except for buses (which come from the less specific psv tag)
535 if ((extraDis & SVC_BUS) && (extra & SVC_BUS)) {
536 extra = extra & ~SVC_BUS;
537 }
538 SVCPermissions permissions = (defaultPermissions & ~extraDis) | extra;
539 if (!myImportBikeAccess && permissions == (SVC_PEDESTRIAN | SVC_BICYCLE)
540 && (e->myExtraDisallowed & SVC_BICYCLE) != 0
541 && (e->myExtraAllowed & SVC_BICYCLE) == 0) {
542 // remove bicyle permissions where they affect network building the most
543 permissions = SVC_PEDESTRIAN;
544 defaultsToOneWay = true;
545 }
546 if (defaultPermissions == SVC_SHIP) {
547 // extra permission apply to the ships operating on the route rather than the waterway
548 permissions = defaultPermissions;
549 }
550 if (defaultsToOneWay && defaultPermissions == SVC_PEDESTRIAN && (permissions & (~SVC_PEDESTRIAN)) != 0) {
551 defaultsToOneWay = false;
552 }
553 if ((permissions & SVC_RAIL) != 0 && e->myExtraTags.count("electrified") != 0) {
554 permissions |= (SVC_RAIL_ELECTRIC | SVC_RAIL_FAST);
555 }
556
557 // convert the shape
558 PositionVector shape;
559 double distanceStart = myOSMNodes[passed.front()]->positionMeters;
560 double distanceEnd = myOSMNodes[passed.back()]->positionMeters;
561 const bool useDistance = distanceStart != std::numeric_limits<double>::max() && distanceEnd != std::numeric_limits<double>::max();
562 if (useDistance) {
563 // negative sign denotes counting in the other direction
564 if (distanceStart < distanceEnd) {
565 distanceEnd *= -1;
566 } else {
567 distanceStart *= -1;
568 }
569 } else {
570 distanceStart = 0;
571 distanceEnd = 0;
572 }
573 // get additional direction information
574 int nodeDirection = WAY_UNKNOWN;
575 const NIOSMNode* fn = myOSMNodes.find(StringUtils::toLong(from->getID()))->second;
576 const NIOSMNode* ft = myOSMNodes.find(StringUtils::toLong(to->getID()))->second;
577 if (fn->railwaySignal != SIGNAL_NONE) {
578 nodeDirection |= fn->myRailDirection;
579 }
580 if (ft->railwaySignal != SIGNAL_NONE) {
581 nodeDirection |= ft->myRailDirection;
582 }
583
584 std::vector<std::shared_ptr<NBPTStop> > ptStops;
585 for (long long i : passed) {
586 NIOSMNode* n = myOSMNodes.find(i)->second;
587 // recheck permissions, maybe they got assigned to a strange edge, see #11656
588 if (n->ptStopPosition && (n->permissions == 0 || (permissions & n->permissions) != 0)) {
589 std::shared_ptr<NBPTStop> existingPtStop = sc.get(toString(n->id));
590 if (existingPtStop != nullptr) {
591 existingPtStop->registerAdditionalEdge(toString(e->id), id);
592 } else {
593 Position ptPos(n->lon, n->lat, n->ele);
595 WRITE_ERRORF("Unable to project coordinates for node '%'.", n->id);
596 }
598 ptStops.push_back(std::make_shared<NBPTStop>(element, toString(n->id), ptPos, id, toString(e->id), n->ptStopLength, n->name, n->permissions));
599 sc.insert(ptStops.back());
600 }
601 }
602 if (n->railwaySignal != SIGNAL_NONE) {
603 nodeDirection |= n->myRailDirection;
604 }
605 Position pos(n->lon, n->lat, n->ele);
606 shape.push_back(pos);
607 }
608 //if (e->id == DEBUGID) {
609 // std::cout
610 // << " id=" << id << " from=" << from->getID() << " fromRailDirection=" << myOSMNodes.find(StringUtils::toLong(from->getID()))->second->myRailDirection
611 // << " to=" << to->getID() << " toRailDirection=" << myOSMNodes.find(StringUtils::toLong(to->getID()))->second->myRailDirection
612 // << " origRailDirection=" << e->myRailDirection
613 // << " nodeDirection=" << nodeDirection
614 // << "\n";
615 //}
616 if (e->myRailDirection == WAY_UNKNOWN && (nodeDirection & WAY_BACKWARD) != 0) {
617 // legacy behavior seems to have handled missing tags quite well
619 //std::cout << " id=" << id << " newRailDir=" << e->myRailDirection << "\n";
620 } else if (nodeDirection != WAY_UNKNOWN) {
621 // additional direction information can just be added
622 e->myRailDirection = (e->myRailDirection | nodeDirection) & ~WAY_UNKNOWN;
623 }
624
626 WRITE_ERRORF("Unable to project coordinates for edge '%'.", id);
627 }
628
629 SVCPermissions forwardPermissions = permissions;
630 SVCPermissions backwardPermissions = permissions;
631 const std::string streetName = isRailway(permissions) && e->ref != "" ? e->ref : e->streetName;
632 if (streetName == e->ref) {
633 e->unsetParameter("ref"); // avoid superfluous param for railways
634 }
635 double forwardWidth = tc.getEdgeTypeWidth(type);
636 double backwardWidth = tc.getEdgeTypeWidth(type);
637 double sidewalkWidth = tc.getEdgeTypeSidewalkWidth(type);
638 bool addSidewalk = sidewalkWidth != NBEdge::UNSPECIFIED_WIDTH;
639 if (myImportSidewalks) {
640 if (addSidewalk) {
641 // only use sidewalk width from typemap but don't add sidewalks
642 // unless OSM specifies them
643 addSidewalk = false;
644 } else {
645 sidewalkWidth = OptionsCont::getOptions().getFloat("default.sidewalk-width");
646 }
647 }
648 double bikeLaneWidth = tc.getEdgeTypeBikeLaneWidth(type);
649 const bool reverseOneway = (e->myIsOneWay == "-1" || e->myIsOneWay == "reverse");
650 const std::string& onewayBike = e->myExtraTags["oneway:bicycle"];
651 if (onewayBike == "false" || onewayBike == "no" || onewayBike == "0") {
652 const WayType contraBike = reverseOneway ? WAY_FORWARD : WAY_BACKWARD;
653 e->myCyclewayType = e->myCyclewayType == WAY_UNKNOWN ? contraBike : (WayType)(e->myCyclewayType | contraBike);
654 }
655
656 const bool addBikeLane = bikeLaneWidth != NBEdge::UNSPECIFIED_WIDTH ||
657 (myImportBikeAccess && (((e->myCyclewayType & WAY_BOTH) != 0 || e->myExtraTags.count("segregated") != 0) &&
658 !(e->myCyclewayType == WAY_BACKWARD && (e->myBuswayType & WAY_BOTH) != 0) &&
659 !(reverseOneway && e->myCyclewayType == WAY_FORWARD && (e->myBuswayType & WAY_BOTH) != 0)));
660 if (addBikeLane && bikeLaneWidth == NBEdge::UNSPECIFIED_WIDTH) {
661 bikeLaneWidth = OptionsCont::getOptions().getFloat("default.bikelane-width");
662 }
663 // check directions
664 bool addForward = true;
665 bool addBackward = true;
666 const bool explicitOneWay = StringUtils::isBool(e->myIsOneWay) && StringUtils::toBool(e->myIsOneWay);
667 const bool explicitTwoWay = StringUtils::isBool(e->myIsOneWay) && !StringUtils::toBool(e->myIsOneWay);
668 if ((explicitOneWay || (defaultsToOneWay && (!explicitTwoWay || isRailway(permissions)))) && (e->myRailDirection & WAY_BACKWARD) == 0) {
669 addBackward = false;
670 }
671 if (e->myIsOneWay == "-1" || e->myIsOneWay == "reverse"
672 || ((e->myRailDirection & WAY_BACKWARD) != 0 && (e->myRailDirection & WAY_FORWARD) == 0)) {
673 // one-way in reversed direction of way
674 addForward = false;
675 addBackward = true;
676 }
677 if (!e->myIsOneWay.empty() && !explicitOneWay && !explicitTwoWay && e->myIsOneWay != "-1" && e->myIsOneWay != "reverse") {
678 WRITE_WARNINGF(TL("New value for oneway found: %"), e->myIsOneWay);
679 }
680 if ((permissions == SVC_BICYCLE || permissions == (SVC_BICYCLE | SVC_PEDESTRIAN) || permissions == SVC_PEDESTRIAN)) {
681 if (addBackward && (onewayBike == "true" || onewayBike == "yes" || onewayBike == "1")) {
682 addBackward = false;
683 }
684 if (addForward && (onewayBike == "reverse" || onewayBike == "-1")) {
685 addForward = false;
686 }
687 if (!addBackward && (onewayBike == "false" || onewayBike == "no" || onewayBike == "0")) {
688 addBackward = true;
689 }
690 }
691 if (e->myNoLanes == 0) {
692 WRITE_WARNINGF(TL("Skipping edge '%' because it has zero lanes."), id);
693 return newIndex;
694 }
695 const Edge::DirLaneInfo& dirFwd = e->myDirForward;
696 const Edge::DirLaneInfo& dirBwd = e->myDirBackward;
697 const bool hasForwardBusLanes = myImportLaneAccess && dirFwd.busLanes > 0;
698 const bool hasBackwardBusLanes = myImportLaneAccess && dirBwd.busLanes > 0;
699 // if we had been able to extract the number of lanes, override the highway type default
700 if (e->myNoLanes > 0) {
701 if (addForward && !addBackward) {
702 numLanesForward = dirFwd.lanes > 0 ? dirFwd.lanes : (dirBwd.lanes > 0 ? MAX2(1, e->myNoLanes - dirBwd.lanes) : e->myNoLanes);
703 } else if (!addForward && addBackward) {
704 numLanesBackward = dirBwd.lanes > 0 ? dirBwd.lanes : (dirFwd.lanes > 0 ? MAX2(1, e->myNoLanes - dirFwd.lanes) : e->myNoLanes);
705 } else {
706 if (dirFwd.lanes > 0 && dirBwd.lanes > 0) {
707 numLanesForward = dirFwd.lanes;
708 numLanesBackward = dirBwd.lanes;
709 } else if (dirFwd.lanes > 0) {
710 numLanesForward = dirFwd.lanes;
711 numLanesBackward = MAX2(1, e->myNoLanes - dirFwd.lanes - e->myNoLanesBothWays);
712 } else if (dirBwd.lanes > 0) {
713 numLanesBackward = dirBwd.lanes;
714 numLanesForward = MAX2(1, e->myNoLanes - dirBwd.lanes - e->myNoLanesBothWays);
715 } else {
716 const int effectiveLanes = e->myNoLanesBothWays > 0 ? MAX2(2, e->myNoLanes - e->myNoLanesBothWays) : e->myNoLanes;
717 numLanesForward = MAX2(1, (int)std::ceil(effectiveLanes / 2.0));
718 numLanesBackward = MAX2(1, effectiveLanes - numLanesForward);
719 }
720 }
721 } else {
722 auto resolveUnmarked = [&](const Edge::DirLaneInfo& dir, WayType buswayBit, bool hasBus, int& numLanes) {
723 if (dir.lanes > 0) {
724 numLanes = dir.lanes;
725 } else if (((e->myBuswayType & buswayBit) != 0 || hasBus) && (extraDis & SVC_PASSENGER) == 0) {
726 // if we have a busway lane, yet cars may drive this implies at least two lanes
727 numLanes = MAX2(numLanes, MAX2(2, (hasBus ? dir.busLanes : 1) + 1));
728 } else if (hasBus) {
729 numLanes = MAX2(numLanes, dir.busLanes);
730 }
731 };
732 resolveUnmarked(dirFwd, WAY_FORWARD, hasForwardBusLanes, numLanesForward);
733 resolveUnmarked(dirBwd, WAY_BACKWARD, hasBackwardBusLanes, numLanesBackward);
734 if (myAnnotateDefaults && dirFwd.lanes == 0 && dirBwd.lanes == 0) {
735 defaults.push_back(SUMO_ATTR_NUMLANES);
736 }
737 }
738 // deal with busways / contraflow exemptions (oneway:<mode>=no) running opposite a one-way street
739 const SVCPermissions motorContra = e->myOnewayContraPermissions & ~SVC_BICYCLE;
740 auto openContra = [&](bool& addDir, SVCPermissions& dirPerms, int& numLanes,
741 const Edge::DirLaneInfo& dir, WayType buswayBit, bool hasBus, bool isContraSide) {
742 if (!addDir && ((e->myBuswayType & buswayBit) != 0
743 || (isContraSide && motorContra != 0)
744 || (hasBus && dir.hasExplicitDirBus))) {
745 addDir = true;
746 SVCPermissions perms = (isContraSide ? e->myOnewayContraPermissions : (SVCPermissions)0)
747 | (hasBus ? dir.busClasses : (SVCPermissions)0);
748 if ((e->myBuswayType & buswayBit) != 0) {
749 perms |= SVC_BUS;
750 }
751 dirPerms = perms != 0 ? perms : (SVCPermissions)SVC_BUS;
752 numLanes = dir.lanes > 0 ? dir.lanes : (hasBus ? dir.busLanes : 1);
753 }
754 };
755 openContra(addForward, forwardPermissions, numLanesForward, dirFwd, WAY_FORWARD, hasForwardBusLanes, reverseOneway);
756 openContra(addBackward, backwardPermissions, numLanesBackward, dirBwd, WAY_BACKWARD, hasBackwardBusLanes, !reverseOneway);
757 // width is meant for raw lane count before adding sidewalks or cycleways
758 const int taggedLanes = (addForward ? numLanesForward : 0) + (addBackward ? numLanesBackward : 0);
759 if (e->myWidth > 0 && e->myWidthLanesForward.size() == 0 && e->myWidthLanesBackward.size() == 0 && taggedLanes != 0
760 && !OptionsCont::getOptions().getBool("ignore-widths")) {
761 // width is tagged excluding sidewalks and cycleways
762 forwardWidth = e->myWidth / taggedLanes;
763 backwardWidth = forwardWidth;
764 }
765
766 // if we had been able to extract the maximum speed, override the type's default
767 if (e->myMaxSpeed != MAXSPEED_UNGIVEN) {
768 speed = e->myMaxSpeed;
769 } else if (myAnnotateDefaults) {
770 defaults.push_back(SUMO_ATTR_SPEED);
771 }
772 double speedBackward = (e->myMaxSpeedBase != MAXSPEED_UNGIVEN) ? e->myMaxSpeedBase : speed;
774 speedBackward = e->myMaxSpeedBackward;
775 addBackward = true;
776 }
777 if (speed <= 0 || speedBackward <= 0) {
778 WRITE_WARNINGF(TL("Skipping edge '%' because it has speed %."), id, speed);
779 return newIndex;
780 }
781 if (e->myNoLanes == 1 && addForward && addBackward) {
782 // narrow road which now receives a total of 2 lanes but has less capacity than implied
783 if (e->myWidth < 0 && e->myWidthLanesForward.size() == 0 && e->myWidthLanesBackward.size() == 0) {
784 if (forwardWidth == NBEdge::UNSPECIFIED_WIDTH) {
785 forwardWidth = SUMO_const_laneWidth;
786 }
787 if (backwardWidth == NBEdge::UNSPECIFIED_WIDTH) {
788 backwardWidth = SUMO_const_laneWidth;
789 }
790 forwardWidth /= 2;
791 backwardWidth /= 2;
792 }
793 if (e->myWidth < 5) {
794 routingType = "narrow";
795 }
796 }
797 // deal with cycleways that run in the opposite direction of a one-way street
798 WayType cyclewayType = e->myCyclewayType; // make a copy because we do some temporary modifications
799 if (addBikeLane) {
800 if (!addForward && (cyclewayType & WAY_FORWARD) != 0) {
801 addForward = true;
802 forwardPermissions = SVC_BICYCLE;
803 forwardWidth = bikeLaneWidth;
804 numLanesForward = 1;
805 // do not add an additional cycle lane
806 cyclewayType = (WayType)(cyclewayType & ~WAY_FORWARD);
807 }
808 if (!addBackward && (cyclewayType & WAY_BACKWARD) != 0) {
809 addBackward = true;
810 backwardPermissions = SVC_BICYCLE;
811 backwardWidth = bikeLaneWidth;
812 numLanesBackward = 1;
813 // do not add an additional cycle lane
814 cyclewayType = (WayType)(cyclewayType & ~WAY_BACKWARD);
815 }
816 }
817 // deal with sidewalks that run in the opposite direction of a one-way street
818 WayType sidewalkType = e->mySidewalkType; // make a copy because we do some temporary modifications
819 if (sidewalkType == WAY_UNKNOWN && (e->myExtraAllowed & SVC_PEDESTRIAN) != 0 && (permissions & SVC_PASSENGER) != 0) {
820 // do not assume shared space unless sidewalk is actively disabled
822 sidewalkType = WAY_BOTH;
823 }
824 }
825 if (addSidewalk || (myImportSidewalks && (permissions & SVC_ROAD_CLASSES) != 0 && defaultPermissions != SVC_PEDESTRIAN)) {
826 if (!addForward && (sidewalkType & WAY_FORWARD) != 0) {
827 addForward = true;
828 forwardPermissions = SVC_PEDESTRIAN;
829 forwardWidth = tc.getEdgeTypeSidewalkWidth(type);
830 numLanesForward = 1;
831 // do not add an additional sidewalk
832 sidewalkType = (WayType)(sidewalkType & ~WAY_FORWARD); //clang tidy thinks "!WAY_FORWARD" is always false
833 } else if (addSidewalk && addForward && (sidewalkType & WAY_BOTH) == 0
834 && numLanesForward == 1 && numLanesBackward <= 1
835 && (e->myExtraDisallowed & SVC_PEDESTRIAN) == 0) {
836 // our typemap says pedestrians should walk here but the data says
837 // there is no sidewalk at all. If the road is small, pedestrians can just walk
838 // on the road
839 forwardPermissions |= SVC_PEDESTRIAN;
840 }
841 if (!addBackward && (sidewalkType & WAY_BACKWARD) != 0) {
842 addBackward = true;
843 backwardPermissions = SVC_PEDESTRIAN;
844 backwardWidth = tc.getEdgeTypeSidewalkWidth(type);
845 numLanesBackward = 1;
846 // do not add an additional cycle lane
847 sidewalkType = (WayType)(sidewalkType & ~WAY_BACKWARD); //clang tidy thinks "!WAY_BACKWARD" is always false
848 } else if (addSidewalk && addBackward && (sidewalkType & WAY_BOTH) == 0
849 && numLanesBackward == 1 && numLanesForward <= 1
850 && (e->myExtraDisallowed & SVC_PEDESTRIAN) == 0) {
851 // our typemap says pedestrians should walk here but the data says
852 // there is no sidewalk at all. If the road is small, pedestrians can just walk
853 // on the road
854 backwardPermissions |= SVC_PEDESTRIAN;
855 }
856 }
857
858 bool applyPlacement = false;
859 double placementOffset = 0;
861 if (!explicitOneWay) {
862 if (index <= 0) {
864 }
865 } else if (!(addForward && !addBackward)) {
866 if (index <= 0) {
868 }
869 } else if (numLanesForward <= 0) {
870 if (index <= 0) {
871 WRITE_WARNINGF(TL("Ignoring placement for edge '%' because lane count is invalid."), id);
872 }
873 } else {
874 const double defaultPlacementWidth = forwardWidth == NBEdge::UNSPECIFIED_WIDTH || forwardWidth <= 0
875 ? SUMO_const_laneWidth : forwardWidth;
876 std::vector<double> laneWidths((size_t)numLanesForward, defaultPlacementWidth);
877 if (!OptionsCont::getOptions().getBool("ignore-widths")
878 && (int)e->myWidthLanesForward.size() == numLanesForward) {
879 for (int i = 0; i < numLanesForward; ++i) {
880 laneWidths[(size_t)i] = e->myWidthLanesForward[(size_t)i] > 0
881 ? e->myWidthLanesForward[(size_t)i] : defaultPlacementWidth;
882 }
883 }
884 if (e->myPlacementLane < 1 || e->myPlacementLane > numLanesForward) {
885 if (index <= 0) {
886 WRITE_WARNINGF(TL("Ignoring placement for edge '%' because lane index '%' is out of range [1, %]."),
887 id, e->myPlacementLane, numLanesForward);
888 }
889 } else {
890 const int laneIndex = e->myPlacementLane - 1;
891 double leftOffset = 0;
892 for (int i = 0; i < laneIndex; ++i) {
893 leftOffset += laneWidths[(size_t)i];
894 }
895 double placementRefOffset = leftOffset;
897 placementRefOffset += laneWidths[(size_t)laneIndex];
898 } else if (e->myPlacement == PlacementType::MIDDLE_OF) {
899 placementRefOffset += laneWidths[(size_t)laneIndex] / 2.;
900 }
901 double totalWidth = 0;
902 for (double laneWidth : laneWidths) {
903 totalWidth += laneWidth;
904 }
905 placementOffset = totalWidth / 2. - placementRefOffset;
906 applyPlacement = true;
907 }
908 }
909 }
910 if (applyPlacement && fabs(placementOffset) > POSITION_EPS) {
911 try {
912 shape.move2side(placementOffset);
913 } catch (InvalidArgument&) {
914 if (index <= 0) {
915 WRITE_WARNINGF(TL("Ignoring placement for edge '%' because offset shape computation failed."), id);
916 }
917 applyPlacement = false;
918 }
919 }
920
921 const std::string origID = OptionsCont::getOptions().getBool("output.original-names") ? toString(e->id) : "";
922 const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
923 const int offsetFactor = lefthand ? -1 : 1;
924 LaneSpreadFunction lsf = ((addBackward || OptionsCont::getOptions().getBool("osm.oneway-spread-right")) &&
925 ((!isRailway(permissions) || (permissions == SVC_CABLE_CAR && e->myRailDirection == WAY_UNKNOWN)))
927 if (addBackward && lsf == LaneSpreadFunction::RIGHT && OptionsCont::getOptions().getString("default.spreadtype") == toString(LaneSpreadFunction::ROADCENTER)) {
929 }
930 if (addForward && addBackward && lsf == LaneSpreadFunction::RIGHT && explicitOneWay) {
932 }
934 // user defined value overrides defaults
935 lsf = tc.getEdgeTypeSpreadType(type);
936 }
937 if (applyPlacement) {
938 // placement references the directional edge centerline for one-way edges
940 }
941 if (defaults.size() > 0) {
942 e->setParameter("osmDefaults", joinToString(defaults, " "));
943 }
944
945 id = StringUtils::escapeXML(id);
946 const std::string reverseID = "-" + id;
947 if (e->myIsCircularJunction && (addForward || addBackward)) {
950 }
951 const bool markOSMDirection = from->getType() == SumoXMLNodeType::RAIL_SIGNAL || to->getType() == SumoXMLNodeType::RAIL_SIGNAL;
952 if (addForward) {
953 assert(numLanesForward > 0);
954 NBEdge* nbe = new NBEdge(id, from, to, type, speed, NBEdge::UNSPECIFIED_FRICTION, numLanesForward, tc.getEdgeTypePriority(type),
955 forwardWidth, NBEdge::UNSPECIFIED_OFFSET, shape, lsf,
956 StringUtils::escapeXML(streetName), origID, true);
957 if (markOSMDirection) {
959 }
960 nbe->setPermissions(forwardPermissions, -1);
961 if ((e->myBuswayType & WAY_FORWARD) != 0 && (forwardPermissions & SVC_PASSENGER) != 0) {
962 nbe->setPermissions(SVC_BUS, 0);
963 }
965 applyLaneUse(nbe, e, true);
967 nbe->setTurnSignTarget(last->getID());
968 if (addBikeLane && (cyclewayType == WAY_UNKNOWN || (cyclewayType & WAY_FORWARD) != 0)) {
969 nbe->addBikeLane(bikeLaneWidth * offsetFactor);
970 } else if (nbe->getPermissions(0) == SVC_BUS) {
971 // bikes drive on buslanes if no separate cycle lane is available
973 }
974 if ((addSidewalk && (sidewalkType == WAY_UNKNOWN || (sidewalkType & WAY_FORWARD) != 0))
975 || (myImportSidewalks && (sidewalkType & WAY_FORWARD) != 0 && defaultPermissions != SVC_PEDESTRIAN)) {
976 nbe->addSidewalk(sidewalkWidth * offsetFactor);
977 }
978 if (!addBackward && (e->myExtraAllowed & SVC_PEDESTRIAN) != 0 && (nbe->getPermissions(0) & SVC_PEDESTRIAN) == 0) {
979 // Pedestrians are explicitly allowed (maybe through foot="yes") but did not get a sidewalk (maybe through sidewalk="no").
980 // Since we do not have a backward edge, we need to make sure they can at least walk somewhere, see #14124
982 }
984 nbe->setDistance(distanceStart);
986 if (e->myAmInRoundabout) {
987 // ensure roundabout edges have the precedence
990 }
991
992 // process forward lanes width
993 const int numForwardLanesFromWidthKey = (int)e->myWidthLanesForward.size();
994 if (numForwardLanesFromWidthKey > 0 && !OptionsCont::getOptions().getBool("ignore-widths")) {
995 if ((int)nbe->getLanes().size() != numForwardLanesFromWidthKey) {
996 WRITE_WARNINGF(TL("Forward lanes count for edge '%' ('%') is not matching the number of lanes defined in width:lanes:forward key ('%'). Using default width values."),
997 id, nbe->getLanes().size(), numForwardLanesFromWidthKey);
998 } else {
999 for (int i = 0; i < numForwardLanesFromWidthKey; i++) {
1000 const double actualWidth = e->myWidthLanesForward[i] <= 0 ? forwardWidth : e->myWidthLanesForward[i];
1001 const int laneIndex = lefthand ? i : numForwardLanesFromWidthKey - i - 1;
1002 nbe->setLaneWidth(laneIndex, actualWidth);
1003 }
1004 }
1005 }
1006 if ((e->myRailDirection & WAY_PREFER_FORWARD) != 0 && isRailway(forwardPermissions)) {
1007 nbe->setRoutingType("4");
1008 } else {
1009 nbe->setRoutingType(routingType);
1010 }
1011
1012 if (!ec.insert(nbe)) {
1013 delete nbe;
1014 throw ProcessError(TLF("Could not add edge '%'.", id));
1015 }
1016 }
1017 if (addBackward) {
1018 assert(numLanesBackward > 0);
1019 NBEdge* nbe = new NBEdge(reverseID, to, from, type, speedBackward, NBEdge::UNSPECIFIED_FRICTION, numLanesBackward, tc.getEdgeTypePriority(type),
1020 backwardWidth, NBEdge::UNSPECIFIED_OFFSET, shape.reverse(), lsf,
1021 StringUtils::escapeXML(streetName), origID, true);
1022 if (markOSMDirection) {
1024 }
1025 nbe->setPermissions(backwardPermissions);
1026 if ((e->myBuswayType & WAY_BACKWARD) != 0 && (backwardPermissions & SVC_PASSENGER) != 0) {
1027 nbe->setPermissions(SVC_BUS, 0);
1028 }
1030 applyLaneUse(nbe, e, false);
1032 nbe->setTurnSignTarget(first->getID());
1033 if (addBikeLane && (cyclewayType == WAY_UNKNOWN || (cyclewayType & WAY_BACKWARD) != 0)) {
1034 nbe->addBikeLane(bikeLaneWidth * offsetFactor);
1035 } else if (nbe->getPermissions(0) == SVC_BUS) {
1036 // bikes drive on buslanes if no separate cycle lane is available
1038 }
1039 if ((addSidewalk && (sidewalkType == WAY_UNKNOWN || (sidewalkType & WAY_BACKWARD) != 0))
1040 || (myImportSidewalks && (sidewalkType & WAY_BACKWARD) != 0 && defaultPermissions != SVC_PEDESTRIAN)) {
1041 nbe->addSidewalk(sidewalkWidth * offsetFactor);
1042 }
1044 nbe->setDistance(distanceEnd);
1046 if (e->myAmInRoundabout) {
1047 // ensure roundabout edges have the precedence
1050 }
1051 // process backward lanes width
1052 const int numBackwardLanesFromWidthKey = (int)e->myWidthLanesBackward.size();
1053 if (numBackwardLanesFromWidthKey > 0 && !OptionsCont::getOptions().getBool("ignore-widths")) {
1054 if ((int)nbe->getLanes().size() != numBackwardLanesFromWidthKey) {
1055 WRITE_WARNINGF(TL("Backward lanes count for edge '%' ('%') is not matching the number of lanes defined in width:lanes:backward key ('%'). Using default width values."),
1056 id, nbe->getLanes().size(), numBackwardLanesFromWidthKey);
1057 } else {
1058 for (int i = 0; i < numBackwardLanesFromWidthKey; i++) {
1059 const double actualWidth = e->myWidthLanesBackward[i] <= 0 ? backwardWidth : e->myWidthLanesBackward[i];
1060 const int laneIndex = lefthand ? i : numBackwardLanesFromWidthKey - i - 1;
1061 nbe->setLaneWidth(laneIndex, actualWidth);
1062 }
1063 }
1064 }
1065 if ((e->myRailDirection & WAY_PREFER_BACKWARD) != 0 && isRailway(backwardPermissions)) {
1066 nbe->setRoutingType("4");
1067 } else {
1068 nbe->setRoutingType(routingType);
1069 }
1070
1071 if (!ec.insert(nbe)) {
1072 delete nbe;
1073 throw ProcessError(TLF("Could not add edge '-%'.", id));
1074 }
1075 }
1076 if ((e->myParkingType & PARKING_BOTH) != 0 && OptionsCont::getOptions().isSet("parking-output")) {
1077 if ((e->myParkingType & PARKING_RIGHT) != 0) {
1078 if (addForward) {
1079 nb.getParkingCont().push_back(NBParking(id, id));
1080 } else {
1082 if ((e->myParkingType & PARKING_LEFT) == 0 && !addBackward) {
1084 nb.getParkingCont().push_back(NBParking(reverseID, reverseID));
1085 }
1086 }
1087 }
1088 if ((e->myParkingType & PARKING_LEFT) != 0) {
1089 if (addBackward) {
1090 nb.getParkingCont().push_back(NBParking(reverseID, reverseID));
1091 } else {
1093 if ((e->myParkingType & PARKING_RIGHT) == 0 && !addForward) {
1095 nb.getParkingCont().push_back(NBParking(id, id));
1096 }
1097 }
1098 }
1099 }
1100 return newIndex;
1101}
1102
1103
1104void
1106 NBNodeCont& nc = nb.getNodeCont();
1107 NBEdgeCont& ec = nb.getEdgeCont();
1108 // reconstruct elevation from layer info
1109 // build a map of raising and lowering forces (attractor and distance)
1110 // for all nodes unknownElevation
1111 std::map<NBNode*, std::vector<std::pair<double, double> > > layerForces;
1112
1113 // collect all nodes that belong to a way with layer information
1114 std::set<NBNode*> knownElevation;
1115 for (auto& myEdge : myEdges) {
1116 Edge* e = myEdge.second;
1117 if (e->myLayer != 0) {
1118 for (auto j = e->myCurrentNodes.begin(); j != e->myCurrentNodes.end(); ++j) {
1119 NBNode* node = nc.retrieve(toString(*j));
1120 if (node != nullptr) {
1121 knownElevation.insert(node);
1122 layerForces[node].emplace_back(e->myLayer * layerElevation, POSITION_EPS);
1123 }
1124 }
1125 }
1126 }
1127#ifdef DEBUG_LAYER_ELEVATION
1128 std::cout << "known elevations:\n";
1129 for (std::set<NBNode*>::iterator it = knownElevation.begin(); it != knownElevation.end(); ++it) {
1130 const std::vector<std::pair<double, double> >& primaryLayers = layerForces[*it];
1131 std::cout << " node=" << (*it)->getID() << " ele=";
1132 for (std::vector<std::pair<double, double> >::const_iterator it_ele = primaryLayers.begin(); it_ele != primaryLayers.end(); ++it_ele) {
1133 std::cout << it_ele->first << " ";
1134 }
1135 std::cout << "\n";
1136 }
1137#endif
1138 // layer data only provides a lower bound on elevation since it is used to
1139 // resolve the relation among overlapping ways.
1140 // Perform a sanity check for steep inclines and raise the knownElevation if necessary
1141 std::map<NBNode*, double> knownEleMax;
1142 for (auto it : knownElevation) {
1143 double eleMax = -std::numeric_limits<double>::max();
1144 const std::vector<std::pair<double, double> >& primaryLayers = layerForces[it];
1145 for (const auto& primaryLayer : primaryLayers) {
1146 eleMax = MAX2(eleMax, primaryLayer.first);
1147 }
1148 knownEleMax[it] = eleMax;
1149 }
1150 const double gradeThreshold = OptionsCont::getOptions().getFloat("osm.layer-elevation.max-grade") / 100;
1151 bool changed = true;
1152 while (changed) {
1153 changed = false;
1154 for (auto it = knownElevation.begin(); it != knownElevation.end(); ++it) {
1155 std::map<NBNode*, std::pair<double, double> > neighbors = getNeighboringNodes(*it,
1156 knownEleMax[*it]
1157 / gradeThreshold * 3,
1158 knownElevation);
1159 for (auto& neighbor : neighbors) {
1160 if (knownElevation.count(neighbor.first) != 0) {
1161 const double grade = fabs(knownEleMax[*it] - knownEleMax[neighbor.first])
1162 / MAX2(POSITION_EPS, neighbor.second.first);
1163#ifdef DEBUG_LAYER_ELEVATION
1164 std::cout << " grade at node=" << (*it)->getID() << " ele=" << knownEleMax[*it] << " neigh=" << it_neigh->first->getID() << " neighEle=" << knownEleMax[it_neigh->first] << " grade=" << grade << " dist=" << it_neigh->second.first << " speed=" << it_neigh->second.second << "\n";
1165#endif
1166 if (grade > gradeThreshold * 50 / 3.6 / neighbor.second.second) {
1167 // raise the lower node to the higher level
1168 const double eleMax = MAX2(knownEleMax[*it], knownEleMax[neighbor.first]);
1169 if (knownEleMax[*it] < eleMax) {
1170 knownEleMax[*it] = eleMax;
1171 } else {
1172 knownEleMax[neighbor.first] = eleMax;
1173 }
1174 changed = true;
1175 }
1176 }
1177 }
1178 }
1179 }
1180
1181 // collect all nodes within a grade-dependent range around knownElevation-nodes and apply knowElevation forces
1182 std::set<NBNode*> unknownElevation;
1183 for (auto it = knownElevation.begin(); it != knownElevation.end(); ++it) {
1184 const double eleMax = knownEleMax[*it];
1185 const double maxDist = fabs(eleMax) * 100 / layerElevation;
1186 std::map<NBNode*, std::pair<double, double> > neighbors = getNeighboringNodes(*it, maxDist, knownElevation);
1187 for (auto& neighbor : neighbors) {
1188 if (knownElevation.count(neighbor.first) == 0) {
1189 unknownElevation.insert(neighbor.first);
1190 layerForces[neighbor.first].emplace_back(eleMax, neighbor.second.first);
1191 }
1192 }
1193 }
1194
1195 // apply forces to ground-level nodes (neither in knownElevation nor unknownElevation)
1196 for (auto it = unknownElevation.begin(); it != unknownElevation.end(); ++it) {
1197 double eleMax = -std::numeric_limits<double>::max();
1198 const std::vector<std::pair<double, double> >& primaryLayers = layerForces[*it];
1199 for (const auto& primaryLayer : primaryLayers) {
1200 eleMax = MAX2(eleMax, primaryLayer.first);
1201 }
1202 const double maxDist = fabs(eleMax) * 100 / layerElevation;
1203 std::map<NBNode*, std::pair<double, double> > neighbors = getNeighboringNodes(*it, maxDist, knownElevation);
1204 for (auto& neighbor : neighbors) {
1205 if (knownElevation.count(neighbor.first) == 0 && unknownElevation.count(neighbor.first) == 0) {
1206 layerForces[*it].emplace_back(0, neighbor.second.first);
1207 }
1208 }
1209 }
1210 // compute the elevation for each node as the weighted average of all forces
1211#ifdef DEBUG_LAYER_ELEVATION
1212 std::cout << "summation of forces\n";
1213#endif
1214 std::map<NBNode*, double> nodeElevation;
1215 for (auto& layerForce : layerForces) {
1216 const std::vector<std::pair<double, double> >& forces = layerForce.second;
1217 if (knownElevation.count(layerForce.first) != 0) {
1218 // use the maximum value
1219 /*
1220 double eleMax = -std::numeric_limits<double>::max();
1221 for (std::vector<std::pair<double, double> >::const_iterator it_force = forces.begin(); it_force != forces.end(); ++it_force) {
1222 eleMax = MAX2(eleMax, it_force->first);
1223 }
1224 */
1225#ifdef DEBUG_LAYER_ELEVATION
1226 std::cout << " node=" << it->first->getID() << " knownElevation=" << knownEleMax[it->first] << "\n";
1227#endif
1228 nodeElevation[layerForce.first] = knownEleMax[layerForce.first];
1229 } else if (forces.size() == 1) {
1230 nodeElevation[layerForce.first] = forces.front().first;
1231 } else {
1232 // use the weighted sum
1233 double distSum = 0;
1234 for (const auto& force : forces) {
1235 distSum += force.second;
1236 }
1237 double weightSum = 0;
1238 double elevation = 0;
1239#ifdef DEBUG_LAYER_ELEVATION
1240 std::cout << " node=" << it->first->getID() << " distSum=" << distSum << "\n";
1241#endif
1242 for (const auto& force : forces) {
1243 const double weight = (distSum - force.second) / distSum;
1244 weightSum += weight;
1245 elevation += force.first * weight;
1246
1247#ifdef DEBUG_LAYER_ELEVATION
1248 std::cout << " force=" << it_force->first << " dist=" << it_force->second << " weight=" << weight << " ele=" << elevation << "\n";
1249#endif
1250 }
1251 nodeElevation[layerForce.first] = elevation / weightSum;
1252 }
1253 }
1254#ifdef DEBUG_LAYER_ELEVATION
1255 std::cout << "final elevations:\n";
1256 for (std::map<NBNode*, double>::iterator it = nodeElevation.begin(); it != nodeElevation.end(); ++it) {
1257 std::cout << " node=" << (it->first)->getID() << " ele=" << it->second << "\n";
1258 }
1259#endif
1260 // apply node elevations
1261 for (auto& it : nodeElevation) {
1262 NBNode* n = it.first;
1263 n->reinit(n->getPosition() + Position(0, 0, it.second), n->getType());
1264 }
1265
1266 // apply way elevation to all edges that had layer information
1267 for (const auto& it : ec) {
1268 NBEdge* edge = it.second;
1269 const PositionVector& geom = edge->getGeometry();
1270 const double length = geom.length2D();
1271 const double zFrom = nodeElevation[edge->getFromNode()];
1272 const double zTo = nodeElevation[edge->getToNode()];
1273 // XXX if the from- or to-node was part of multiple ways with
1274 // different layers, reconstruct the layer value from origID
1275 double dist = 0;
1276 PositionVector newGeom;
1277 for (auto it_pos = geom.begin(); it_pos != geom.end(); ++it_pos) {
1278 if (it_pos != geom.begin()) {
1279 dist += (*it_pos).distanceTo2D(*(it_pos - 1));
1280 }
1281 newGeom.push_back((*it_pos) + Position(0, 0, zFrom + (zTo - zFrom) * dist / length));
1282 }
1283 edge->setGeometry(newGeom);
1284 }
1285}
1286
1287std::map<NBNode*, std::pair<double, double> >
1288NIImporter_OpenStreetMap::getNeighboringNodes(NBNode* node, double maxDist, const std::set<NBNode*>& knownElevation) {
1289 std::map<NBNode*, std::pair<double, double> > result;
1290 std::set<NBNode*> visited;
1291 std::vector<NBNode*> open;
1292 open.push_back(node);
1293 result[node] = std::make_pair(0, 0);
1294 while (!open.empty()) {
1295 NBNode* n = open.back();
1296 open.pop_back();
1297 if (visited.count(n) != 0) {
1298 continue;
1299 }
1300 visited.insert(n);
1301 const EdgeVector& edges = n->getEdges();
1302 for (auto e : edges) {
1303 NBNode* s = nullptr;
1304 if (n->hasIncoming(e)) {
1305 s = e->getFromNode();
1306 } else {
1307 s = e->getToNode();
1308 }
1309 const double dist = result[n].first + e->getGeometry().length2D();
1310 const double speed = MAX2(e->getSpeed(), result[n].second);
1311 if (result.count(s) == 0) {
1312 result[s] = std::make_pair(dist, speed);
1313 } else {
1314 result[s] = std::make_pair(MIN2(dist, result[s].first), MAX2(speed, result[s].second));
1315 }
1316 if (dist < maxDist && knownElevation.count(s) == 0) {
1317 open.push_back(s);
1318 }
1319 }
1320 }
1321 result.erase(node);
1322 return result;
1323}
1324
1325
1326std::string
1327NIImporter_OpenStreetMap::usableType(const std::string& type, const std::string& id, NBTypeCont& tc) {
1328 if (tc.knows(type)) {
1329 return type;
1330 }
1331 if (myUnusableTypes.count(type) > 0) {
1332 return "";
1333 }
1334 if (myKnownCompoundTypes.count(type) > 0) {
1335 return myKnownCompoundTypes[type];
1336 }
1337 // this edge has a type which does not yet exist in the TypeContainer
1339 std::vector<std::string> types;
1340 while (tok.hasNext()) {
1341 std::string t = tok.next();
1342 if (tc.knows(t)) {
1343 if (std::find(types.begin(), types.end(), t) == types.end()) {
1344 types.push_back(t);
1345 }
1346 } else if (tok.size() > 1) {
1347 if (!StringUtils::startsWith(t, "service.")) {
1348 WRITE_WARNINGF(TL("Discarding unknown compound '%' in type '%' (first occurrence for edge '%')."), t, type, id);
1349 }
1350 }
1351 }
1352 if (types.empty()) {
1353 if (!StringUtils::startsWith(type, "service.")) {
1354 WRITE_WARNINGF(TL("Discarding unusable type '%' (first occurrence for edge '%')."), type, id);
1355 }
1356 myUnusableTypes.insert(type);
1357 return "";
1358 }
1359 const std::string newType = joinToString(types, "|");
1360 if (tc.knows(newType)) {
1361 myKnownCompoundTypes[type] = newType;
1362 return newType;
1363 } else if (myKnownCompoundTypes.count(newType) > 0) {
1364 return myKnownCompoundTypes[newType];
1365 } else {
1366 // build a new type by merging all values
1367 int numLanes = 0;
1368 double maxSpeed = 0;
1369 int prio = 0;
1370 double width = NBEdge::UNSPECIFIED_WIDTH;
1371 double sidewalkWidth = NBEdge::UNSPECIFIED_WIDTH;
1372 double bikelaneWidth = NBEdge::UNSPECIFIED_WIDTH;
1373 bool defaultIsOneWay = true;
1374 SVCPermissions permissions = 0;
1376 bool discard = true;
1377 bool hadDiscard = false;
1378 for (auto& type2 : types) {
1379 if (!tc.getEdgeTypeShallBeDiscarded(type2)) {
1380 numLanes = MAX2(numLanes, tc.getEdgeTypeNumLanes(type2));
1381 maxSpeed = MAX2(maxSpeed, tc.getEdgeTypeSpeed(type2));
1382 prio = MAX2(prio, tc.getEdgeTypePriority(type2));
1383 defaultIsOneWay &= tc.getEdgeTypeIsOneWay(type2);
1384 //std::cout << "merging component " << type2 << " into type " << newType << " allows=" << getVehicleClassNames(tc.getPermissions(type2)) << " oneway=" << defaultIsOneWay << "\n";
1385 permissions |= tc.getEdgeTypePermissions(type2);
1386 spreadType = tc.getEdgeTypeSpreadType(type2);
1387 width = MAX2(width, tc.getEdgeTypeWidth(type2));
1388 sidewalkWidth = MAX2(sidewalkWidth, tc.getEdgeTypeSidewalkWidth(type2));
1389 bikelaneWidth = MAX2(bikelaneWidth, tc.getEdgeTypeBikeLaneWidth(type2));
1390 discard = false;
1391 } else {
1392 hadDiscard = true;
1393 }
1394 }
1395 if (hadDiscard && permissions == 0) {
1396 discard = true;
1397 }
1398 if (discard) {
1399 WRITE_WARNINGF(TL("Discarding compound type '%' (first occurrence for edge '%')."), newType, id);
1400 myUnusableTypes.insert(newType);
1401 return "";
1402 }
1403 if (width != NBEdge::UNSPECIFIED_WIDTH) {
1404 width = MAX2(width, SUMO_const_laneWidth);
1405 }
1406 // ensure pedestrians don't run into trains
1407 if (sidewalkWidth == NBEdge::UNSPECIFIED_WIDTH
1408 && (permissions & SVC_PEDESTRIAN) != 0
1409 && (permissions & SVC_RAIL_CLASSES) != 0) {
1410 //std::cout << "patching sidewalk for type '" << newType << "' which allows=" << getVehicleClassNames(permissions) << "\n";
1411 sidewalkWidth = OptionsCont::getOptions().getFloat("default.sidewalk-width");
1412 }
1413
1414 WRITE_MESSAGEF(TL("Adding new type '%' (first occurrence for edge '%')."), type, id);
1415 tc.insertEdgeType(newType, numLanes, maxSpeed, prio, permissions, spreadType, width,
1416 defaultIsOneWay, sidewalkWidth, bikelaneWidth, 0, 0, 0);
1417 for (auto& type3 : types) {
1418 if (!tc.getEdgeTypeShallBeDiscarded(type3)) {
1419 tc.copyEdgeTypeRestrictionsAndAttrs(type3, newType);
1420 }
1421 }
1422 myKnownCompoundTypes[type] = newType;
1423 return newType;
1424 }
1425}
1426
1427void
1429 const std::string id = toString(e->id);
1430 std::string type = usableType(e->myHighWayType, id, tc);
1431 if (type != "" && isRailway(tc.getEdgeTypePermissions(type))) {
1432 std::vector<NIOSMNode*> nodes;
1433 std::vector<double> usablePositions;
1434 std::vector<int> usableIndex;
1435 for (long long int n : e->myCurrentNodes) {
1438 if (node->positionMeters != std::numeric_limits<double>::max()) {
1439 usablePositions.push_back(node->positionMeters);
1440 usableIndex.push_back((int)nodes.size());
1441 }
1442 nodes.push_back(node);
1443 }
1444 if (usablePositions.size() == 0) {
1445 return;
1446 } else {
1447 bool forward = true;
1448 if (usablePositions.size() == 1) {
1449 WRITE_WARNINGF(TL("Ambiguous railway kilometrage direction for way '%' (assuming forward)"), id);
1450 } else {
1451 forward = usablePositions.front() < usablePositions.back();
1452 }
1453 // check for consistency
1454 for (int i = 1; i < (int)usablePositions.size(); i++) {
1455 if ((usablePositions[i - 1] < usablePositions[i]) != forward) {
1456 WRITE_WARNINGF(TL("Inconsistent railway kilometrage direction for way '%': % (skipping)"), id, toString(usablePositions));
1457 return;
1458 }
1459 }
1460 if (nodes.size() > usablePositions.size()) {
1461 // complete missing values
1462 PositionVector shape;
1463 for (NIOSMNode* node : nodes) {
1464 shape.push_back(Position(node->lon, node->lat, 0));
1465 }
1467 return; // error will be given later
1468 }
1469 double sign = forward ? 1 : -1;
1470 // extend backward before first usable value
1471 for (int i = usableIndex.front() - 1; i >= 0; i--) {
1472 nodes[i]->positionMeters = nodes[i + 1]->positionMeters - sign * shape[i].distanceTo2D(shape[i + 1]);
1473 }
1474 // extend forward
1475 for (int i = usableIndex.front() + 1; i < (int)nodes.size(); i++) {
1476 if (nodes[i]->positionMeters == std::numeric_limits<double>::max()) {
1477 nodes[i]->positionMeters = nodes[i - 1]->positionMeters + sign * shape[i].distanceTo2D(shape[i - 1]);
1478 }
1479 }
1480 //std::cout << " way=" << id << " usable=" << toString(usablePositions) << "\n indices=" << toString(usableIndex)
1481 // << " final:\n";
1482 //for (auto n : nodes) {
1483 // std::cout << " " << n->id << " " << n->positionMeters << " " << n->position<< "\n";
1484 //}
1485 }
1486 }
1487 }
1488}
1489
1490
1491double
1493 if (node->position.size() > 0) {
1494 try {
1495 if (StringUtils::startsWith(node->position, "mi:")) {
1496 return StringUtils::toDouble(node->position.substr(3)) * 1609.344; // meters per mile
1497 } else {
1498 return StringUtils::toDouble(node->position) * 1000;
1499 }
1500 } catch (...) {
1501 WRITE_WARNINGF(TL("Value of railway:position is not numeric ('%') in node '%'."), node->position, toString(node->id));
1502 }
1503 }
1504 return std::numeric_limits<double>::max();
1505}
1506
1510 if (type == "train") {
1511 result = SVC_RAIL;
1512 } else if (type == "subway") {
1513 result = SVC_SUBWAY;
1514 } else if (type == "aerialway") {
1515 result = SVC_CABLE_CAR;
1516 } else if (type == "light_rail" || type == "monorail") {
1517 result = SVC_RAIL_URBAN;
1518 } else if (type == "share_taxi") {
1519 result = SVC_TAXI;
1520 } else if (type == "minibus") {
1521 result = SVC_BUS;
1522 } else if (type == "trolleybus") {
1523 result = SVC_BUS;
1524 } else if (SumoVehicleClassStrings.hasString(type)) {
1525 result = SumoVehicleClassStrings.get(type);
1526 }
1527 std::string stop = "";
1528 if (result == SVC_TRAM) {
1529 stop = ".tram";
1530 } else if (result == SVC_BUS) {
1531 stop = ".bus";
1532 } else if (isRailway(result)) {
1533 stop = ".train";
1534 }
1535 if (toSet != nullptr && result != SVC_IGNORING) {
1536 toSet->permissions |= result;
1537 toSet->ptStopLength = OptionsCont::getOptions().getFloat("osm.stop-output.length" + stop);
1538 }
1539 return result;
1540}
1541
1542
1543void
1545 bool multiLane = changeProhibition > 3;
1546 //std::cout << "applyChangeProhibition e=" << e->getID() << " changeProhibition=" << std::bitset<32>(changeProhibition) << " val=" << changeProhibition << "\n";
1547 for (int lane = 0; changeProhibition > 0 && lane < e->getNumLanes(); lane++) {
1548 int code = changeProhibition % 4; // only look at the last 2 bits
1549 SVCPermissions changeLeft = (code & CHANGE_NO_LEFT) == 0 ? SVCAll : (SVCPermissions)SVC_AUTHORITY;
1550 SVCPermissions changeRight = (code & CHANGE_NO_RIGHT) == 0 ? SVCAll : (SVCPermissions)SVC_AUTHORITY;
1551 e->setPermittedChanging(lane, changeLeft, changeRight);
1552 if (multiLane) {
1553 changeProhibition = changeProhibition >> 2;
1554 }
1555 }
1556}
1557
1558
1559void
1561 if (myImportLaneAccess) {
1562 const int numLanes = e->getNumLanes();
1563 const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
1564 const std::vector<bool>& designated = forward ? nie->myDesignatedLaneForward : nie->myDesignatedLaneBackward;
1565 const std::vector<SVCPermissions>& allowed = forward ? nie->myAllowedLaneForward : nie->myAllowedLaneBackward;
1566 const std::vector<SVCPermissions>& disallowed = forward ? nie->myDisallowedLaneForward : nie->myDisallowedLaneBackward;
1567 // lanes:bus* / lanes:psv* fallback on curb lane(s) when no explicit bus:lanes* / psv:lanes* tag was present (#10406)
1568 const Edge::DirLaneInfo& dir = forward ? nie->myDirForward : nie->myDirBackward;
1569 if (dir.busLanes > 0 && !dir.hasBusSpec && dir.busClasses != 0) {
1570 for (int lane = 0; lane < MIN2(numLanes, dir.busLanes); lane++) {
1571 e->setPermissions(dir.busClasses, lane);
1572 e->preferVehicleClass(lane, dir.busClasses);
1573 }
1574 }
1575 for (int lane = 0; lane < numLanes; lane++) {
1576 // laneUse stores from left to right
1577 const int i = lefthand ? lane : numLanes - 1 - lane;
1578 // Extra allowed SVCs for this lane or none if no info was present for the lane
1579 const SVCPermissions extraAllowed = i < (int)allowed.size() ? allowed[i] : (SVCPermissions)SVC_IGNORING;
1580 // Extra disallowed SVCs for this lane or none if no info was present for the lane
1581 const SVCPermissions extraDisallowed = i < (int)disallowed.size() ? disallowed[i] : (SVCPermissions)SVC_IGNORING;
1582 if (i < (int)designated.size() && designated[i]) {
1583 // if designated, delete all permissions
1584 e->setPermissions(SVC_IGNORING, lane);
1585 e->preferVehicleClass(lane, extraAllowed);
1586 }
1587 e->setPermissions((e->getPermissions(lane) | extraAllowed) & (~extraDisallowed), lane);
1588 }
1589 }
1590}
1591
1592void
1593NIImporter_OpenStreetMap::mergeTurnSigns(std::vector<int>& signs, std::vector<int> signs2) {
1594 if (signs.empty()) {
1595 signs.insert(signs.begin(), signs2.begin(), signs2.end());
1596 } else {
1597 for (int i = 0; i < (int)MIN2(signs.size(), signs2.size()); i++) {
1598 signs[i] |= signs2[i];
1599 }
1600 }
1601}
1602
1603
1604void
1605NIImporter_OpenStreetMap::applyTurnSigns(NBEdge* e, const std::vector<int>& turnSigns) {
1606 if (myImportTurnSigns && turnSigns.size() > 0) {
1607 // no sidewalks and bike lanes have been added yet
1608 if ((int)turnSigns.size() == e->getNumLanes()) {
1609 //std::cout << "apply turnSigns for " << e->getID() << " turnSigns=" << toString(turnSigns) << "\n";
1610 for (int i = 0; i < (int)turnSigns.size(); i++) {
1611 // laneUse stores from left to right
1612 const int laneIndex = e->getNumLanes() - 1 - i;
1613 NBEdge::Lane& lane = e->getLaneStruct(laneIndex);
1614 lane.turnSigns = turnSigns[i];
1615 }
1616 } else {
1617 WRITE_WARNINGF(TL("Ignoring turn sign information for % lanes on edge % with % driving lanes"), turnSigns.size(), e->getID(), e->getNumLanes());
1618 }
1619 }
1620}
1621
1622
1623// ---------------------------------------------------------------------------
1624// definitions of NIImporter_OpenStreetMap::NodesHandler-methods
1625// ---------------------------------------------------------------------------
1626NIImporter_OpenStreetMap::NodesHandler::NodesHandler(std::map<long long int, NIOSMNode*>& toFill,
1627 std::set<NIOSMNode*, CompareNodes>& uniqueNodes, const OptionsCont& oc) :
1628 SUMOSAXHandler("osm - file"),
1629 myToFill(toFill),
1630 myCurrentNode(nullptr),
1631 myIsStation(false),
1632 myHierarchyLevel(0),
1633 myUniqueNodes(uniqueNodes),
1634 myImportElevation(oc.getBool("osm.elevation")),
1635 myDuplicateNodes(0),
1636 myOptionsCont(oc) {
1637 // init rail signal rules
1638 for (std::string kv : oc.getStringVector("osm.railsignals")) {
1639 if (kv == "DEFAULT") {
1640 myRailSignalRules.push_back("railway:signal:main=");
1641 myRailSignalRules.push_back("railway:signal:combined=");
1642 } else if (kv == "ALL") {
1643 myRailSignalRules.push_back("railway=signal");
1644 } else {
1645 myRailSignalRules.push_back("railway:signal:" + kv);
1646 }
1647 }
1648}
1649
1650
1652
1653void
1655 ++myHierarchyLevel;
1656 if (element == SUMO_TAG_NODE) {
1657 bool ok = true;
1658 myLastNodeID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
1659 if (myHierarchyLevel != 2) {
1660 WRITE_ERROR("Node element on wrong XML hierarchy level (id='" + myLastNodeID +
1661 "', level='" + toString(myHierarchyLevel) + "').");
1662 return;
1663 }
1664 const std::string& action = attrs.getOpt<std::string>(SUMO_ATTR_ACTION, myLastNodeID.c_str(), ok);
1665 if (action == "delete" || !ok) {
1666 return;
1667 }
1668 try {
1669 // we do not use attrs.get here to save some time on parsing
1670 const long long int id = StringUtils::toLong(myLastNodeID);
1671 myCurrentNode = nullptr;
1672 const auto insertionIt = myToFill.lower_bound(id);
1673 if (insertionIt == myToFill.end() || insertionIt->first != id) {
1674 // assume we are loading multiple files, so we won't report duplicate nodes
1675 const double tlon = attrs.get<double>(SUMO_ATTR_LON, myLastNodeID.c_str(), ok);
1676 const double tlat = attrs.get<double>(SUMO_ATTR_LAT, myLastNodeID.c_str(), ok);
1677 if (!ok) {
1678 return;
1679 }
1680 myCurrentNode = new NIOSMNode(id, tlon, tlat);
1681 auto similarNode = myUniqueNodes.find(myCurrentNode);
1682 if (similarNode == myUniqueNodes.end()) {
1683 myUniqueNodes.insert(myCurrentNode);
1684 } else {
1685 delete myCurrentNode;
1686 myCurrentNode = *similarNode;
1687 myDuplicateNodes++;
1688 }
1689 myToFill.emplace_hint(insertionIt, id, myCurrentNode);
1690 }
1691 } catch (FormatException&) {
1692 WRITE_ERROR(TL("Attribute 'id' in the definition of a node is not of type long long int."));
1693 return;
1694 }
1695 }
1696 if (element == SUMO_TAG_TAG && myCurrentNode != nullptr) {
1697 if (myHierarchyLevel != 3) {
1698 WRITE_ERROR(TL("Tag element on wrong XML hierarchy level."));
1699 return;
1700 }
1701 bool ok = true;
1702 const std::string& key = attrs.get<std::string>(SUMO_ATTR_K, myLastNodeID.c_str(), ok, false);
1703 // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
1704 if (key == "highway" || key == "ele" || key == "crossing" || key == "railway" || key == "public_transport"
1705 || key == "name" || key == "train" || key == "bus" || key == "tram" || key == "light_rail" || key == "subway" || key == "station" || key == "noexit"
1706 || key == "crossing:barrier"
1707 || key == "crossing:light"
1708 || key == "railway:ref"
1709 || StringUtils::startsWith(key, "railway:signal")
1710 || StringUtils::startsWith(key, "railway:position")
1711 ) {
1712 const std::string& value = attrs.get<std::string>(SUMO_ATTR_V, myLastNodeID.c_str(), ok, false);
1713 if (key == "highway" && value.find("traffic_signal") != std::string::npos) {
1714 myCurrentNode->tlsControlled = true;
1715 } else if (key == "crossing" && value.find("traffic_signals") != std::string::npos) {
1716 myCurrentNode->tlsControlled = true;
1717 } else if (key == "highway" && value.find("crossing") != std::string::npos) {
1718 myCurrentNode->pedestrianCrossing = true;
1719 } else if ((key == "noexit" && value == "yes")
1720 || (key == "railway" && value == "buffer_stop")) {
1721 myCurrentNode->railwayBufferStop = true;
1722 } else if (key == "railway" && value.find("crossing") != std::string::npos) {
1723 myCurrentNode->railwayCrossing = true;
1724 } else if (key == "crossing:barrier") {
1725 myCurrentNode->setParameter("crossing:barrier", value);
1726 } else if (key == "crossing:light") {
1727 myCurrentNode->setParameter("crossing:light", value);
1728 } else if (key == "railway:signal:direction") {
1729 if (value == "both") {
1730 myCurrentNode->myRailDirection = WAY_BOTH;
1731 } else if (value == "backward") {
1732 myCurrentNode->myRailDirection = WAY_BACKWARD;
1733 } else if (value == "forward") {
1734 myCurrentNode->myRailDirection = WAY_FORWARD;
1735 }
1736 } else if (StringUtils::startsWith(key, "railway:signal") || (key == "railway" && value == "signal")) {
1737 std::string kv = key + "=" + value;
1738 std::string kglob = key + "=";
1739 if (key == "railway:signal:train_protection" && value == "DE-ESO:ne14") {
1740 myCurrentNode->railwaySignal |= SIGNAL_ETCS_BLOCK;
1741 } else if (myCurrentNode->railwaySignal == SIGNAL_NONE) {
1742 if ((std::find(myRailSignalRules.begin(), myRailSignalRules.end(), kv) != myRailSignalRules.end())
1743 || (std::find(myRailSignalRules.begin(), myRailSignalRules.end(), kglob) != myRailSignalRules.end())) {
1744 myCurrentNode->railwaySignal = SIGNAL_MAIN;
1745 }
1746 }
1747 } else if (StringUtils::startsWith(key, "railway:position") && value.size() > myCurrentNode->position.size()) {
1748 // use the entry with the highest precision (more digits)
1749 myCurrentNode->position = value;
1750 } else if ((key == "public_transport" && value == "stop_position") ||
1751 (key == "highway" && value == "bus_stop")) {
1752 myCurrentNode->ptStopPosition = true;
1753 if (myCurrentNode->ptStopLength == 0) {
1754 // default length
1755 myCurrentNode->ptStopLength = myOptionsCont.getFloat("osm.stop-output.length");
1756 }
1757 } else if (key == "name") {
1758 myCurrentNode->name = value;
1759 } else if (myImportElevation && key == "ele") {
1760 try {
1761 const double elevation = StringUtils::parseDist(value);
1762 if (std::isnan(elevation)) {
1763 WRITE_WARNINGF(TL("Value of key '%' is invalid ('%') in node '%'."), key, value, myLastNodeID);
1764 } else {
1765 myCurrentNode->ele = elevation;
1766 }
1767 } catch (...) {
1768 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in node '%'."), key, value, myLastNodeID);
1769 }
1770 } else if (key == "station") {
1771 interpretTransportType(value, myCurrentNode);
1772 myIsStation = true;
1773 } else if (key == "railway:ref") {
1774 myRailwayRef = value;
1775 } else {
1776 // v="yes"
1777 interpretTransportType(key, myCurrentNode);
1778 }
1779 }
1780 if (myAllAttributes && (myExtraAttributes.count(key) != 0 || myExtraAttributes.size() == 0)) {
1781 const std::string info = "node=" + toString(myCurrentNode->id) + ", k=" + key;
1782 myCurrentNode->setParameter(key, attrs.get<std::string>(SUMO_ATTR_V, info.c_str(), ok, false));
1783 }
1784 }
1785}
1786
1787
1788void
1790 if (element == SUMO_TAG_NODE && myHierarchyLevel == 2) {
1791 if (myIsStation && myRailwayRef != "") {
1792 myCurrentNode->setParameter("railway:ref", myRailwayRef);
1793 }
1794 myCurrentNode = nullptr;
1795 myIsStation = false;
1796 myRailwayRef = "";
1797 }
1798 --myHierarchyLevel;
1799}
1800
1801
1802// ---------------------------------------------------------------------------
1803// definitions of NIImporter_OpenStreetMap::EdgesHandler-methods
1804// ---------------------------------------------------------------------------
1806 const std::map<long long int, NIOSMNode*>& osmNodes,
1807 std::map<long long int, Edge*>& toFill, std::map<long long int, Edge*>& platformShapes,
1808 const NBTypeCont& tc):
1809 SUMOSAXHandler("osm - file"),
1810 myOSMNodes(osmNodes),
1811 myEdgeMap(toFill),
1812 myPlatformShapesMap(platformShapes),
1813 myTypeCont(tc) {
1814
1815 const double unlimitedSpeed = OptionsCont::getOptions().getFloat("osm.speedlimit-none");
1816
1818 mySpeedMap["sign"] = MAXSPEED_UNGIVEN;
1819 mySpeedMap["signals"] = MAXSPEED_UNGIVEN;
1820 mySpeedMap["none"] = unlimitedSpeed;
1821 mySpeedMap["no"] = unlimitedSpeed;
1822 mySpeedMap["walk"] = 5. / 3.6;
1823 // https://wiki.openstreetmap.org/wiki/Key:source:maxspeed#Commonly_used_values
1824 mySpeedMap["AT:urban"] = 50. / 3.6;
1825 mySpeedMap["AT:rural"] = 100. / 3.6;
1826 mySpeedMap["AT:trunk"] = 100. / 3.6;
1827 mySpeedMap["AT:motorway"] = 130. / 3.6;
1828 mySpeedMap["AU:urban"] = 50. / 3.6;
1829 mySpeedMap["BE:urban"] = 50. / 3.6;
1830 mySpeedMap["BE:zone"] = 30. / 3.6;
1831 mySpeedMap["BE:motorway"] = 120. / 3.6;
1832 mySpeedMap["BE:zone30"] = 30. / 3.6;
1833 mySpeedMap["BE-VLG:rural"] = 70. / 3.6;
1834 mySpeedMap["BE-WAL:rural"] = 90. / 3.6;
1835 mySpeedMap["BE:school"] = 30. / 3.6;
1836 mySpeedMap["CZ:motorway"] = 130. / 3.6;
1837 mySpeedMap["CZ:trunk"] = 110. / 3.6;
1838 mySpeedMap["CZ:rural"] = 90. / 3.6;
1839 mySpeedMap["CZ:urban_motorway"] = 80. / 3.6;
1840 mySpeedMap["CZ:urban_trunk"] = 80. / 3.6;
1841 mySpeedMap["CZ:urban"] = 50. / 3.6;
1842 mySpeedMap["DE:motorway"] = unlimitedSpeed;
1843 mySpeedMap["DE:rural"] = 100. / 3.6;
1844 mySpeedMap["DE:urban"] = 50. / 3.6;
1845 mySpeedMap["DE:bicycle_road"] = 30. / 3.6;
1846 mySpeedMap["DK:motorway"] = 130. / 3.6;
1847 mySpeedMap["DK:rural"] = 80. / 3.6;
1848 mySpeedMap["DK:urban"] = 50. / 3.6;
1849 mySpeedMap["EE:urban"] = 50. / 3.6;
1850 mySpeedMap["EE:rural"] = 90. / 3.6;
1851 mySpeedMap["ES:urban"] = 50. / 3.6;
1852 mySpeedMap["ES:zone30"] = 30. / 3.6;
1853 mySpeedMap["FR:motorway"] = 130. / 3.6; // 110 (raining)
1854 mySpeedMap["FR:rural"] = 80. / 3.6;
1855 mySpeedMap["FR:urban"] = 50. / 3.6;
1856 mySpeedMap["FR:zone30"] = 30. / 3.6;
1857 mySpeedMap["HU:living_street"] = 20. / 3.6;
1858 mySpeedMap["HU:motorway"] = 130. / 3.6;
1859 mySpeedMap["HU:rural"] = 90. / 3.6;
1860 mySpeedMap["HU:trunk"] = 110. / 3.6;
1861 mySpeedMap["HU:urban"] = 50. / 3.6;
1862 mySpeedMap["IT:rural"] = 90. / 3.6;
1863 mySpeedMap["IT:motorway"] = 130. / 3.6;
1864 mySpeedMap["IT:urban"] = 50. / 3.6;
1865 mySpeedMap["JP:nsl"] = 60. / 3.6;
1866 mySpeedMap["JP:express"] = 100. / 3.6;
1867 mySpeedMap["LT:rural"] = 90. / 3.6;
1868 mySpeedMap["LT:urban"] = 50. / 3.6;
1869 mySpeedMap["NO:rural"] = 80. / 3.6;
1870 mySpeedMap["NO:urban"] = 50. / 3.6;
1871 mySpeedMap["ON:urban"] = 50. / 3.6;
1872 mySpeedMap["ON:rural"] = 80. / 3.6;
1873 mySpeedMap["PT:motorway"] = 120. / 3.6;
1874 mySpeedMap["PT:rural"] = 90. / 3.6;
1875 mySpeedMap["PT:trunk"] = 100. / 3.6;
1876 mySpeedMap["PT:urban"] = 50. / 3.6;
1877 mySpeedMap["RO:motorway"] = 130. / 3.6;
1878 mySpeedMap["RO:rural"] = 90. / 3.6;
1879 mySpeedMap["RO:trunk"] = 100. / 3.6;
1880 mySpeedMap["RO:urban"] = 50. / 3.6;
1881 mySpeedMap["RS:living_street"] = 30. / 3.6;
1882 mySpeedMap["RS:motorway"] = 130. / 3.6;
1883 mySpeedMap["RS:rural"] = 80. / 3.6;
1884 mySpeedMap["RS:trunk"] = 100. / 3.6;
1885 mySpeedMap["RS:urban"] = 50. / 3.6;
1886 mySpeedMap["RU:living_street"] = 20. / 3.6;
1887 mySpeedMap["RU:urban"] = 60. / 3.6;
1888 mySpeedMap["RU:rural"] = 90. / 3.6;
1889 mySpeedMap["RU:motorway"] = 110. / 3.6;
1890 const double seventy = StringUtils::parseSpeed("70mph");
1891 const double sixty = StringUtils::parseSpeed("60mph");
1892 mySpeedMap["GB:motorway"] = seventy;
1893 mySpeedMap["GB:nsl_dual"] = seventy;
1894 mySpeedMap["GB:nsl_single"] = sixty;
1895 mySpeedMap["UK:motorway"] = seventy;
1896 mySpeedMap["UK:nsl_dual"] = seventy;
1897 mySpeedMap["UK:nsl_single"] = sixty;
1898 mySpeedMap["UZ:living_street"] = 30. / 3.6;
1899 mySpeedMap["UZ:urban"] = 70. / 3.6;
1900 mySpeedMap["UZ:rural"] = 100. / 3.6;
1901 mySpeedMap["UZ:motorway"] = 110. / 3.6;
1902}
1903
1905
1906void
1908 if (element == SUMO_TAG_WAY) {
1909 bool ok = true;
1910 const long long int id = attrs.get<long long int>(SUMO_ATTR_ID, nullptr, ok);
1911 const std::string& action = attrs.getOpt<std::string>(SUMO_ATTR_ACTION, nullptr, ok);
1912 if (action == "delete" || !ok) {
1913 myCurrentEdge = nullptr;
1914 return;
1915 }
1916 myCurrentEdge = new Edge(id);
1917 resetWayStaging();
1918 }
1919 // parse "nd" (node) elements
1920 if (element == SUMO_TAG_ND && myCurrentEdge != nullptr) {
1921 bool ok = true;
1922 long long int ref = attrs.get<long long int>(SUMO_ATTR_REF, nullptr, ok);
1923 if (ok) {
1924 auto node = myOSMNodes.find(ref);
1925 if (node == myOSMNodes.end()) {
1926 WRITE_WARNINGF(TL("The referenced geometry information (ref='%') is not known"), toString(ref));
1927 return;
1928 }
1929
1930 ref = node->second->id; // node may have been substituted
1931 if (myCurrentEdge->myCurrentNodes.empty() ||
1932 myCurrentEdge->myCurrentNodes.back() != ref) { // avoid consecutive duplicates
1933 myCurrentEdge->myCurrentNodes.push_back(ref);
1934 }
1935
1936 }
1937 }
1938 if (element == SUMO_TAG_TAG && myCurrentEdge != nullptr) {
1939 bool ok = true;
1940 std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myCurrentEdge->id).c_str(), ok, false);
1941 std::string buswaySpec;
1942 if (key.size() > 6 && StringUtils::startsWith(key, "busway:")) {
1943 // handle special busway keys
1944 buswaySpec = key.substr(7);
1945 if (buswaySpec == "right" || buswaySpec == "left" || buswaySpec == "both") {
1946 key = "busway";
1947 } else {
1948 key = "ignore";
1949 }
1950 }
1951 if (myAllAttributes && (myExtraAttributes.count(key) != 0 || myExtraAttributes.size() == 0)) {
1952 const std::string info = "way=" + toString(myCurrentEdge->id) + ", k=" + key;
1953 myCurrentEdge->setParameter(key, attrs.get<std::string>(SUMO_ATTR_V, info.c_str(), ok, false));
1954 }
1955 // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
1956 if (!StringUtils::endsWith(key, "way")
1957 && !StringUtils::startsWith(key, "lanes")
1958 && key != "maxspeed" && key != "maxspeed:type"
1959 && key != "zone:maxspeed"
1960 && key != "maxspeed:forward" && key != "maxspeed:backward"
1961 && key != "junction" && key != "name" && key != "tracks" && key != "layer"
1962 && key != "route"
1963 && !StringUtils::startsWith(key, "cycleway")
1964 && !StringUtils::startsWith(key, "sidewalk")
1965 && key != "ref"
1966 && key != "highspeed"
1967 && !StringUtils::startsWith(key, "parking")
1968 && !StringUtils::startsWith(key, "change")
1969 && !StringUtils::startsWith(key, "vehicle:lanes")
1970 && key != "postal_code"
1971 && key != "railway:preferred_direction"
1972 && key != "railway:bidirectional"
1973 && key != "railway:track_ref"
1974 && key != "usage"
1975 && key != "access"
1976 && key != "emergency"
1977 && key != "service"
1978 && key != "electrified"
1979 && key != "segregated"
1980 && key != "bus"
1981 && key != "psv"
1982 && key != "foot"
1983 && key != "bicycle"
1984 && !StringUtils::startsWith(key, "oneway:")
1985 && key != "placement"
1986 && key != "bus:lanes"
1987 && key != "bus:lanes:forward"
1988 && key != "bus:lanes:backward"
1989 && key != "psv:lanes"
1990 && key != "psv:lanes:forward"
1991 && key != "psv:lanes:backward"
1992 && key != "bicycle:lanes"
1993 && key != "bicycle:lanes:forward"
1994 && key != "bicycle:lanes:backward"
1995 && !StringUtils::startsWith(key, "width")
1996 && !(StringUtils::startsWith(key, "turn:") && key.find(":lanes") != std::string::npos)
1997 && key != "public_transport") {
1998 return;
1999 }
2000 const std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentEdge->id).c_str(), ok, false);
2001
2002 if (key == "highway" || key == "railway" || key == "waterway" || StringUtils::startsWith(key, "cycleway")
2003 || key == "busway" || key == "route" || StringUtils::startsWith(key, "sidewalk") || key == "highspeed"
2004 || key == "aeroway" || key == "aerialway" || key == "usage" || key == "service") {
2005 if (key == "highway" && (value == "service" || StringUtils::endsWith(value, "_link"))) {
2006 myCurrentEdge->myRoundaboutGuessExcluded = true;
2007 }
2008 // build type id
2009 if (key != "highway" || myTypeCont.knows(key + "." + value)) {
2010 myCurrentEdge->myCurrentIsRoad = true;
2011 }
2012 // special cycleway stuff https://wiki.openstreetmap.org/wiki/Key:cycleway
2013 if (key == "cycleway") {
2014 if (value == "no" || value == "none" || value == "separate") {
2015 myCurrentEdge->myCyclewayType = WAY_NONE;
2016 } else if (value == "both") {
2017 myCurrentEdge->myCyclewayType = WAY_BOTH;
2018 } else if (value == "right") {
2019 myCurrentEdge->myCyclewayType = WAY_FORWARD;
2020 } else if (value == "left") {
2021 myCurrentEdge->myCyclewayType = WAY_BACKWARD;
2022 } else if (value == "opposite_track") {
2023 myCurrentEdge->myCyclewayType = WAY_BACKWARD;
2024 } else if (value == "opposite_lane") {
2025 myCurrentEdge->myCyclewayType = WAY_BACKWARD;
2026 } else if (value == "opposite") {
2027 // according to the wiki ref above, this should rather be a bidi lane, see #13438
2028 myCurrentEdge->myCyclewayType = WAY_BACKWARD;
2029 }
2030 }
2031 if (key == "cycleway:left") {
2032 if (myCurrentEdge->myCyclewayType == WAY_UNKNOWN) {
2033 myCurrentEdge->myCyclewayType = WAY_NONE;
2034 }
2035 if (value == "yes" || value == "lane" || value == "track") {
2036 myCurrentEdge->myCyclewayType = (WayType)(myCurrentEdge->myCyclewayType | WAY_BACKWARD);
2037 }
2038 key = "cycleway"; // for type adaption
2039 }
2040 if (key == "cycleway:right") {
2041 if (myCurrentEdge->myCyclewayType == WAY_UNKNOWN) {
2042 myCurrentEdge->myCyclewayType = WAY_NONE;
2043 }
2044 if (value == "yes" || value == "lane" || value == "track") {
2045 myCurrentEdge->myCyclewayType = (WayType)(myCurrentEdge->myCyclewayType | WAY_FORWARD);
2046 }
2047 key = "cycleway"; // for type adaption
2048 }
2049 if (key == "cycleway:both") {
2050 if (myCurrentEdge->myCyclewayType == WAY_UNKNOWN) {
2051 if (value == "no" || value == "none" || value == "separate") {
2052 myCurrentEdge->myCyclewayType = WAY_NONE;
2053 }
2054 if (value == "yes" || value == "lane" || value == "track") {
2055 myCurrentEdge->myCyclewayType = WAY_BOTH;
2056 }
2057 }
2058 key = "cycleway"; // for type adaption
2059 }
2060 if (key == "cycleway" && value != "lane" && value != "track" && value != "opposite_track" && value != "opposite_lane") {
2061 // typemap covers only the lane and track cases
2062 return;
2063 }
2064 if (StringUtils::startsWith(key, "cycleway:")) {
2065 // no need to extend the type id for other cycleway sub tags
2066 return;
2067 }
2068 // special sidewalk stuff
2069 if (key == "sidewalk") {
2070 if (value == "no" || value == "none" || value == "separate") {
2071 myCurrentEdge->mySidewalkType = WAY_NONE;
2072 if (value == "separate") {
2073 myCurrentEdge->myExtraDisallowed |= SVC_PEDESTRIAN;
2074 }
2075 } else if (value == "both" || value == "yes") {
2076 myCurrentEdge->mySidewalkType = WAY_BOTH;
2077 } else if (value == "right") {
2078 myCurrentEdge->mySidewalkType = WAY_FORWARD;
2079 } else if (value == "left") {
2080 myCurrentEdge->mySidewalkType = WAY_BACKWARD;
2081 }
2082 }
2083 if (key == "sidewalk:left") {
2084 if (myCurrentEdge->mySidewalkType == WAY_UNKNOWN) {
2085 myCurrentEdge->mySidewalkType = WAY_NONE;
2086 }
2087 if (value == "yes") {
2088 myCurrentEdge->mySidewalkType = (WayType)(myCurrentEdge->mySidewalkType | WAY_BACKWARD);
2089 }
2090 if (value == "separate") {
2091 myCurrentEdge->myExtraDisallowed |= SVC_PEDESTRIAN;
2092 }
2093 }
2094 if (key == "sidewalk:right") {
2095 if (myCurrentEdge->mySidewalkType == WAY_UNKNOWN) {
2096 myCurrentEdge->mySidewalkType = WAY_NONE;
2097 }
2098 if (value == "yes") {
2099 myCurrentEdge->mySidewalkType = (WayType)(myCurrentEdge->mySidewalkType | WAY_FORWARD);
2100 }
2101 if (value == "separate") {
2102 myCurrentEdge->myExtraDisallowed |= SVC_PEDESTRIAN;
2103 }
2104 }
2105 if (key == "sidewalk:both") {
2106 if (myCurrentEdge->mySidewalkType == WAY_UNKNOWN) {
2107 if (value == "no" || value == "none" || value == "separate") {
2108 myCurrentEdge->mySidewalkType = WAY_NONE;
2109 if (value == "separate") {
2110 myCurrentEdge->myExtraDisallowed |= SVC_PEDESTRIAN;
2111 }
2112 }
2113 if (value == "yes") {
2114 myCurrentEdge->mySidewalkType = WAY_BOTH;
2115 }
2116 }
2117 }
2118 if (StringUtils::startsWith(key, "sidewalk")) {
2119 // no need to extend the type id
2120 return;
2121 }
2122 // special busway stuff
2123 if (key == "busway") {
2124 if (value == "no" || value == "none") {
2125 return;
2126 }
2127 if (value == "opposite_track" || value == "opposite_lane") {
2128 myCurrentEdge->myBuswayType = (WayType)(myCurrentEdge->myBuswayType | WAY_BACKWARD);
2129 } else if (buswaySpec == "right") {
2130 myCurrentEdge->myBuswayType = (WayType)(myCurrentEdge->myBuswayType | WAY_FORWARD);
2131 } else if (buswaySpec == "left") {
2132 myCurrentEdge->myBuswayType = (WayType)(myCurrentEdge->myBuswayType | WAY_BACKWARD);
2133 } else if (buswaySpec == "both") {
2134 myCurrentEdge->myBuswayType = (WayType)(myCurrentEdge->myBuswayType | WAY_BOTH);
2135 }
2136 // no need to extend the type id
2137 return;
2138 }
2139 std::string singleTypeID = key + "." + value;
2140 if (key == "highspeed") {
2141 if (value == "no") {
2142 return;
2143 }
2144 singleTypeID = "railway.highspeed";
2145 }
2146 addType(singleTypeID);
2147
2148 } else if (key == "bus" || key == "psv") {
2149 // 'psv' includes taxi in the UK but not in germany
2150 try {
2151 if (StringUtils::toBool(value)) {
2152 myCurrentEdge->myExtraAllowed |= SVC_BUS;
2153 addType(key);
2154 } else {
2155 myCurrentEdge->myExtraDisallowed |= SVC_BUS;
2156 }
2157 } catch (const BoolFormatException&) {
2158 myCurrentEdge->myExtraAllowed |= SVC_BUS;
2159 addType(key);
2160 }
2161 } else if (key == "emergency") {
2162 try {
2163 if (StringUtils::toBool(value)) {
2164 myCurrentEdge->myExtraAllowed |= SVC_AUTHORITY | SVC_EMERGENCY;
2165 }
2166 } catch (const BoolFormatException&) {
2167 myCurrentEdge->myExtraAllowed |= SVC_AUTHORITY | SVC_EMERGENCY;
2168 }
2169 } else if (key == "access") {
2170 if (value == "no") {
2171 myCurrentEdge->myExtraDisallowed |= ~(SVC_PUBLIC_CLASSES | SVC_EMERGENCY | SVC_AUTHORITY);
2172 }
2173 } else if (StringUtils::startsWith(key, "width:lanes")) {
2174 try {
2175 const std::vector<std::string> values = StringTokenizer(value, "|").getVector();
2176 std::vector<double> widthLanes;
2177 for (std::string width : values) {
2178 const double parsedWidth = width == "" ? -1 : StringUtils::parseDist(width);
2179 widthLanes.push_back(parsedWidth);
2180 }
2181
2182 if (key == "width:lanes") {
2183 myUnsuffixedWidthLanes = widthLanes;
2184 } else if (key == "width:lanes:forward") {
2185 myCurrentEdge->myWidthLanesForward = widthLanes;
2186 } else if (key == "width:lanes:backward") {
2187 myCurrentEdge->myWidthLanesBackward = widthLanes;
2188 } else {
2189 WRITE_WARNINGF(TL("Using default lane width for edge '%' as key '%' could not be parsed."), toString(myCurrentEdge->id), key);
2190 }
2191 } catch (const NumberFormatException&) {
2192 WRITE_WARNINGF(TL("Using default lane width for edge '%' as value '%' could not be parsed."), toString(myCurrentEdge->id), value);
2193 }
2194 } else if (key == "width") {
2195 try {
2196 myCurrentEdge->myWidth = StringUtils::parseDist(value);
2197 } catch (const NumberFormatException&) {
2198 WRITE_WARNINGF(TL("Using default width for edge '%' as value '%' could not be parsed."), toString(myCurrentEdge->id), value);
2199 }
2200 } else if (key == "foot") {
2201 if (value == "use_sidepath" || value == "no") {
2202 myCurrentEdge->myExtraDisallowed |= SVC_PEDESTRIAN;
2203 } else if (value == "yes" || value == "designated" || value == "permissive") {
2204 myCurrentEdge->myExtraAllowed |= SVC_PEDESTRIAN;
2205 }
2206 } else if (key == "bicycle") {
2207 if (value == "use_sidepath" || value == "no") {
2208 myCurrentEdge->myExtraDisallowed |= SVC_BICYCLE;
2209 } else if (value == "yes" || value == "designated" || value == "permissive") {
2210 myCurrentEdge->myExtraAllowed |= SVC_BICYCLE;
2211 }
2212 } else if (StringUtils::startsWith(key, "oneway:")) {
2213 const std::string mode = key.substr(7);
2214 if (mode == "bicycle") {
2215 myCurrentEdge->myExtraTags["oneway:bicycle"] = value;
2216 }
2217 if (value == "no" || value == "false" || value == "0") {
2218 static const std::pair<const char*, SVCPermissions> onewayModes[] = {
2219 {"bus", SVC_BUS},
2220 {"psv", SVC_BUS},
2221 {"taxi", SVC_TAXI},
2222 {"bicycle", SVC_BICYCLE},
2223 {"moped", SVC_MOPED},
2224 {"motorcycle", SVC_MOTORCYCLE},
2225 {"hgv", SVC_TRUCK | SVC_TRAILER},
2226 {"emergency", SVC_EMERGENCY | SVC_AUTHORITY}
2227 };
2228 for (const auto& entry : onewayModes) {
2229 if (mode == entry.first) {
2230 myCurrentEdge->myOnewayContraPermissions |= entry.second;
2231 break;
2232 }
2233 }
2234 }
2235 } else if (key == "placement") {
2236 if (!interpretPlacement(value, myCurrentEdge->myPlacement, myCurrentEdge->myPlacementLane)) {
2237 WRITE_WARNINGF(TL("Ignoring unsupported placement value '%' for edge '%'."), value, myCurrentEdge->id);
2238 }
2239 } else if (key == "lanes") {
2240 try {
2241 myCurrentEdge->myNoLanes = StringUtils::toInt(value);
2242 } catch (NumberFormatException&) {
2243 // might be a list of values
2244 StringTokenizer st(value, ";", true);
2245 std::vector<std::string> list = st.getVector();
2246 if (list.size() >= 2) {
2247 int minLanes = std::numeric_limits<int>::max();
2248 try {
2249 for (auto& i : list) {
2250 const int numLanes = StringUtils::toInt(StringUtils::prune(i));
2251 minLanes = MIN2(minLanes, numLanes);
2252 }
2253 myCurrentEdge->myNoLanes = minLanes;
2254 WRITE_WARNINGF(TL("Using minimum lane number from list (%) for edge '%'."), value, toString(myCurrentEdge->id));
2255 } catch (NumberFormatException&) {
2256 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
2257 }
2258 }
2259 } catch (EmptyData&) {
2260 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
2261 }
2262 } else if (key == "lanes:forward" || key == "lanes:backward") {
2263 try {
2264 const int val = StringUtils::toInt(value);
2265 if (val > 0) {
2266 (key == "lanes:forward" ? myCurrentEdge->myDirForward : myCurrentEdge->myDirBackward).lanes = val;
2267 }
2268 } catch (...) {
2269 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
2270 }
2271 } else if (key == "lanes:both_ways") {
2272 try {
2273 const int val = StringUtils::toInt(value);
2274 if (val > 0) {
2275 myCurrentEdge->myNoLanesBothWays = val;
2276 }
2277 } catch (...) {
2278 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
2279 }
2280 } else if (key == "lanes:bus" || key == "lanes:psv") {
2281 const int cnt = parseBusLaneCount(key, value);
2282 if (cnt > 0) {
2283 myUnsuffixedBusLanesCount = MAX2(myUnsuffixedBusLanesCount, cnt);
2284 myUnsuffixedBusLanesClasses |= (key == "lanes:psv") ? (SVC_BUS | SVC_TAXI) : (SVCPermissions)SVC_BUS;
2285 }
2286 } else if (key == "lanes:bus:forward" || key == "lanes:psv:forward"
2287 || key == "lanes:bus:backward" || key == "lanes:psv:backward") {
2288 const int cnt = parseBusLaneCount(key, value);
2289 if (cnt > 0) {
2290 const bool fwd = StringUtils::endsWith(key, ":forward");
2291 Edge::DirLaneInfo& dir = fwd ? myCurrentEdge->myDirForward : myCurrentEdge->myDirBackward;
2292 dir.busLanes = MAX2(dir.busLanes, cnt);
2293 dir.busClasses |= StringUtils::startsWith(key, "lanes:psv") ? (SVC_BUS | SVC_TAXI) : (SVCPermissions)SVC_BUS;
2294 dir.hasExplicitDirBus = true;
2295 }
2296 } else if (key == "maxspeed:forward" && myMaxSpeedForward == MAXSPEED_UNGIVEN) {
2297 myMaxSpeedForward = interpretSpeed(key, value);
2298 } else if (key == "maxspeed" && myMaxSpeedExplicit == MAXSPEED_UNGIVEN) {
2299 myMaxSpeedExplicit = interpretSpeed(key, value);
2300 } else if ((key == "maxspeed:type" || key == "zone:maxspeed") && myMaxSpeedFallbackValue.empty()) {
2301 myMaxSpeedFallbackKey = key;
2302 myMaxSpeedFallbackValue = value;
2303 } else if (key == "maxspeed:backward" && myCurrentEdge->myMaxSpeedBackward == MAXSPEED_UNGIVEN) {
2304 myCurrentEdge->myMaxSpeedBackward = interpretSpeed(key, value);
2305 } else if (key == "junction") {
2306 if ((value == "roundabout" || value == "circular") && myCurrentEdge->myIsOneWay.empty()) {
2307 myCurrentEdge->myIsOneWay = "yes";
2308 }
2309 if (value == "roundabout") {
2310 myCurrentEdge->myAmInRoundabout = true;
2311 } else if (value == "circular") {
2312 myCurrentEdge->myRoundaboutGuessExcluded = true;
2313 myCurrentEdge->myIsCircularJunction = true;
2314 }
2315 } else if (key == "oneway") {
2316 myCurrentEdge->myIsOneWay = value;
2317 } else if (key == "name") {
2318 myCurrentEdge->streetName = value;
2319 } else if (key == "ref") {
2320 myCurrentEdge->ref = value;
2321 myCurrentEdge->setParameter("ref", value);
2322 } else if (key == "layer") {
2323 try {
2324 myCurrentEdge->myLayer = StringUtils::toInt(value);
2325 } catch (...) {
2326 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
2327 }
2328 } else if (key == "tracks") {
2329 try {
2330 if (StringUtils::toInt(value) == 1) {
2331 myCurrentEdge->myIsOneWay = "true";
2332 } else {
2333 WRITE_WARNINGF(TL("Ignoring track count % for edge '%'."), value, myCurrentEdge->id);
2334 }
2335 } catch (...) {
2336 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
2337 }
2338 } else if (key == "railway:preferred_direction") {
2339 if (value == "both") {
2340 myCurrentEdge->myRailDirection = WAY_BOTH | WAY_PREFER_FORWARD | WAY_PREFER_BACKWARD;
2341 } else if (value == "backward") {
2342 myCurrentEdge->myRailDirection = (myCurrentEdge->myRailDirection | WAY_BACKWARD | WAY_PREFER_BACKWARD) & ~WAY_UNKNOWN;
2343 } else if (value == "forward") {
2344 myCurrentEdge->myRailDirection = (myCurrentEdge->myRailDirection | WAY_FORWARD | WAY_PREFER_FORWARD) & ~WAY_UNKNOWN;
2345 }
2346 } else if (key == "railway:bidirectional") {
2347 if (value == "regular") {
2348 myCurrentEdge->myRailDirection = (myCurrentEdge->myRailDirection | WAY_BOTH) & ~WAY_UNKNOWN;
2349 }
2350 } else if (key == "electrified" || key == "segregated") {
2351 if (value != "no") {
2352 myCurrentEdge->myExtraTags[key] = value;
2353 }
2354 } else if (key == "railway:track_ref") {
2355 myCurrentEdge->setParameter(key, value);
2356 } else if (key == "public_transport" && value == "platform") {
2357 myCurrentEdge->myExtraTags["platform"] = "yes";
2358 } else if ((key == "parking:both" || key == "parking:lane:both") && !StringUtils::startsWith(value, "no")) {
2359 myCurrentEdge->myParkingType |= PARKING_BOTH;
2360 } else if ((key == "parking:left" || key == "parking:lane:left") && !StringUtils::startsWith(value, "no")) {
2361 myCurrentEdge->myParkingType |= PARKING_LEFT;
2362 } else if ((key == "parking:right" || key == "parking:lane:right") && !StringUtils::startsWith(value, "no")) {
2363 myCurrentEdge->myParkingType |= PARKING_RIGHT;
2364 } else if (key == "change" || key == "change:lanes") {
2365 myCurrentEdge->myChangeForward = myCurrentEdge->myChangeBackward = interpretChangeType(value);
2366 } else if (key == "change:forward" || key == "change:lanes:forward") {
2367 myCurrentEdge->myChangeForward = interpretChangeType(value);
2368 } else if (key == "change:backward" || key == "change:lanes:backward") {
2369 myCurrentEdge->myChangeBackward = interpretChangeType(value);
2370 } else if (key == "vehicle:lanes") {
2371 myUnsuffixedLaneUse.push_back({value, SVC_PASSENGER, false});
2372 myUnsuffixedLaneUse.push_back({value, SVC_PRIVATE, false});
2373 } else if (key == "vehicle:lanes:forward") {
2374 interpretLaneUse(value, SVC_PASSENGER, true);
2375 interpretLaneUse(value, SVC_PRIVATE, true);
2376 } else if (key == "vehicle:lanes:backward") {
2377 interpretLaneUse(value, SVC_PASSENGER, false);
2378 interpretLaneUse(value, SVC_PRIVATE, false);
2379 } else if (key == "bus:lanes") {
2380 myUnsuffixedLaneUse.push_back({value, SVC_BUS, true});
2381 } else if (key == "bus:lanes:forward") {
2382 interpretLaneUse(value, SVC_BUS, true);
2383 myCurrentEdge->myDirForward.hasBusSpec = true;
2384 } else if (key == "bus:lanes:backward") {
2385 interpretLaneUse(value, SVC_BUS, false);
2386 myCurrentEdge->myDirBackward.hasBusSpec = true;
2387 } else if (key == "psv:lanes") {
2388 myUnsuffixedLaneUse.push_back({value, SVC_BUS, true});
2389 myUnsuffixedLaneUse.push_back({value, SVC_TAXI, true});
2390 } else if (key == "psv:lanes:forward") {
2391 interpretLaneUse(value, SVC_BUS, true);
2392 interpretLaneUse(value, SVC_TAXI, true);
2393 myCurrentEdge->myDirForward.hasBusSpec = true;
2394 } else if (key == "psv:lanes:backward") {
2395 interpretLaneUse(value, SVC_BUS, false);
2396 interpretLaneUse(value, SVC_TAXI, false);
2397 myCurrentEdge->myDirBackward.hasBusSpec = true;
2398 } else if (key == "bicycle:lanes") {
2399 myUnsuffixedLaneUse.push_back({value, SVC_BICYCLE, false});
2400 } else if (key == "bicycle:lanes:forward") {
2401 interpretLaneUse(value, SVC_BICYCLE, true);
2402 } else if (key == "bicycle:lanes:backward") {
2403 interpretLaneUse(value, SVC_BICYCLE, false);
2404 } else if (StringUtils::startsWith(key, "turn:") && key.find(":lanes") != std::string::npos) {
2405 int shift = 0;
2406 // use the first 8 bit to encode permitted directions for all classes
2407 // and the successive 8 bit blocks for selected classes
2408 if (StringUtils::startsWith(key, "turn:bus") || StringUtils::startsWith(key, "turn:psv:")) {
2410 } else if (StringUtils::startsWith(key, "turn:taxi")) {
2412 } else if (StringUtils::startsWith(key, "turn:bicycle")) {
2414 }
2415 const std::vector<std::string> values = StringTokenizer(value, "|").getVector();
2416 std::vector<int> turnCodes;
2417 for (std::string codeList : values) {
2418 const std::vector<std::string> codes = StringTokenizer(codeList, ";").getVector();
2419 int turnCode = 0;
2420 if (codes.size() == 0) {
2421 turnCode = (int)LinkDirection::STRAIGHT;
2422 }
2423 for (std::string code : codes) {
2424 if (code == "" || code == "none" || code == "through") {
2425 turnCode |= (int)LinkDirection::STRAIGHT << shift ;
2426 } else if (code == "left" || code == "sharp_left") {
2427 turnCode |= (int)LinkDirection::LEFT << shift;
2428 } else if (code == "right" || code == "sharp_right") {
2429 turnCode |= (int)LinkDirection::RIGHT << shift;
2430 } else if (code == "slight_left") {
2431 turnCode |= (int)LinkDirection::PARTLEFT << shift;
2432 } else if (code == "slight_right") {
2433 turnCode |= (int)LinkDirection::PARTRIGHT << shift;
2434 } else if (code == "reverse") {
2435 turnCode |= (int)LinkDirection::TURN << shift;
2436 } else if (code == "merge_to_left" || code == "merge_to_right") {
2437 turnCode |= (int)LinkDirection::NODIR << shift;
2438 }
2439 }
2440 turnCodes.push_back(turnCode);
2441 }
2442 if (StringUtils::endsWith(key, "lanes:forward")) {
2443 mergeTurnSigns(myCurrentEdge->myTurnSignsForward, turnCodes);
2444 } else if (StringUtils::endsWith(key, "lanes:backward")) {
2445 mergeTurnSigns(myCurrentEdge->myTurnSignsBackward, turnCodes);
2446 } else if (StringUtils::endsWith(key, "lanes:both_ways")) {
2447 mergeTurnSigns(myCurrentEdge->myTurnSignsForward, turnCodes);
2448 mergeTurnSigns(myCurrentEdge->myTurnSignsBackward, turnCodes);
2449 } else if (StringUtils::endsWith(key, "lanes")) {
2450 mergeTurnSigns(myUnsuffixedTurnSigns, turnCodes);
2451 }
2452 }
2453 }
2454}
2455
2456
2457void
2458NIImporter_OpenStreetMap::EdgesHandler::addType(const std::string& singleTypeID) {
2459 // special case: never build compound type for highspeed rail
2460 if (!myCurrentEdge->myHighWayType.empty() && singleTypeID != "railway.highspeed") {
2461 if (myCurrentEdge->myHighWayType == "railway.highspeed") {
2462 return;
2463 }
2464 // osm-ways may be used by more than one mode (eg railway.tram + highway.residential. this is relevant for multimodal traffic)
2465 // we create a new type for this kind of situation which must then be resolved in insertEdge()
2466 std::vector<std::string> types = StringTokenizer(myCurrentEdge->myHighWayType,
2468 types.push_back(singleTypeID);
2469 myCurrentEdge->myHighWayType = joinToStringSorting(types, compoundTypeSeparator);
2470 } else {
2471 myCurrentEdge->myHighWayType = singleTypeID;
2472 }
2473}
2474
2475
2476double
2477NIImporter_OpenStreetMap::EdgesHandler::interpretSpeed(const std::string& key, std::string value) {
2478 if (mySpeedMap.find(value) != mySpeedMap.end()) {
2479 return mySpeedMap[value];
2480 } else {
2481 // handle symbolic names of the form DE:30 / DE:zone30 / DE:zone:30
2482 if (value.size() > 3 && value[2] == ':') {
2483 if (value.substr(3, 4) == "zone") {
2484 value = value.substr(7);
2485 if (!value.empty() && (value[0] == ':' || value[0] == '_')) {
2486 value = value.substr(1);
2487 }
2488 } else {
2489 value = value.substr(3);
2490 }
2491 }
2492 try {
2493 return StringUtils::parseSpeed(value);
2494 } catch (...) {
2495 WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
2496 toString(myCurrentEdge->id) + "'.");
2497 return MAXSPEED_UNGIVEN;
2498 }
2499 }
2500}
2501
2502
2503int
2505 int result = 0;
2506 const std::vector<std::string> values = StringTokenizer(value, "|").getVector();
2507 for (const std::string& val : values) {
2508 if (val == "no") {
2509 result += CHANGE_NO;
2510 } else if (val == "not_left") {
2511 result += CHANGE_NO_LEFT;
2512 } else if (val == "not_right") {
2513 result += CHANGE_NO_RIGHT;
2514 }
2515 result = result << 2;
2516 }
2517 // last shift was superfluous
2518 result = result >> 2;
2519
2520 if (values.size() > 1) {
2521 result += 2 << 29; // mark multi-value input
2522 }
2523 //std::cout << " way=" << myCurrentEdge->id << " value=" << value << " result=" << std::bitset<32>(result) << "\n";
2524 return result;
2525}
2526
2527
2528bool
2531 laneIndex = -1;
2532 const std::vector<std::string> tokens = StringTokenizer(value, ":").getVector();
2533 if (tokens.size() != 2) {
2534 return false;
2535 }
2536 const std::string where = StringUtils::prune(tokens[0]);
2537 if (where == "left_of") {
2539 } else if (where == "right_of") {
2541 } else if (where == "middle_of") {
2543 } else {
2544 return false;
2545 }
2546 try {
2547 laneIndex = StringUtils::toInt(StringUtils::prune(tokens[1]));
2548 } catch (ProcessError&) {
2550 laneIndex = -1;
2551 return false;
2552 }
2553 if (laneIndex <= 0) {
2555 laneIndex = -1;
2556 return false;
2557 }
2558 return true;
2559}
2560
2561
2562void
2564 const std::vector<std::string> values = StringTokenizer(value, "|").getVector();
2565 std::vector<bool>& designated = forward ? myCurrentEdge->myDesignatedLaneForward : myCurrentEdge->myDesignatedLaneBackward;
2566 std::vector<SVCPermissions>& allowed = forward ? myCurrentEdge->myAllowedLaneForward : myCurrentEdge->myAllowedLaneBackward;
2567 std::vector<SVCPermissions>& disallowed = forward ? myCurrentEdge->myDisallowedLaneForward : myCurrentEdge->myDisallowedLaneBackward;
2568 designated.resize(MAX2(designated.size(), values.size()), false);
2569 allowed.resize(MAX2(allowed.size(), values.size()), SVC_IGNORING);
2570 disallowed.resize(MAX2(disallowed.size(), values.size()), SVC_IGNORING);
2571 int i = 0;
2572 for (const std::string& val : values) {
2573 if (val == "yes" || val == "permissive") {
2574 allowed[i] |= svc;
2575 } else if (val == "lane" || val == "designated") {
2576 allowed[i] |= svc;
2577 designated[i] = true;
2578 } else if (val == "no") {
2579 disallowed[i] |= svc;
2580 } else {
2581 WRITE_WARNINGF(TL("Unknown lane use specifier '%' ignored for way '%'"), val, myCurrentEdge->id);
2582 }
2583 i++;
2584 }
2585}
2586
2587
2588int
2589NIImporter_OpenStreetMap::EdgesHandler::parseBusLaneCount(const std::string& key, const std::string& value) const {
2590 if (value == "yes") {
2591 return 1;
2592 }
2593 if (value == "no" || value == "none") {
2594 return 0;
2595 }
2596 try {
2597 const int cnt = StringUtils::toInt(value);
2598 return cnt > 0 ? cnt : 0;
2599 } catch (...) {
2600 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
2601 return 0;
2602 }
2603}
2604
2605
2606void
2608 myUnsuffixedWidthLanes.clear();
2609 myUnsuffixedTurnSigns.clear();
2610 myUnsuffixedLaneUse.clear();
2611 myUnsuffixedBusLanesCount = 0;
2612 myUnsuffixedBusLanesClasses = 0;
2613 myMaxSpeedExplicit = MAXSPEED_UNGIVEN;
2614 myMaxSpeedForward = MAXSPEED_UNGIVEN;
2615 myMaxSpeedFallbackKey.clear();
2616 myMaxSpeedFallbackValue.clear();
2617}
2618
2619
2620void
2622 const bool reverseOneway = (myCurrentEdge->myIsOneWay == "-1" || myCurrentEdge->myIsOneWay == "reverse");
2623 const bool explicitOneway = StringUtils::isBool(myCurrentEdge->myIsOneWay) && StringUtils::toBool(myCurrentEdge->myIsOneWay);
2624 const bool defaultOneway = myCurrentEdge->myIsOneWay.empty()
2625 && myTypeCont.knows(myCurrentEdge->myHighWayType)
2626 && myTypeCont.getEdgeTypeIsOneWay(myCurrentEdge->myHighWayType);
2627 Edge::DirLaneInfo& dirFwd = myCurrentEdge->myDirForward;
2628 Edge::DirLaneInfo& dirBwd = myCurrentEdge->myDirBackward;
2629 const int explicitBusFwd = dirFwd.busLanes;
2630 const int explicitBusBwd = dirBwd.busLanes;
2631 const int explicitBusSum = explicitBusFwd + explicitBusBwd;
2632
2633 // 1. Route unsuffixed :lanes tags to forward or backward now that oneway is final
2634 if (!myUnsuffixedWidthLanes.empty()) {
2635 std::vector<double>& target = reverseOneway ? myCurrentEdge->myWidthLanesBackward : myCurrentEdge->myWidthLanesForward;
2636 if (target.empty()) {
2637 target = std::move(myUnsuffixedWidthLanes);
2638 }
2639 }
2640 if (!myUnsuffixedTurnSigns.empty()) {
2641 mergeTurnSigns(reverseOneway ? myCurrentEdge->myTurnSignsBackward : myCurrentEdge->myTurnSignsForward, myUnsuffixedTurnSigns);
2642 }
2643 for (const auto& entry : myUnsuffixedLaneUse) {
2644 interpretLaneUse(entry.value, entry.svc, !reverseOneway);
2645 if (entry.isBusOrPsv) {
2646 (reverseOneway ? dirBwd : dirFwd).hasBusSpec = true;
2647 }
2648 }
2649 if (myUnsuffixedBusLanesCount > 0) {
2650 auto applyBus = [&](Edge::DirLaneInfo& dir, int count) {
2651 dir.busLanes = MAX2(dir.busLanes, count);
2652 dir.busClasses |= myUnsuffixedBusLanesClasses;
2653 };
2654 if (reverseOneway) {
2655 applyBus(dirBwd, myUnsuffixedBusLanesCount);
2656 } else if (explicitOneway || defaultOneway) {
2657 applyBus(dirFwd, myUnsuffixedBusLanesCount);
2658 } else if (myUnsuffixedBusLanesCount >= 2 && myUnsuffixedBusLanesCount % 2 == 0) {
2659 applyBus(dirFwd, myUnsuffixedBusLanesCount / 2);
2660 applyBus(dirBwd, myUnsuffixedBusLanesCount / 2);
2661 } else {
2662 applyBus(dirFwd, myUnsuffixedBusLanesCount);
2663 }
2664 }
2665
2666 // 2. Direction-aware contraflow busway mark for bus/psv exemptions (suppresses redundant bike lane)
2667 if ((explicitOneway || defaultOneway || reverseOneway) && (myCurrentEdge->myOnewayContraPermissions & SVC_BUS) != 0) {
2668 const WayType contra = reverseOneway ? WAY_FORWARD : WAY_BACKWARD;
2669 myCurrentEdge->myBuswayType = (WayType)(myCurrentEdge->myBuswayType | contra);
2670 }
2671
2672 // 3. Speed precedence: maxspeed:forward > maxspeed > maxspeed:type / zone:maxspeed
2673 double baseSpeed = myMaxSpeedExplicit;
2674 if (baseSpeed == MAXSPEED_UNGIVEN && !myMaxSpeedFallbackValue.empty()) {
2675 baseSpeed = interpretSpeed(myMaxSpeedFallbackKey, myMaxSpeedFallbackValue);
2676 }
2677 myCurrentEdge->myMaxSpeedBase = baseSpeed;
2678 myCurrentEdge->myMaxSpeed = (myMaxSpeedForward != MAXSPEED_UNGIVEN) ? myMaxSpeedForward : baseSpeed;
2679
2680 // 4. Lane count reconciliation when both directional counts are given (#10315)
2681 if (dirFwd.lanes > 0 && dirBwd.lanes > 0) {
2682 const int dirSum = dirFwd.lanes + dirBwd.lanes + myCurrentEdge->myNoLanesBothWays;
2683 if (myCurrentEdge->myNoLanes < 0) {
2684 myCurrentEdge->myNoLanes = dirSum;
2685 } else if (myCurrentEdge->myNoLanes != dirSum) {
2686 if (explicitBusSum > 0 && myCurrentEdge->myNoLanes == dirSum + explicitBusSum) {
2687 // Some mappers exclude directional lanes:bus* / lanes:psv* from lanes:forward / lanes:backward
2688 dirFwd.lanes += explicitBusFwd;
2689 dirBwd.lanes += explicitBusBwd;
2690 } else {
2691 WRITE_WARNINGF(TL("Lane count (%) does not match sum of directional lanes (%) for edge '%'."),
2692 myCurrentEdge->myNoLanes, dirSum, myCurrentEdge->id);
2693 if (myCurrentEdge->myNoLanes > dirSum) {
2694 myCurrentEdge->myNoLanes = dirSum;
2695 }
2696 }
2697 }
2698 }
2699}
2700
2701
2702void
2704 if (element == SUMO_TAG_WAY && myCurrentEdge != nullptr) {
2705 if (myCurrentEdge->myCurrentIsRoad) {
2706 resolveEdgeTags();
2707 const auto insertionIt = myEdgeMap.lower_bound(myCurrentEdge->id);
2708 if (insertionIt == myEdgeMap.end() || insertionIt->first != myCurrentEdge->id) {
2709 // assume we are loading multiple files, so we won't report duplicate edges
2710 myEdgeMap.emplace_hint(insertionIt, myCurrentEdge->id, myCurrentEdge);
2711 } else {
2712 delete myCurrentEdge;
2713 }
2714 } else if (myCurrentEdge->myExtraTags.count("platform") != 0) {
2715 const auto insertionIt = myPlatformShapesMap.lower_bound(myCurrentEdge->id);
2716 if (insertionIt == myPlatformShapesMap.end() || insertionIt->first != myCurrentEdge->id) {
2717 // assume we are loading multiple files, so we won't report duplicate platforms
2718 myPlatformShapesMap.emplace_hint(insertionIt, myCurrentEdge->id, myCurrentEdge);
2719 } else {
2720 delete myCurrentEdge;
2721 }
2722 } else {
2723 delete myCurrentEdge;
2724 }
2725 myCurrentEdge = nullptr;
2726 }
2727}
2728
2729
2730// ---------------------------------------------------------------------------
2731// definitions of NIImporter_OpenStreetMap::RelationHandler-methods
2732// ---------------------------------------------------------------------------
2734 const std::map<long long int, NIOSMNode*>& osmNodes,
2735 const std::map<long long int, Edge*>& osmEdges, NBPTStopCont* nbptStopCont,
2736 const std::map<long long int, Edge*>& platformShapes,
2737 NBPTLineCont* nbptLineCont,
2738 const OptionsCont& oc) :
2739 SUMOSAXHandler("osm - file"),
2740 myOSMNodes(osmNodes),
2741 myOSMEdges(osmEdges),
2742 myPlatformShapes(platformShapes),
2743 myNBPTStopCont(nbptStopCont),
2744 myNBPTLineCont(nbptLineCont),
2745 myOptionsCont(oc) {
2746 resetValues();
2747}
2748
2749
2751
2752
2753void
2755 myCurrentRelation = INVALID_ID;
2756 myIsRestriction = false;
2757 myRestrictionException = SVC_IGNORING;
2758 myFromWay = INVALID_ID;
2759 myToWay = INVALID_ID;
2760 myViaNode = INVALID_ID;
2761 myViaWay = INVALID_ID;
2762 myStation = INVALID_ID;
2763 myRestrictionType = RestrictionType::UNKNOWN;
2764 myPlatforms.clear();
2765 myStops.clear();
2766 myPlatformStops.clear();
2767 myWays.clear();
2768 myIsStopArea = false;
2769 myIsRoute = false;
2770 myPTRouteType = "";
2771 myRouteColor.setValid(false);
2772}
2773
2774
2775void
2777 if (element == SUMO_TAG_RELATION) {
2778 bool ok = true;
2779 myCurrentRelation = attrs.get<long long int>(SUMO_ATTR_ID, nullptr, ok);
2780 const std::string& action = attrs.getOpt<std::string>(SUMO_ATTR_ACTION, nullptr, ok);
2781 if (action == "delete" || !ok) {
2782 myCurrentRelation = INVALID_ID;
2783 }
2784 myName = "";
2785 myRef = "";
2786 myInterval = -1;
2787 myNightService = "";
2788 return;
2789 }
2790 if (myCurrentRelation == INVALID_ID) {
2791 return;
2792 }
2793 if (element == SUMO_TAG_MEMBER) {
2794 bool ok = true;
2795 std::string role = attrs.hasAttribute("role") ? attrs.getStringSecure("role", "") : "";
2796 const long long int ref = attrs.get<long long int>(SUMO_ATTR_REF, nullptr, ok);
2797 if (role == "via") {
2798 // u-turns for divided ways may be given with 2 via-nodes or 1 via-way
2799 std::string memberType = attrs.get<std::string>(SUMO_ATTR_TYPE, nullptr, ok);
2800 if (memberType == "way" && checkEdgeRef(ref)) {
2801 myViaWay = ref;
2802 } else if (memberType == "node") {
2803 if (myOSMNodes.find(ref) != myOSMNodes.end()) {
2804 myViaNode = ref;
2805 } else {
2806 WRITE_WARNINGF(TL("No node found for reference '%' in relation '%'."), toString(ref), toString(myCurrentRelation));
2807 }
2808 }
2809 } else if (role == "from" && checkEdgeRef(ref)) {
2810 myFromWay = ref;
2811 } else if (role == "to" && checkEdgeRef(ref)) {
2812 myToWay = ref;
2813 } else if (StringUtils::startsWith(role, "stop")) {
2814 // permit _entry_only and _exit_only variants
2815 myStops.push_back(ref);
2816 } else if (StringUtils::startsWith(role, "platform")) {
2817 // permit _entry_only and _exit_only variants
2818 std::string memberType = attrs.get<std::string>(SUMO_ATTR_TYPE, nullptr, ok);
2819 if (memberType == "way") {
2820 const std::map<long long int, NIImporter_OpenStreetMap::Edge*>::const_iterator& wayIt = myPlatformShapes.find(ref);
2821 if (wayIt != myPlatformShapes.end()) {
2822 NIIPTPlatform platform;
2823 platform.isWay = true;
2824 platform.ref = ref;
2825 myPlatforms.push_back(platform);
2826 }
2827 } else if (memberType == "node") {
2828 // myIsStopArea may not be set yet
2829 myStops.push_back(ref);
2830 myPlatformStops.insert(ref);
2831 NIIPTPlatform platform;
2832 platform.isWay = false;
2833 platform.ref = ref;
2834 myPlatforms.push_back(platform);
2835 }
2836
2837 } else if (role == "station") {
2838 myStation = ref;
2839 } else if (role.empty()) {
2840 std::string memberType = attrs.get<std::string>(SUMO_ATTR_TYPE, nullptr, ok);
2841 if (memberType == "way") {
2842 myWays.push_back(ref);
2843 } else if (memberType == "node") {
2844 auto it = myOSMNodes.find(ref);
2845 if (it != myOSMNodes.end() && it->second->hasParameter("railway:ref")) {
2846 myStation = ref;
2847 } else {
2848 myStops.push_back(ref);
2849 }
2850 }
2851 }
2852 return;
2853 }
2854 // parse values
2855 if (element == SUMO_TAG_TAG) {
2856 bool ok = true;
2857 std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myCurrentRelation).c_str(), ok, false);
2858 // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
2859 if (key == "type" || key == "restriction") {
2860 std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
2861 if (key == "type" && value == "restriction") {
2862 myIsRestriction = true;
2863 return;
2864 }
2865 if (key == "type" && value == "route") {
2866 myIsRoute = true;
2867 return;
2868 }
2869 if (key == "restriction") {
2870 // @note: the 'right/left/straight' part is ignored since the information is
2871 // redundantly encoded in the 'from', 'to' and 'via' members
2872 if (value.substr(0, 5) == "only_") {
2873 myRestrictionType = RestrictionType::ONLY;
2874 } else if (value.substr(0, 3) == "no_") {
2875 myRestrictionType = RestrictionType::NO;
2876 } else {
2877 WRITE_WARNINGF(TL("Found unknown restriction type '%' in relation '%'"), value, toString(myCurrentRelation));
2878 }
2879 return;
2880 }
2881 } else if (key == "except") {
2882 std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
2883 for (const std::string& v : StringTokenizer(value, ";").getVector()) {
2884 if (v == "psv") {
2885 myRestrictionException |= SVC_BUS;
2886 } else if (v == "bicycle") {
2887 myRestrictionException |= SVC_BICYCLE;
2888 } else if (v == "hgv") {
2889 myRestrictionException |= SVC_TRUCK | SVC_TRAILER;
2890 } else if (v == "motorcar") {
2891 myRestrictionException |= SVC_PASSENGER | SVC_TAXI;
2892 } else if (v == "emergency") {
2893 myRestrictionException |= SVC_EMERGENCY;
2894 }
2895 }
2896 } else if (key == "public_transport") {
2897 std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
2898 if (value == "stop_area") {
2899 myIsStopArea = true;
2900 }
2901 } else if (key == "route") {
2902 std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
2903 if (value == "train" || value == "subway" || value == "light_rail" || value == "monorail" || value == "tram" || value == "bus"
2904 || value == "trolleybus" || value == "aerialway" || value == "ferry" || value == "share_taxi" || value == "minibus") {
2905 myPTRouteType = value;
2906 }
2907
2908 } else if (key == "name") {
2909 myName = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
2910 } else if (key == "colour") {
2911 std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
2912 try {
2913 myRouteColor = RGBColor::parseColor(value);
2914 } catch (...) {
2915 WRITE_WARNINGF(TL("Invalid color value '%' in relation %"), value, myCurrentRelation);
2916 }
2917 } else if (key == "ref") {
2918 myRef = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
2919 } else if (key == "interval" || key == "headway") {
2920 myInterval = attrs.get<int>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
2921 } else if (key == "by_night") {
2922 myNightService = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
2923 }
2924 }
2925}
2926
2927
2928bool
2930 if (myOSMEdges.find(ref) != myOSMEdges.end()) {
2931 return true;
2932 }
2933 WRITE_WARNINGF(TL("No way found for reference '%' in relation '%'"), toString(ref), toString(myCurrentRelation));
2934 return false;
2935}
2936
2937
2938void
2940 if (element == SUMO_TAG_RELATION) {
2941 if (myIsRestriction) {
2942 assert(myCurrentRelation != INVALID_ID);
2943 bool ok = true;
2944 if (myRestrictionType == RestrictionType::UNKNOWN) {
2945 WRITE_WARNINGF(TL("Ignoring restriction relation '%' with unknown type."), toString(myCurrentRelation));
2946 ok = false;
2947 }
2948 if (myFromWay == INVALID_ID) {
2949 WRITE_WARNINGF(TL("Ignoring restriction relation '%' with unknown from-way."), toString(myCurrentRelation));
2950 ok = false;
2951 }
2952 if (myToWay == INVALID_ID) {
2953 WRITE_WARNINGF(TL("Ignoring restriction relation '%' with unknown to-way."), toString(myCurrentRelation));
2954 ok = false;
2955 }
2956 if (myViaNode == INVALID_ID && myViaWay == INVALID_ID) {
2957 WRITE_WARNINGF(TL("Ignoring restriction relation '%' with unknown via."), toString(myCurrentRelation));
2958 ok = false;
2959 }
2960 if (ok && !applyRestriction()) {
2961 WRITE_WARNINGF(TL("Ignoring restriction relation '%'."), toString(myCurrentRelation));
2962 }
2963 } else if (myIsStopArea) {
2964 for (long long ref : myStops) {
2965 myStopAreas[ref] = myCurrentRelation;
2966 if (myOSMNodes.find(ref) == myOSMNodes.end()) {
2967 //WRITE_WARNING(
2968 // "Referenced node: '" + toString(ref) + "' in relation: '" + toString(myCurrentRelation)
2969 // + "' does not exist. Probably OSM file is incomplete.");
2970 continue;
2971 }
2972
2973 NIOSMNode* n = myOSMNodes.find(ref)->second;
2974 std::shared_ptr<NBPTStop> ptStop = myNBPTStopCont->get(toString(n->id));
2975 if (ptStop == nullptr) {
2976 //WRITE_WARNING(
2977 // "Relation '" + toString(myCurrentRelation) + "' refers to a non existing pt stop at node: '"
2978 // + toString(n->id) + "'. Probably OSM file is incomplete.");
2979 continue;
2980 }
2981 for (NIIPTPlatform& myPlatform : myPlatforms) {
2982 if (myPlatform.isWay) {
2983 assert(myPlatformShapes.find(myPlatform.ref) != myPlatformShapes.end()); //already tested earlier
2984 Edge* edge = (*myPlatformShapes.find(myPlatform.ref)).second;
2985 if (edge->myCurrentNodes.size() > 1 && edge->myCurrentNodes[0] == *(edge->myCurrentNodes.end() - 1)) {
2986 WRITE_WARNINGF(TL("Platform '%' in relation: '%' is given as polygon, which currently is not supported."), myPlatform.ref, myCurrentRelation);
2987 continue;
2988
2989 }
2991 for (auto nodeRef : edge->myCurrentNodes) {
2992 if (myOSMNodes.find(nodeRef) == myOSMNodes.end()) {
2993 //WRITE_WARNING(
2994 // "Referenced node: '" + toString(ref) + "' in relation: '" + toString(myCurrentRelation)
2995 // + "' does not exist. Probably OSM file is incomplete.");
2996 continue;
2997 }
2998 NIOSMNode* pNode = myOSMNodes.find(nodeRef)->second;
2999 Position pNodePos(pNode->lon, pNode->lat, pNode->ele);
3000 if (!NBNetBuilder::transformCoordinate(pNodePos)) {
3001 WRITE_ERRORF("Unable to project coordinates for node '%'.", pNode->id);
3002 continue;
3003 }
3004 p.push_back(pNodePos);
3005 }
3006 if (p.size() == 0) {
3007 WRITE_WARNINGF(TL("Referenced platform: '%' in relation: '%' is corrupt. Probably OSM file is incomplete."),
3008 toString(myPlatform.ref), toString(myCurrentRelation));
3009 continue;
3010 }
3011 NBPTPlatform platform(p[(int)p.size() / 2], p.length());
3012 ptStop->addPlatformCand(platform);
3013 } else {
3014 if (myOSMNodes.find(myPlatform.ref) == myOSMNodes.end()) {
3015 //WRITE_WARNING(
3016 // "Referenced node: '" + toString(ref) + "' in relation: '" + toString(myCurrentRelation)
3017 // + "' does not exist. Probably OSM file is incomplete.");
3018 continue;
3019 }
3020 NIOSMNode* pNode = myOSMNodes.find(myPlatform.ref)->second;
3021 Position platformPos(pNode->lon, pNode->lat, pNode->ele);
3022 if (!NBNetBuilder::transformCoordinate(platformPos)) {
3023 WRITE_ERRORF("Unable to project coordinates for node '%'.", pNode->id);
3024 }
3025 NBPTPlatform platform(platformPos, myOptionsCont.getFloat("osm.stop-output.length"));
3026 ptStop->addPlatformCand(platform);
3027
3028 }
3029 }
3030 ptStop->setIsMultipleStopPositions(myStops.size() > 1, myCurrentRelation);
3031 if (myStation != INVALID_ID) {
3032 const auto& nodeIt = myOSMNodes.find(myStation);
3033 if (nodeIt != myOSMNodes.end()) {
3034 NIOSMNode* station = nodeIt->second;
3035 if (station != nullptr) {
3036 if (station->hasParameter("railway:ref")) {
3037 ptStop->setParameter("stationRef", station->getParameter("railway:ref"));
3038 }
3039 }
3040 }
3041 }
3042 }
3043 } else if (myPTRouteType != "" && myIsRoute) {
3044 NBPTLine* ptLine = new NBPTLine(toString(myCurrentRelation), myName, myPTRouteType, myRef, myInterval, myNightService,
3045 interpretTransportType(myPTRouteType), myRouteColor);
3046 int consecutiveGap = false;
3047 int missingBefore = 0;
3048 int missingAfter = 0;
3049 for (long long ref : myStops) {
3050 const auto& nodeIt = myOSMNodes.find(ref);
3051 if (nodeIt == myOSMNodes.end()) {
3052 if (ptLine->getStops().empty()) {
3053 missingBefore++;
3054 } else {
3055 missingAfter++;
3056 consecutiveGap++;
3057 }
3058 continue;
3059 }
3060 // give some slack for single missing stops
3061 if (consecutiveGap > 1) {
3062 WRITE_WARNINGF(TL("PT line '%' in relation % has a gap of % stops, only keeping first part."), myName, myCurrentRelation, consecutiveGap);
3063 missingAfter = (int)myStops.size() - missingBefore - (int)ptLine->getStops().size();
3064 break;
3065 }
3066 // reset gap
3067 consecutiveGap = 0;
3068
3069 const NIOSMNode* const n = nodeIt->second;
3070 std::shared_ptr<NBPTStop> ptStop = myNBPTStopCont->get(toString(n->id));
3071 if (ptStop == nullptr) {
3072 // loose stop, which must later be mapped onto a line way
3073 Position ptPos(n->lon, n->lat, n->ele);
3075 WRITE_ERRORF("Unable to project coordinates for node '%'.", n->id);
3076 }
3078 ptStop = std::make_shared<NBPTStop>(stopElement, toString(n->id), ptPos, "", "", n->ptStopLength, n->name, n->permissions);
3079 myNBPTStopCont->insert(ptStop);
3080 if (myStopAreas.count(n->id)) {
3081 ptStop->setIsMultipleStopPositions(false, myStopAreas[n->id]);
3082 }
3083 if (myPlatformStops.count(n->id) > 0) {
3084 ptStop->setIsPlatform();
3085 }
3086 }
3087 ptLine->addPTStop(ptStop);
3088 }
3089 for (long long& myWay : myWays) {
3090 auto entr = myOSMEdges.find(myWay);
3091 if (entr != myOSMEdges.end()) {
3092 Edge* edge = entr->second;
3093 for (long long& myCurrentNode : edge->myCurrentNodes) {
3094 ptLine->addWayNode(myWay, myCurrentNode);
3095 }
3096 }
3097 }
3098 ptLine->setNumOfStops((int)myStops.size(), missingBefore, missingAfter);
3099 if (ptLine->getStops().empty()) {
3100 WRITE_WARNINGF(TL("PT line in relation % with no stops ignored. Probably OSM file is incomplete."), myCurrentRelation);
3101 delete ptLine;
3102 resetValues();
3103 return;
3104 }
3105 if (!myNBPTLineCont->insert(ptLine)) {
3106 WRITE_WARNINGF(TL("Ignoring duplicate PT line '%'."), myCurrentRelation);
3107 delete ptLine;
3108 }
3109 }
3110 // other relations might use similar subelements so reset in any case
3111 resetValues();
3112 }
3113}
3114
3115bool
3117 // since OSM ways are bidirectional we need the via to figure out which direction was meant
3118 if (myViaNode != INVALID_ID) {
3119 NBNode* viaNode = myOSMNodes.find(myViaNode)->second->node;
3120 if (viaNode == nullptr) {
3121 WRITE_WARNINGF(TL("Via-node '%' was not instantiated"), toString(myViaNode));
3122 return false;
3123 }
3124 NBEdge* from = findEdgeRef(myFromWay, viaNode->getIncomingEdges());
3125 NBEdge* to = findEdgeRef(myToWay, viaNode->getOutgoingEdges());
3126 if (from == nullptr) {
3127 WRITE_WARNINGF(TL("from-edge '%' of restriction relation could not be determined"), toString(myFromWay));
3128 return false;
3129 }
3130 if (to == nullptr) {
3131 WRITE_WARNINGF(TL("to-edge '%' of restriction relation could not be determined"), toString(myToWay));
3132 return false;
3133 }
3134 if (myRestrictionType == RestrictionType::ONLY) {
3135 from->addEdge2EdgeConnection(to, true);
3136 // make sure that these connections remain disabled even if network
3137 // modifications (ramps.guess) reset existing connections
3138 for (NBEdge* cand : from->getToNode()->getOutgoingEdges()) {
3139 if (!from->isConnectedTo(cand)) {
3140 if (myRestrictionException == SVC_IGNORING) {
3141 from->removeFromConnections(cand, -1, -1, true);
3142 } else {
3143 from->addEdge2EdgeConnection(cand, true, myRestrictionException);
3144 }
3145 }
3146 }
3147 } else {
3148 if (myRestrictionException == SVC_IGNORING) {
3149 from->removeFromConnections(to, -1, -1, true);
3150 } else {
3151 from->addEdge2EdgeConnection(to, true, myRestrictionException);
3152 for (NBEdge* cand : from->getToNode()->getOutgoingEdges()) {
3153 if (!from->isConnectedTo(cand)) {
3154 from->addEdge2EdgeConnection(cand, true);
3155 }
3156 }
3157 }
3158 }
3159 } else {
3160 // XXX interpreting via-ways or via-node lists not yet implemented
3161 WRITE_WARNINGF(TL("direction of restriction relation could not be determined%"), "");
3162 return false;
3163 }
3164 return true;
3165}
3166
3167NBEdge*
3169 const std::vector<NBEdge*>& candidates) const {
3170 const std::string prefix = toString(wayRef);
3171 const std::string backPrefix = "-" + prefix;
3172 NBEdge* result = nullptr;
3173 int found = 0;
3174 for (auto candidate : candidates) {
3175 const std::string& cid = candidate->getID();
3176 const bool matchFwd = (cid == prefix) || (cid.size() > prefix.size() && cid.compare(0, prefix.size(), prefix) == 0 && cid[prefix.size()] == '#');
3177 const bool matchBwd = (cid == backPrefix) || (cid.size() > backPrefix.size() && cid.compare(0, backPrefix.size(), backPrefix) == 0 && cid[backPrefix.size()] == '#');
3178 if (matchFwd || matchBwd) {
3179 result = candidate;
3180 found++;
3181 }
3182 }
3183 if (found > 1) {
3184 WRITE_WARNINGF(TL("Ambiguous way reference '%' in restriction relation"), prefix);
3185 result = nullptr;
3186 }
3187 return result;
3188}
3189
3190
3191/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define WRITE_MESSAGEF(...)
Definition MsgHandler.h:301
#define WRITE_ERRORF(...)
Definition MsgHandler.h:308
#define WRITE_ERROR(msg)
Definition MsgHandler.h:307
#define WRITE_WARNING(msg)
Definition MsgHandler.h:298
#define PROGRESS_BEGIN_TIME_MESSAGE(msg)
Definition MsgHandler.h:304
#define TL(string)
Definition MsgHandler.h:316
#define PROGRESS_TIME_MESSAGE(before)
Definition MsgHandler.h:305
#define PROGRESS_DONE_MESSAGE()
Definition MsgHandler.h:303
#define TLF(string,...)
Definition MsgHandler.h:318
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition MsgHandler.h:302
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition NBCont.h:42
SVCPermissions extraDisallowed(SVCPermissions disallowed, const MMVersion &networkVersion)
Interprets disallowed vehicles depending on network version.
const SVCPermissions SVCAll
all VClasses are allowed
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permissions is a (exclusive) railway edge.
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
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_SHIP
is an arbitrary ship
@ SVC_PRIVATE
private vehicles
@ SVC_TRUCK
vehicle is a large transport vehicle
@ SVC_ROAD_CLASSES
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_RAIL
vehicle is a not electrified rail
@ SVC_RAIL_CLASSES
classes which drive on tracks
@ SVC_CABLE_CAR
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_RAIL_FAST
vehicle that is allowed to drive on high-speed rail tracks
@ SVC_TRAILER
vehicle is a large transport vehicle
@ SVC_RAIL_ELECTRIC
rail vehicle that requires electrified tracks
@ SVC_RAIL_URBAN
vehicle is a city rail
@ SVC_MOTORCYCLE
vehicle is a motorcycle
@ SVC_EMERGENCY
public emergency vehicles
@ SVC_MOPED
vehicle is a moped
@ SVC_AUTHORITY
authorities vehicles
@ SVC_TRAM
vehicle is a light rail
@ SVC_PUBLIC_CLASSES
public transport
@ SVC_TAXI
vehicle is a taxi
@ SVC_BUS
vehicle is a bus
@ SVC_SUBWAY
@ SVC_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_MEMBER
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_ND
@ SUMO_TAG_WAY
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
@ SUMO_TAG_NODE
alternative definition for junction
@ SUMO_TAG_RELATION
@ SUMO_TAG_TAG
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
@ PARTLEFT
The link is a partial left direction.
@ RIGHT
The link is a (hard) right direction.
@ TURN
The link is a 180 degree turn.
@ LEFT
The link is a (hard) left direction.
@ STRAIGHT
The link is a straight direction.
@ PARTRIGHT
The link is a partial right direction.
@ NODIR
The link has no direction (is a dead end link)
@ SUMO_ATTR_LON
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_V
@ SUMO_ATTR_NUMLANES
@ SUMO_ATTR_REF
@ SUMO_ATTR_LAT
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
@ SUMO_ATTR_ACTION
@ SUMO_ATTR_K
const double SUMO_const_laneWidth
Definition StdDefs.h:52
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string joinToStringSorting(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:347
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:322
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
static bool isReadable(std::string path)
Checks whether the given file is readable.
void setFileName(const std::string &name)
Sets the current file name.
bool wasInformed() const
Returns the information whether any messages were added.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Storage for edges, including some functionality operating on multiple edges.
Definition NBEdgeCont.h:59
int extractRoundabouts()
Determines which edges have been marked as roundabouts and stores them internally.
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
The representation of a single edge during network building.
Definition NBEdge.h:92
static const int TURN_SIGN_SHIFT_BUS
shift values for decoding turn signs
Definition NBEdge.h:379
static const int TURN_SIGN_SHIFT_BICYCLE
Definition NBEdge.h:381
void setPermittedChanging(int lane, SVCPermissions changeLeft, SVCPermissions changeRight)
set allowed classes for changing to the left and right from the given lane
Definition NBEdge.cpp:4536
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition NBEdge.cpp:4545
void setPermissions(SVCPermissions permissions, int lane=-1)
set allowed/disallowed classes for the given lane or for all lanes if -1 is given
Definition NBEdge.cpp:4508
@ ROUNDABOUT
Definition NBEdge.h:387
void addBikeLane(double width)
add a bicycle lane of the given width and shift existing connections
Definition NBEdge.cpp:4751
NBNode * getToNode() const
Returns the destination node of the edge.
Definition NBEdge.h:552
static const double UNSPECIFIED_FRICTION
unspecified lane friction
Definition NBEdge.h:355
Lane & getLaneStruct(int lane)
Definition NBEdge.h:1459
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition NBEdge.h:789
bool addEdge2EdgeConnection(NBEdge *dest, bool overrideRemoval=false, SVCPermissions permission=SVC_UNSPECIFIED)
Adds a connection to another edge.
Definition NBEdge.cpp:1121
void setTurnSignTarget(const std::string &target)
Definition NBEdge.h:1588
void setDistance(double distance)
set kilometrage at start of edge (negative value implies couting down along the edge)
Definition NBEdge.h:1425
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition NBEdge.h:736
const std::string & getID() const
Definition NBEdge.h:1559
void setLaneWidth(int lane, double width)
set lane specific width (negative lane implies set for all lanes)
Definition NBEdge.cpp:4331
void addSidewalk(double width)
add a pedestrian sidewalk of the given width and shift existing connections
Definition NBEdge.cpp:4739
int getNumLanes() const
Returns the number of lanes.
Definition NBEdge.h:526
void setRoundaboutGuessExcluded(bool excluded)
Definition NBEdge.h:1439
void removeFromConnections(NBEdge *toEdge, int fromLane=-1, int toLane=-1, bool tryLater=false, const bool adaptToLaneRemoval=false, const bool keepPossibleTurns=false)
Removes the specified connection(s)
Definition NBEdge.cpp:1474
bool isConnectedTo(const NBEdge *e, const bool ignoreTurnaround=false) const
Returns the information whethe a connection to the given edge has been added (or computed)
Definition NBEdge.cpp:1355
static const int TURN_SIGN_SHIFT_TAXI
Definition NBEdge.h:380
void preferVehicleClass(int lane, SVCPermissions vclasses)
prefer certain vehicle classes for the given lane or for all lanes if -1 is given (ensures also permi...
Definition NBEdge.cpp:4317
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition NBEdge.h:545
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition NBEdge.h:346
void setRoutingType(const std::string &routingType)
set the routingType for this edge
Definition NBEdge.h:1449
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition NBEdge.h:349
void setJunctionPriority(const NBNode *const node, int prio)
Sets the junction priority of the edge.
Definition NBEdge.cpp:2171
void setGeometry(const PositionVector &g, bool inner=false)
(Re)sets the edge's geometry
Definition NBEdge.cpp:661
Instance responsible for building networks.
static bool transformCoordinates(PositionVector &from, bool includeInBoundary=true, GeoConvHelper *from_srs=nullptr)
NBPTLineCont & getPTLineCont()
Returns a reference to the pt line container.
NBParkingCont & getParkingCont()
NBPTStopCont & getPTStopCont()
Returns a reference to the pt stop container.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
NBEdgeCont & getEdgeCont()
NBTypeCont & getTypeCont()
Returns a reference to the type container.
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=nullptr)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
Container for nodes during the netbuilding process.
Definition NBNodeCont.h:57
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Represents a single node (junction) during network building.
Definition NBNode.h:66
bool hasIncoming(const NBEdge *const e) const
Returns whether the given edge ends at this node.
Definition NBNode.cpp:2003
NBNode::Crossing * addCrossing(EdgeVector edges, double width, bool priority, int tlIndex=-1, int tlIndex2=-1, const PositionVector &customShape=PositionVector::EMPTY, bool fromSumoNet=false, const Parameterised *params=nullptr)
add a pedestrian crossing to this node
Definition NBNode.cpp:4089
void reinit(const Position &position, SumoXMLNodeType type, bool updateEdgeGeometries=false)
Resets initial values.
Definition NBNode.cpp:361
SumoXMLNodeType getType() const
Returns the type of this node.
Definition NBNode.h:287
void setRoundaboutType(RoundaboutType roundaboutType)
set roundabout type
Definition NBNode.h:593
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges (The edges which yield in this node)
Definition NBNode.h:270
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges (The edges which start at this node)
Definition NBNode.h:275
bool checkCrossingDuplicated(EdgeVector edges)
return true if there already exist a crossing with the same edges as the input
Definition NBNode.cpp:3030
const Position & getPosition() const
Definition NBNode.h:262
const EdgeVector & getEdges() const
Returns all edges which participate in this node (Edges that start or end at this node)
Definition NBNode.h:280
static const int FORWARD
edge directions (for pedestrian related stuff)
Definition NBNode.h:218
A traffic light logics which must be computed (only nodes/edges are given)
Definition NBOwnTLDef.h:44
void setNumOfStops(int numStops, int missingBefore, int missingAfter)
Definition NBPTLine.cpp:166
void addWayNode(long long int way, long long int node)
Definition NBPTLine.cpp:121
const std::vector< std::shared_ptr< NBPTStop > > & getStops()
Definition NBPTLine.cpp:68
void addPTStop(std::shared_ptr< NBPTStop > pStop)
Definition NBPTLine.cpp:54
Container for public transport stops during the net building process.
const std::map< std::string, std::shared_ptr< NBPTStop > > & getStops() const
Returns an unmodifiable reference to the stored pt stops.
int cleanupDeleted(NBEdgeCont &cont, bool reAssign=false)
remove stops on non existing (removed) edges
std::shared_ptr< NBPTStop > get(std::string id) const
Retrieve a previously inserted pt stop.
bool insert(std::shared_ptr< NBPTStop > ptStop, bool floating=false)
Inserts a node into the map.
The representation of an imported parking area.
Definition NBParking.h:42
static const std::string OSM_DIRECTION
processing parameter for rail signal edges and nodes
static const std::string OSM_SIGNAL_DIRECTION
A container for traffic light definitions and built programs.
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
A storage for available edgeTypes of edges.
Definition NBTypeCont.h:52
bool getEdgeTypeShallBeDiscarded(const std::string &edgeType) const
Returns the information whether edges of this edgeType shall be discarded.
void insertEdgeType(const std::string &id, int numLanes, double maxSpeed, int prio, SVCPermissions permissions, LaneSpreadFunction spreadType, double width, bool oneWayIsDefault, double sidewalkWidth, double bikeLaneWidth, double widthResolution, double maxWidth, double minWidth)
Adds a edgeType into the list.
bool copyEdgeTypeRestrictionsAndAttrs(const std::string &fromId, const std::string &toId)
Copy restrictions to a edgeType.
double getEdgeTypeSpeed(const std::string &edgeType) const
Returns the maximal velocity for the given edgeType [m/s].
int getEdgeTypePriority(const std::string &edgeType) const
Returns the priority for the given edgeType.
int getEdgeTypeNumLanes(const std::string &edgeType) const
Returns the number of lanes for the given edgeType.
double getEdgeTypeWidth(const std::string &edgeType) const
Returns the lane width for the given edgeType [m].
SVCPermissions getEdgeTypePermissions(const std::string &edgeType) const
Returns allowed vehicle classes for the given edgeType.
bool knows(const std::string &edgeType) const
Returns whether the named edgeType is in the container.
double getEdgeTypeSidewalkWidth(const std::string &edgeType) const
Returns the lane width for a sidewalk to be added [m].
LaneSpreadFunction getEdgeTypeSpreadType(const std::string &edgeType) const
Returns spreadType for the given edgeType.
double getEdgeTypeBikeLaneWidth(const std::string &edgeType) const
Returns the lane width for a bike lane to be added [m].
bool getEdgeTypeIsOneWay(const std::string &edgeType) const
Returns whether edges are one-way per default for the given edgeType.
bool operator()(const Edge *e1, const Edge *e2) const
An internal definition of a loaded edge.
int myPlacementLane
1-based lane index for placement specification
std::vector< SVCPermissions > myDisallowedLaneBackward
(optional) information about additional disallowed SVCs on backward lane(s)
DirLaneInfo myDirForward
per-direction lane counts and bus/PSV lane metadata
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.
int myNoLanesBothWays
explicitly tagged center two-way lane count, or 0 if unknown
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.
SVCPermissions myOnewayContraPermissions
Vehicle classes exempted from oneway restriction via oneway:<mode>=no.
double myMaxSpeed
resolved forward maximum speed in m/s, 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.
bool myRoundaboutGuessExcluded
Way metadata that rules out an inferred roundabout.
int myRailDirection
Information about the direction(s) of railway usage.
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.
double myMaxSpeedBase
direction-neutral base maximum speed (maxspeed / maxspeed:type / zone:maxspeed) in m/s,...
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
explicitly tagged backward maximum speed in m/s, 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.
PlacementType myPlacement
placement of the OSM way geometry relative to lanes
bool myIsCircularJunction
Whether OSM explicitly classifies the way as a circular junction.
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.
void addType(const std::string &singleTypeID)
void interpretLaneUse(const std::string &value, SUMOVehicleClass svc, const bool forward) const
int interpretChangeType(const std::string &value) const
EdgesHandler(const std::map< long long int, NIOSMNode * > &osmNodes, std::map< long long int, Edge * > &toFill, std::map< long long int, Edge * > &platformShapes, const NBTypeCont &tc)
Constructor.
void myEndElement(int element) override
Called when a closing tag occurs.
bool interpretPlacement(const std::string &value, NIImporter_OpenStreetMap::PlacementType &placement, int &laneIndex) const
double interpretSpeed(const std::string &key, std::string value)
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;.
int parseBusLaneCount(const std::string &key, const std::string &value) const
A class which extracts OSM-nodes from a parsed OSM-file.
void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
NodesHandler(std::map< long long int, NIOSMNode * > &toFill, std::set< NIOSMNode *, CompareNodes > &uniqueNodes, const OptionsCont &cont)
Constructor.
void myEndElement(int element) override
Called when a closing tag occurs.
StringVector myRailSignalRules
custom requirements for rail signal tagging
A class which extracts relevant relation information from a parsed OSM-file.
void myEndElement(int element) override
Called when a closing tag occurs.
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;.
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.
bool checkEdgeRef(long long int ref) const
check whether a referenced way has a corresponding edge
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
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
WayType
details on the kind of sidewalk, cycleway, busway along this road
void applyLaneUse(NBEdge *e, NIImporter_OpenStreetMap::Edge *nie, const bool forward)
Applies lane use information from nie to e.
bool myOnewayDualSidewalk
import sidewalks
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
int myPlacementSkippedNonExplicitOneWay
number of placement skips due to non-explicit oneway
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.
bool myETCS_movingBlock
whether ETCS signals default to moving block
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
bool myAnnotateDefaults
whether edges should carry information on the use of typemap defaults
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
int myPlacementSkippedAuxOppositeDirection
number of placement skips due to generated opposite-direction auxiliary edges
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)
const std::string & getID() const
Returns the id.
Definition Named.h:73
A storage for options typed value containers)
Definition OptionsCont.h:92
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
void unsetParameter(const std::string &key)
Removes a parameter.
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
void updateParameters(const Parameterised::Map &mapArg)
Adds or updates all given parameters from the map.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
double length2D() const
Returns the length.
double length() const
Returns the length.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
PositionVector reverse() const
reverse position vector
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition RGBColor.cpp:267
Encapsulated SAX-Attributes.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue=T(), bool report=true) const
Tries to read given attribute assuming it is an int.
virtual std::string getStringSecure(int id, const std::string &def) const =0
Returns the string-value of the named (by its enum-value) attribute.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
SAX-handler base for SUMO-files.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(const std::string &str) const
get key
int size() const
returns the number of existing substrings
std::vector< std::string > getVector()
return vector of strings
bool hasNext()
returns the information whether further substrings exist
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined
static bool isBool(const std::string &sData)
check if the given value can be converted to bool
static long long int toLong(const std::string &sData)
converts a string into the long value described by it by calling the char-type converter,...
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
static double parseDist(const std::string &sData)
parse a distance, length or width value with a unit
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
static double parseSpeed(const std::string &sData, const bool defaultKmph=true)
parse a speed value with a unit
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler, const bool isNet=false, const bool isRoute=false)
Builds a reader and assigns the handler to it.
unsigned node
unsigned weight
static double fn[10]
Definition odrSpiral.cpp:87
An (internal) definition of a single lane of an edge.
Definition NBEdge.h:143
int turnSigns
turning signs printed on the road, bitset of LinkDirection (imported from OSM)
Definition NBEdge.h:195
Per-direction lane counts and bus/PSV lane metadata.
An internal representation of an OSM-node.
SVCPermissions permissions
type of pt stop
int railwaySignal
Whether this is a railway (main) signal.
NBNode * node
the NBNode that was instantiated
double positionMeters
position converted to m (using highest precision available)
const long long int id
The node's id.
bool pedestrianCrossing
Whether this is a pedestrian crossing.
bool tlsControlled
Whether this is a tls controlled junction.
double ptStopLength
The length of the pt stop.
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.
WayType myRailDirection
Information about the direction(s) of railway usage.