LCOV - code coverage report
Current view: top level - src/netimport - NIImporter_OpenStreetMap.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 89.1 % 1590 1416
Test Date: 2025-11-13 15:38:19 Functions: 87.5 % 40 35

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    NIImporter_OpenStreetMap.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @author  Walter Bamberger
      19              : /// @author  Gregor Laemmel
      20              : /// @author  Mirko Barthauer
      21              : /// @date    Mon, 14.04.2008
      22              : ///
      23              : // Importer for networks stored in OpenStreetMap format
      24              : /****************************************************************************/
      25              : #include <config.h>
      26              : #include <algorithm>
      27              : #include <set>
      28              : #include <functional>
      29              : #include <sstream>
      30              : #include <limits>
      31              : #include <utils/common/UtilExceptions.h>
      32              : #include <utils/common/StringUtils.h>
      33              : #include <utils/common/ToString.h>
      34              : #include <utils/common/MsgHandler.h>
      35              : #include <utils/common/StringUtils.h>
      36              : #include <utils/common/StringTokenizer.h>
      37              : #include <utils/common/FileHelpers.h>
      38              : #include <utils/geom/GeoConvHelper.h>
      39              : #include <utils/geom/GeomConvHelper.h>
      40              : #include <utils/options/OptionsCont.h>
      41              : #include <utils/xml/SUMOSAXHandler.h>
      42              : #include <utils/xml/SUMOSAXReader.h>
      43              : #include <utils/xml/SUMOXMLDefinitions.h>
      44              : #include <utils/xml/XMLSubSys.h>
      45              : #include <netbuild/NBEdge.h>
      46              : #include <netbuild/NBEdgeCont.h>
      47              : #include <netbuild/NBNode.h>
      48              : #include <netbuild/NBNodeCont.h>
      49              : #include <netbuild/NBNetBuilder.h>
      50              : #include <netbuild/NBOwnTLDef.h>
      51              : #include <netbuild/NBPTLine.h>
      52              : #include <netbuild/NBPTLineCont.h>
      53              : #include <netbuild/NBPTPlatform.h>
      54              : #include <netbuild/NBPTStop.h>
      55              : #include "NILoader.h"
      56              : #include "NIImporter_OpenStreetMap.h"
      57              : 
      58              : //#define DEBUG_LAYER_ELEVATION
      59              : //#define DEBUG_RAIL_DIRECTION
      60              : 
      61              : // ---------------------------------------------------------------------------
      62              : // static members
      63              : // ---------------------------------------------------------------------------
      64              : const double NIImporter_OpenStreetMap::MAXSPEED_UNGIVEN = -1;
      65              : 
      66              : const long long int NIImporter_OpenStreetMap::INVALID_ID = std::numeric_limits<long long int>::max();
      67              : bool NIImporter_OpenStreetMap::myAllAttributes(false);
      68              : std::set<std::string> NIImporter_OpenStreetMap::myExtraAttributes;
      69              : 
      70              : // ===========================================================================
      71              : // Private classes
      72              : // ===========================================================================
      73              : 
      74              : /** @brief Functor which compares two Edges
      75              :  */
      76              : class NIImporter_OpenStreetMap::CompareEdges {
      77              : public:
      78       423709 :     bool operator()(const Edge* e1, const Edge* e2) const {
      79       423709 :         if (e1->myHighWayType != e2->myHighWayType) {
      80       141658 :             return e1->myHighWayType > e2->myHighWayType;
      81              :         }
      82       282051 :         if (e1->myNoLanes != e2->myNoLanes) {
      83        13976 :             return e1->myNoLanes > e2->myNoLanes;
      84              :         }
      85       268075 :         if (e1->myNoLanesForward != e2->myNoLanesForward) {
      86          785 :             return e1->myNoLanesForward > e2->myNoLanesForward;
      87              :         }
      88       267290 :         if (e1->myMaxSpeed != e2->myMaxSpeed) {
      89        13146 :             return e1->myMaxSpeed > e2->myMaxSpeed;
      90              :         }
      91       254144 :         if (e1->myIsOneWay != e2->myIsOneWay) {
      92         9589 :             return e1->myIsOneWay > e2->myIsOneWay;
      93              :         }
      94              :         return e1->myCurrentNodes > e2->myCurrentNodes;
      95              :     }
      96              : };
      97              : 
      98              : // ===========================================================================
      99              : // method definitions
     100              : // ===========================================================================
     101              : // ---------------------------------------------------------------------------
     102              : // static methods
     103              : // ---------------------------------------------------------------------------
     104              : const std::string NIImporter_OpenStreetMap::compoundTypeSeparator("|"); //clang-tidy says: "compundTypeSeparator with
     105              : // static storage duration my throw an exception that cannot be caught
     106              : 
     107              : void
     108         2003 : NIImporter_OpenStreetMap::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
     109         2003 :     NIImporter_OpenStreetMap importer;
     110         2003 :     importer.load(oc, nb);
     111         2003 : }
     112              : 
     113         2003 : NIImporter_OpenStreetMap::NIImporter_OpenStreetMap() = default;
     114              : 
     115         2003 : NIImporter_OpenStreetMap::~NIImporter_OpenStreetMap() {
     116              :     // delete nodes
     117       305784 :     for (auto myUniqueNode : myUniqueNodes) {
     118       303781 :         delete myUniqueNode;
     119              :     }
     120              :     // delete edges
     121        22534 :     for (auto& myEdge : myEdges) {
     122        20531 :         delete myEdge.second;
     123              :     }
     124              :     // delete platform shapes
     125         2470 :     for (auto& myPlatformShape : myPlatformShapes) {
     126          467 :         delete myPlatformShape.second;
     127              :     }
     128         2003 : }
     129              : 
     130              : void
     131         2003 : NIImporter_OpenStreetMap::load(const OptionsCont& oc, NBNetBuilder& nb) {
     132         4006 :     if (!oc.isSet("osm-files")) {
     133         1820 :         return;
     134              :     }
     135          370 :     const std::vector<std::string> files = oc.getStringVector("osm-files");
     136              :     std::vector<SUMOSAXReader*> readers;
     137              : 
     138          185 :     myImportLaneAccess = oc.getBool("osm.lane-access");
     139          185 :     myImportTurnSigns = oc.getBool("osm.turn-lanes");
     140          185 :     myImportSidewalks = oc.getBool("osm.sidewalks");
     141          185 :     myImportBikeAccess = oc.getBool("osm.bike-access");
     142          185 :     myImportCrossings = oc.getBool("osm.crossings");
     143          185 :     myOnewayDualSidewalk = oc.getBool("osm.oneway-reverse-sidewalk");
     144          185 :     myAnnotateDefaults = oc.getBool("osm.annotate-defaults");
     145              : 
     146          185 :     myAllAttributes = OptionsCont::getOptions().getBool("osm.all-attributes");
     147          370 :     std::vector<std::string> extra = OptionsCont::getOptions().getStringVector("osm.extra-attributes");
     148              :     myExtraAttributes.insert(extra.begin(), extra.end());
     149          370 :     if (myExtraAttributes.count("all") != 0) {
     150              :         // import all
     151              :         myExtraAttributes.clear();
     152              :     }
     153              : 
     154              :     // load nodes, first
     155          185 :     NodesHandler nodesHandler(myOSMNodes, myUniqueNodes, oc);
     156          372 :     for (const std::string& file : files) {
     157          378 :         if (!FileHelpers::isReadable(file)) {
     158            0 :             WRITE_ERRORF(TL("Could not open osm-file '%'."), file);
     159            0 :             return;
     160              :         }
     161          189 :         nodesHandler.setFileName(file);
     162              :         nodesHandler.resetHierarchy();
     163          567 :         const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing nodes from osm-file '" + file + "'");
     164          189 :         readers.push_back(XMLSubSys::getSAXReader(nodesHandler));
     165          755 :         if (!readers.back()->parseFirst(file) || !readers.back()->parseSection(SUMO_TAG_NODE) ||
     166          188 :                 MsgHandler::getErrorInstance()->wasInformed()) {
     167              :             return;
     168              :         }
     169          187 :         if (nodesHandler.getDuplicateNodes() > 0) {
     170           32 :             WRITE_MESSAGEF(TL("Found and substituted % osm nodes."), toString(nodesHandler.getDuplicateNodes()));
     171              :         }
     172          187 :         PROGRESS_TIME_MESSAGE(before);
     173              :     }
     174              : 
     175              :     // load edges, then
     176          183 :     EdgesHandler edgesHandler(myOSMNodes, myEdges, myPlatformShapes, nb.getTypeCont());
     177              :     int idx = 0;
     178          370 :     for (const std::string& file : files) {
     179          187 :         edgesHandler.setFileName(file);
     180          187 :         readers[idx]->setHandler(edgesHandler);
     181          561 :         const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing edges from osm-file '" + file + "'");
     182          187 :         if (!readers[idx]->parseSection(SUMO_TAG_WAY)) {
     183              :             // eof already reached, no relations
     184           70 :             delete readers[idx];
     185           70 :             readers[idx] = nullptr;
     186              :         }
     187          187 :         PROGRESS_TIME_MESSAGE(before);
     188          187 :         idx++;
     189              :     }
     190              : 
     191              :     /* Remove duplicate edges with the same shape and attributes */
     192          366 :     if (!oc.getBool("osm.skip-duplicates-check")) {
     193          183 :         int numRemoved = 0;
     194          549 :         PROGRESS_BEGIN_MESSAGE(TL("Removing duplicate edges"));
     195          183 :         if (myEdges.size() > 1) {
     196              :             std::set<const Edge*, CompareEdges> dupsFinder;
     197        21503 :             for (auto it = myEdges.begin(); it != myEdges.end();) {
     198        21332 :                 if (dupsFinder.count(it->second) > 0) {
     199          813 :                     numRemoved++;
     200          813 :                     delete it->second;
     201              :                     myEdges.erase(it++);
     202              :                 } else {
     203              :                     dupsFinder.insert(it->second);
     204              :                     it++;
     205              :                 }
     206              :             }
     207              :         }
     208          183 :         if (numRemoved > 0) {
     209           12 :             WRITE_MESSAGEF(TL("Removed % duplicate osm edges."), toString(numRemoved));
     210              :         }
     211          183 :         PROGRESS_DONE_MESSAGE();
     212              :     }
     213              : 
     214              :     /* Mark which nodes are used (by edges or traffic lights).
     215              :      * This is necessary to detect which OpenStreetMap nodes are for
     216              :      * geometry only */
     217              :     std::map<long long int, int> nodeUsage;
     218              :     // Mark which nodes are used by edges (begin and end)
     219        20714 :     for (const auto& edgeIt : myEdges) {
     220              :         assert(edgeIt.second->myCurrentIsRoad);
     221       134415 :         for (const long long int node : edgeIt.second->myCurrentNodes) {
     222       113884 :             nodeUsage[node]++;
     223              :         }
     224              :     }
     225              :     // Mark which nodes are used by traffic lights or are pedestrian crossings
     226       303875 :     for (const auto& nodesIt : myOSMNodes) {
     227       303692 :         if (nodesIt.second->tlsControlled || nodesIt.second->railwaySignal || (nodesIt.second->pedestrianCrossing && myImportCrossings) /* || nodesIt->second->railwayCrossing*/) {
     228              :             // If the key is not found in the map, the value is automatically
     229              :             // initialized with 0.
     230         3622 :             nodeUsage[nodesIt.first]++;
     231              :         }
     232              :     }
     233              : 
     234              :     /* Instantiate edges
     235              :      * Only those nodes in the middle of an edge which are used by more than
     236              :      * one edge are instantiated. Other nodes are considered as geometry nodes. */
     237              :     NBNodeCont& nc = nb.getNodeCont();
     238              :     NBTrafficLightLogicCont& tlsc = nb.getTLLogicCont();
     239        20714 :     for (const auto& edgeIt : myEdges) {
     240        20531 :         Edge* const e = edgeIt.second;
     241        20531 :         if (!e->myCurrentIsRoad) {
     242          270 :             continue;
     243              :         }
     244        20531 :         if (e->myCurrentNodes.size() < 2) {
     245          270 :             WRITE_WARNINGF(TL("Discarding way '%' because it has only % node(s)"), e->id, e->myCurrentNodes.size());
     246          270 :             continue;
     247              :         }
     248        20261 :         extendRailwayDistances(e, nb.getTypeCont());
     249              :         // build nodes;
     250              :         //  - the from- and to-nodes must be built in any case
     251              :         //  - the in-between nodes are only built if more than one edge references them
     252        20261 :         NBNode* first = insertNodeChecking(e->myCurrentNodes.front(), nc, tlsc);
     253        20261 :         NBNode* last = insertNodeChecking(e->myCurrentNodes.back(), nc, tlsc);
     254              :         NBNode* currentFrom = first;
     255              :         int running = 0;
     256              :         std::vector<long long int> passed;
     257       133996 :         for (auto j = e->myCurrentNodes.begin(); j != e->myCurrentNodes.end(); ++j) {
     258       113735 :             passed.push_back(*j);
     259       113735 :             if (nodeUsage[*j] > 1 && j != e->myCurrentNodes.end() - 1 && j != e->myCurrentNodes.begin()) {
     260        18032 :                 NBNode* currentTo = insertNodeChecking(*j, nc, tlsc);
     261        18032 :                 running = insertEdge(e, running, currentFrom, currentTo, passed, nb, first, last);
     262              :                 currentFrom = currentTo;
     263              :                 passed.clear();
     264        18032 :                 passed.push_back(*j);
     265              :             }
     266              :         }
     267        20261 :         if (running == 0) {
     268              :             running = -1;
     269              :         }
     270        20261 :         insertEdge(e, running, currentFrom, last, passed, nb, first, last);
     271        20261 :     }
     272              : 
     273              :     /* Collect edges which explicitly are part of a roundabout and store the edges of each
     274              :      * detected roundabout */
     275          183 :     nb.getEdgeCont().extractRoundabouts();
     276              : 
     277          183 :     if (myImportCrossings) {
     278              :         /* After edges are instantiated
     279              :          * nodes are parsed again to add pedestrian crossings to them
     280              :          * This is only executed if crossings are imported and not guessed */
     281            2 :         const double crossingWidth = OptionsCont::getOptions().getFloat("default.crossing-width");
     282              : 
     283           14 :         for (auto item : nodeUsage) {
     284           13 :             NIOSMNode* osmNode = myOSMNodes.find(item.first)->second;
     285           13 :             if (osmNode->pedestrianCrossing) {
     286            5 :                 NBNode* n = osmNode->node;
     287            5 :                 EdgeVector incomingEdges = n->getIncomingEdges();
     288            5 :                 EdgeVector outgoingEdges = n->getOutgoingEdges();
     289              :                 size_t incomingEdgesNo = incomingEdges.size();
     290              :                 size_t outgoingEdgesNo = outgoingEdges.size();
     291              : 
     292           21 :                 for (size_t i = 0; i < incomingEdgesNo; i++) {
     293              :                     /* Check if incoming edge has driving lanes(and sidewalks)
     294              :                      * if not, ignore
     295              :                      * if yes, check if there is a corresponding outgoing edge for the opposite direction
     296              :                      *   -> if yes, check if it has driving lanes
     297              :                      *          --> if yes, do the crossing
     298              :                      *          --> if no, only do the crossing with the incoming edge (usually one lane roads with two sidewalks)
     299              :                      *   -> if not, do nothing as we don't have a sidewalk in the opposite direction */
     300           16 :                     auto const iEdge = incomingEdges[i];
     301              : 
     302           16 :                     if (iEdge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD) > -1
     303           16 :                             && iEdge->getSpecialLane(SVC_PEDESTRIAN) > -1) {
     304           12 :                         std::string const& iEdgeId = iEdge->getID();
     305              :                         std::size_t const m = iEdgeId.find_first_of("#");
     306           12 :                         std::string const& iWayId = iEdgeId.substr(0, m);
     307           53 :                         for (size_t j = 0; j < outgoingEdgesNo; j++) {
     308           41 :                             auto const oEdge = outgoingEdges[j];
     309              :                             // Searching for a corresponding outgoing edge (based on OSM way identifier)
     310              :                             // with at least a pedestrian lane, going in the opposite direction
     311           41 :                             if (oEdge->getID().find(iWayId) != std::string::npos
     312           19 :                                     && oEdge->getSpecialLane(SVC_PEDESTRIAN) > -1
     313           79 :                                     && oEdge->getID().rfind(iWayId, 0) != 0) {
     314            9 :                                 EdgeVector edgeVector = EdgeVector{ iEdge };
     315            9 :                                 if (oEdge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD) > -1) {
     316            3 :                                     edgeVector.push_back(oEdge);
     317              :                                 }
     318              : 
     319            9 :                                 if (!n->checkCrossingDuplicated(edgeVector)) {
     320            9 :                                     n->addCrossing(edgeVector, crossingWidth, false);
     321              :                                 }
     322            9 :                             }
     323              :                         }
     324              :                     }
     325              :                 }
     326           21 :                 for (size_t i = 0; i < outgoingEdgesNo; i++) {
     327              :                     // Same checks as above for loop, but for outgoing edges
     328           16 :                     auto const oEdge = outgoingEdges[i];
     329              : 
     330           16 :                     if (oEdge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD) > -1
     331           16 :                             && oEdge->getSpecialLane(SVC_PEDESTRIAN) > -1) {
     332           10 :                         std::string const& oEdgeId = oEdge->getID();
     333              :                         std::size_t const m = oEdgeId.find_first_of("#");
     334           10 :                         std::string const& iWayId = oEdgeId.substr(0, m);
     335           45 :                         for (size_t j = 0; j < incomingEdgesNo; j++) {
     336           35 :                             auto const iEdge = incomingEdges[j];
     337           35 :                             if (iEdge->getID().find(iWayId) != std::string::npos
     338           17 :                                     && iEdge->getSpecialLane(SVC_PEDESTRIAN) > -1
     339           69 :                                     && iEdge->getID().rfind(iWayId, 0) != 0) {
     340            7 :                                 EdgeVector edgeVector = EdgeVector{ oEdge };
     341            7 :                                 if (iEdge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD) > -1) {
     342            3 :                                     edgeVector.push_back(iEdge);
     343              :                                 }
     344              : 
     345            7 :                                 if (!n->checkCrossingDuplicated(edgeVector)) {
     346            7 :                                     n->addCrossing(edgeVector, crossingWidth, false);
     347              :                                 }
     348            7 :                             }
     349              :                         }
     350              :                     }
     351              :                 }
     352            5 :             }
     353              :         }
     354              :     }
     355              : 
     356          183 :     const double layerElevation = oc.getFloat("osm.layer-elevation");
     357          183 :     if (layerElevation > 0) {
     358            0 :         reconstructLayerElevation(layerElevation, nb);
     359              :     }
     360              : 
     361              :     // revise pt stops; remove stops on deleted edges
     362          183 :     nb.getPTStopCont().cleanupDeleted(nb.getEdgeCont());
     363              : 
     364              :     // load relations (after edges are built since we want to apply
     365              :     // turn-restrictions directly to NBEdges)
     366              :     RelationHandler relationHandler(myOSMNodes, myEdges, &(nb.getPTStopCont()), myPlatformShapes,
     367          183 :                                     &nb.getPTLineCont(), oc);
     368              :     idx = 0;
     369          370 :     for (const std::string& file : files) {
     370          187 :         if (readers[idx] != nullptr) {
     371          117 :             relationHandler.setFileName(file);
     372          117 :             readers[idx]->setHandler(relationHandler);
     373          351 :             const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing relations from osm-file '" + file + "'");
     374          117 :             readers[idx]->parseSection(SUMO_TAG_RELATION);
     375          117 :             PROGRESS_TIME_MESSAGE(before);
     376          117 :             delete readers[idx];
     377              :         }
     378          187 :         idx++;
     379              :     }
     380              : 
     381              :     // declare additional stops that are not anchored to a (road)-way or route relation
     382              :     std::set<std::string> stopNames;
     383         1697 :     for (const auto& item : nb.getPTStopCont().getStops()) {
     384         3028 :         stopNames.insert(item.second->getName());
     385              :     }
     386       303875 :     for (const auto& item : myOSMNodes) {
     387       303692 :         const NIOSMNode* n = item.second;
     388       303692 :         if (n->ptStopPosition && stopNames.count(n->name) == 0) {
     389          124 :             Position ptPos(n->lon, n->lat, n->ele);
     390          124 :             if (!NBNetBuilder::transformCoordinate(ptPos)) {
     391            0 :                 WRITE_ERRORF("Unable to project coordinates for node '%'.", n->id);
     392              :             }
     393          248 :             std::shared_ptr<NBPTStop> ptStop = std::make_shared<NBPTStop>(toString(n->id), ptPos, "", "", n->ptStopLength, n->name, n->permissions);
     394          248 :             nb.getPTStopCont().insert(ptStop, true);
     395              :         }
     396              :     }
     397          368 : }
     398              : 
     399              : // ---------------------------------------------------------------------------
     400              : // definitions of NIImporter_OpenStreetMap-methods
     401              : // ---------------------------------------------------------------------------
     402              : 
     403              : NBNode*
     404        58663 : NIImporter_OpenStreetMap::insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc) {
     405        58663 :     NBNode* node = nc.retrieve(toString(id));
     406        58663 :     if (node == nullptr) {
     407        30975 :         NIOSMNode* n = myOSMNodes.find(id)->second;
     408        30975 :         Position pos(n->lon, n->lat, n->ele);
     409        30975 :         if (!NBNetBuilder::transformCoordinate(pos, true)) {
     410            0 :             WRITE_ERRORF("Unable to project coordinates for junction '%'.", id);
     411            0 :             return nullptr;
     412              :         }
     413        30975 :         node = new NBNode(toString(id), pos);
     414        30975 :         if (!nc.insert(node)) {
     415            0 :             WRITE_ERRORF(TL("Could not insert junction '%'."), toString(id));
     416            0 :             delete node;
     417            0 :             return nullptr;
     418              :         }
     419        30975 :         n->node = node;
     420        30975 :         if (n->railwayCrossing) {
     421         1574 :             if (n->getParameter("crossing:barrier") != "no") {
     422          652 :                 node->reinit(pos, SumoXMLNodeType::RAIL_CROSSING);
     423          270 :             } else if (n->getParameter("crossing.light") == "yes") {
     424            0 :                 node->reinit(pos, SumoXMLNodeType::TRAFFIC_LIGHT);
     425              :             }
     426        30188 :         } else if (n->railwaySignal) {
     427          863 :             node->reinit(pos, SumoXMLNodeType::RAIL_SIGNAL);
     428        29325 :         } else if (n->tlsControlled) {
     429              :             // ok, this node is a traffic light node where no other nodes
     430              :             //  participate
     431              :             // @note: The OSM-community has not settled on a schema for differentiating between fixed and actuated lights
     432         2456 :             TrafficLightType type = SUMOXMLDefinitions::TrafficLightTypes.get(
     433         2456 :                                         OptionsCont::getOptions().getString("tls.default-type"));
     434         2456 :             NBOwnTLDef* tlDef = new NBOwnTLDef(toString(id), node, 0, type);
     435         2456 :             if (!tlsc.insert(tlDef)) {
     436              :                 // actually, nothing should fail here
     437            0 :                 delete tlDef;
     438            0 :                 throw ProcessError(TLF("Could not allocate tls '%'.", toString(id)));
     439              :             }
     440              :         }
     441        30975 :         if (n->railwayBufferStop) {
     442          124 :             node->setParameter("buffer_stop", "true");
     443              :             node->setFringeType(FringeType::INNER);
     444              :         }
     445        30975 :         if (n->railwaySignal) {
     446          863 :             if (n->myRailDirection == WAY_FORWARD) {
     447         1308 :                 node->setParameter(NBTrafficLightDefinition::OSM_SIGNAL_DIRECTION, "forward");
     448          209 :             } else if (n->myRailDirection == WAY_BACKWARD) {
     449          404 :                 node->setParameter(NBTrafficLightDefinition::OSM_SIGNAL_DIRECTION, "backward");
     450              :             }
     451              :         }
     452        30975 :         node->updateParameters(n->getParametersMap());
     453              :     }
     454              :     return node;
     455              : }
     456              : 
     457              : 
     458              : int
     459        38511 : NIImporter_OpenStreetMap::insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
     460              :                                      const std::vector<long long int>& passed, NBNetBuilder& nb,
     461              :                                      const NBNode* first, const NBNode* last) {
     462              :     NBNodeCont& nc = nb.getNodeCont();
     463              :     NBEdgeCont& ec = nb.getEdgeCont();
     464              :     NBTypeCont& tc = nb.getTypeCont();
     465              :     NBPTStopCont& sc = nb.getPTStopCont();
     466              : 
     467              :     NBTrafficLightLogicCont& tlsc = nb.getTLLogicCont();
     468              :     // patch the id
     469        38511 :     std::string id = toString(e->id);
     470        38511 :     if (from == nullptr || to == nullptr) {
     471            0 :         WRITE_ERRORF("Discarding edge '%' because the nodes could not be built.", id);
     472            0 :         return index;
     473              :     }
     474        38511 :     if (index >= 0) {
     475        53456 :         id = id + "#" + toString(index);
     476              :     } else {
     477        11783 :         index = 0;
     478              :     }
     479        38511 :     if (from == to) {
     480              :         assert(passed.size() >= 2);
     481          109 :         if (passed.size() == 2) {
     482            0 :             WRITE_WARNINGF(TL("Discarding edge '%' which connects two identical nodes without geometry."), id);
     483            0 :             return index;
     484              :         }
     485              :         // in the special case of a looped way split again using passed
     486          109 :         int intermediateIndex = (int) passed.size() / 2;
     487          109 :         NBNode* intermediate = insertNodeChecking(passed[intermediateIndex], nc, tlsc);
     488          109 :         std::vector<long long int> part1(passed.begin(), passed.begin() + intermediateIndex + 1);
     489          109 :         std::vector<long long int> part2(passed.begin() + intermediateIndex, passed.end());
     490          109 :         index = insertEdge(e, index, from, intermediate, part1, nb, first, last);
     491          109 :         return insertEdge(e, index, intermediate, to, part2, nb, first, last);
     492          109 :     }
     493        38402 :     const int newIndex = index + 1;
     494        38402 :     const std::string type = usableType(e->myHighWayType, id, tc);
     495        38402 :     if (type == "") {  // we do not want to import it
     496              :         return newIndex;
     497              :     }
     498              : 
     499        37340 :     int numLanesForward = tc.getEdgeTypeNumLanes(type);
     500        37340 :     int numLanesBackward = tc.getEdgeTypeNumLanes(type);
     501        37340 :     double speed = tc.getEdgeTypeSpeed(type);
     502        37340 :     bool defaultsToOneWay = tc.getEdgeTypeIsOneWay(type);
     503        37340 :     const SVCPermissions defaultPermissions = tc.getEdgeTypePermissions(type);
     504        37340 :     SVCPermissions extra = myImportBikeAccess ? e->myExtraAllowed : (e->myExtraAllowed & ~SVC_BICYCLE);
     505        37340 :     const SVCPermissions extraDis = myImportBikeAccess ? e->myExtraDisallowed : (e->myExtraDisallowed & ~SVC_BICYCLE);
     506              :     std::vector<SumoXMLAttr> defaults;
     507              :     // extra permissions are more specific than extra prohibitions except for buses (which come from the less specific psv tag)
     508        37340 :     if ((extraDis & SVC_BUS) && (extra & SVC_BUS)) {
     509            1 :         extra = extra & ~SVC_BUS;
     510              :     }
     511        37340 :     SVCPermissions permissions = (defaultPermissions & ~extraDis) | extra;
     512        37340 :     if (defaultPermissions == SVC_SHIP) {
     513              :         // extra permission apply to the ships operating on the route rather than the waterway
     514              :         permissions = defaultPermissions;
     515              :     }
     516        37340 :     if (defaultsToOneWay && defaultPermissions == SVC_PEDESTRIAN && (permissions & (~SVC_PEDESTRIAN)) != 0) {
     517              :         defaultsToOneWay = false;
     518              :     }
     519        39610 :     if ((permissions & SVC_RAIL) != 0 && e->myExtraTags.count("electrified") != 0) {
     520          543 :         permissions |= (SVC_RAIL_ELECTRIC | SVC_RAIL_FAST);
     521              :     }
     522              : 
     523              :     // convert the shape
     524        37340 :     PositionVector shape;
     525        37340 :     double distanceStart = myOSMNodes[passed.front()]->positionMeters;
     526        37340 :     double distanceEnd = myOSMNodes[passed.back()]->positionMeters;
     527        37340 :     const bool useDistance = distanceStart != std::numeric_limits<double>::max() && distanceEnd != std::numeric_limits<double>::max();
     528        37340 :     if (useDistance) {
     529              :         // negative sign denotes counting in the other direction
     530          486 :         if (distanceStart < distanceEnd) {
     531          396 :             distanceStart *= -1;
     532              :         } else {
     533           90 :             distanceEnd *= -1;
     534              :         }
     535              :     } else {
     536              :         distanceStart = 0;
     537              :         distanceEnd = 0;
     538              :     }
     539              :     // get additional direction information
     540        74680 :     int nodeDirection = myOSMNodes.find(StringUtils::toLong(from->getID()))->second->myRailDirection |
     541        74680 :                         myOSMNodes.find(StringUtils::toLong(to->getID()))->second->myRailDirection;
     542              : 
     543              :     std::vector<std::shared_ptr<NBPTStop> > ptStops;
     544       160747 :     for (long long i : passed) {
     545       123407 :         NIOSMNode* n = myOSMNodes.find(i)->second;
     546              :         // recheck permissions, maybe they got assigned to a strange edge, see #11656
     547       123407 :         if (n->ptStopPosition && (n->permissions == 0 || (permissions & n->permissions) != 0)) {
     548         3282 :             std::shared_ptr<NBPTStop> existingPtStop = sc.get(toString(n->id));
     549         1641 :             if (existingPtStop != nullptr) {
     550          376 :                 existingPtStop->registerAdditionalEdge(toString(e->id), id);
     551              :             } else {
     552         1453 :                 Position ptPos(n->lon, n->lat, n->ele);
     553         1453 :                 if (!NBNetBuilder::transformCoordinate(ptPos)) {
     554            0 :                     WRITE_ERRORF("Unable to project coordinates for node '%'.", n->id);
     555              :                 }
     556         2906 :                 ptStops.push_back(std::make_shared<NBPTStop>(toString(n->id), ptPos, id, toString(e->id), n->ptStopLength, n->name, n->permissions));
     557         2906 :                 sc.insert(ptStops.back());
     558              :             }
     559              :         }
     560       123407 :         if (n->railwaySignal) {
     561         1723 :             nodeDirection |= n->myRailDirection;
     562              :         }
     563       123407 :         Position pos(n->lon, n->lat, n->ele);
     564       123407 :         shape.push_back(pos);
     565              :     }
     566              : #ifdef DEBUG_LAYER_ELEVATION
     567              :     if (e->id == "DEBUGID") {
     568              :         std::cout
     569              :                 << " id=" << id << " from=" << from->getID() << " fromRailDirection=" << myOSMNodes.find(StringUtils::toLong(from->getID()))->second->myRailDirection
     570              :                 << " to=" << to->getID() << " toRailDirection=" << myOSMNodes.find(StringUtils::toLong(to->getID()))->second->myRailDirection
     571              :                 << " origRailDirection=" << e->myRailDirection
     572              :                 << " nodeDirection=" << nodeDirection
     573              :                 << "\n";
     574              :     }
     575              : #endif
     576        37340 :     if (e->myRailDirection == WAY_UNKNOWN && nodeDirection != WAY_UNKNOWN && nodeDirection != WAY_FORWARD
     577          986 :             && nodeDirection != (WAY_FORWARD | WAY_UNKNOWN)) {
     578              :         //std::cout << "way " << e->id << " nodeDirection=" << nodeDirection << " origDirection=" << e->myRailDirection << "\n";
     579              :         // heuristic: assume that the mapped way direction indicates
     580              :         // potential driving direction
     581          223 :         e->myRailDirection = WAY_BOTH;
     582              :     }
     583        37340 :     if (!NBNetBuilder::transformCoordinates(shape)) {
     584            0 :         WRITE_ERRORF("Unable to project coordinates for edge '%'.", id);
     585              :     }
     586              : 
     587              :     SVCPermissions forwardPermissions = permissions;
     588              :     SVCPermissions backwardPermissions = permissions;
     589        37340 :     const std::string streetName = isRailway(permissions) && e->ref != "" ? e->ref : e->streetName;
     590        37340 :     if (streetName == e->ref) {
     591        48888 :         e->unsetParameter("ref"); // avoid superfluous param for railways
     592              :     }
     593        37340 :     double forwardWidth = tc.getEdgeTypeWidth(type);
     594        37340 :     double backwardWidth = tc.getEdgeTypeWidth(type);
     595        37340 :     double sidewalkWidth = tc.getEdgeTypeSidewalkWidth(type);
     596        37340 :     bool addSidewalk = sidewalkWidth != NBEdge::UNSPECIFIED_WIDTH;
     597        37340 :     if (myImportSidewalks) {
     598         5281 :         if (addSidewalk) {
     599              :             // only use sidewalk width from typemap but don't add sidewalks
     600              :             // unless OSM specifies them
     601              :             addSidewalk = false;
     602              :         } else {
     603         8258 :             sidewalkWidth = OptionsCont::getOptions().getFloat("default.sidewalk-width");
     604              :         }
     605              :     }
     606        37340 :     double bikeLaneWidth = tc.getEdgeTypeBikeLaneWidth(type);
     607        37340 :     const std::string& onewayBike = e->myExtraTags["oneway:bicycle"];
     608        37340 :     if (onewayBike == "false" || onewayBike == "no" || onewayBike == "0") {
     609          602 :         e->myCyclewayType = e->myCyclewayType == WAY_UNKNOWN ? WAY_BACKWARD : (WayType)(e->myCyclewayType | WAY_BACKWARD);
     610              :     }
     611              : 
     612        37340 :     const bool addBikeLane = bikeLaneWidth != NBEdge::UNSPECIFIED_WIDTH ||
     613        41560 :                              (myImportBikeAccess && (((e->myCyclewayType & WAY_BOTH) != 0 || e->myExtraTags.count("segregated") != 0) &&
     614           68 :                                      !(e->myCyclewayType == WAY_BACKWARD && (e->myBuswayType & WAY_BOTH) != 0)));
     615        37340 :     if (addBikeLane && bikeLaneWidth == NBEdge::UNSPECIFIED_WIDTH) {
     616          136 :         bikeLaneWidth = OptionsCont::getOptions().getFloat("default.bikelane-width");
     617              :     }
     618              :     // check directions
     619              :     bool addForward = true;
     620              :     bool addBackward = true;
     621        37340 :     const bool explicitTwoWay = e->myIsOneWay == "no";
     622        36442 :     if ((e->myIsOneWay == "true" || e->myIsOneWay == "yes" || e->myIsOneWay == "1"
     623        29119 :             || (defaultsToOneWay && e->myIsOneWay != "no" && e->myIsOneWay != "false" && e->myIsOneWay != "0"))
     624        62944 :             && e->myRailDirection != WAY_BOTH) {
     625              :         addBackward = false;
     626              :     }
     627        37340 :     if (e->myIsOneWay == "-1" || e->myIsOneWay == "reverse" || e->myRailDirection == WAY_BACKWARD) {
     628              :         // one-way in reversed direction of way
     629              :         addForward = false;
     630              :         addBackward = true;
     631              :     }
     632         8748 :     if (!e->myIsOneWay.empty() && e->myIsOneWay != "false" && e->myIsOneWay != "no" && e->myIsOneWay != "true"
     633        44667 :             && e->myIsOneWay != "yes" && e->myIsOneWay != "-1" && e->myIsOneWay != "1" && e->myIsOneWay != "reverse") {
     634            0 :         WRITE_WARNINGF(TL("New value for oneway found: %"), e->myIsOneWay);
     635              :     }
     636        37340 :     if ((permissions == SVC_BICYCLE || permissions == (SVC_BICYCLE | SVC_PEDESTRIAN) || permissions == SVC_PEDESTRIAN)) {
     637        16064 :         if (addBackward && (onewayBike == "true" || onewayBike == "yes" || onewayBike == "1")) {
     638              :             addBackward = false;
     639              :         }
     640        16064 :         if (addForward && (onewayBike == "reverse" || onewayBike == "-1")) {
     641              :             addForward = false;
     642              :         }
     643        16064 :         if (!addBackward && (onewayBike == "false" || onewayBike == "no" || onewayBike == "0")) {
     644              :             addBackward = true;
     645              :         }
     646              :     }
     647              :     bool ok = true;
     648              :     // if we had been able to extract the number of lanes, override the highway type default
     649        37340 :     if (e->myNoLanes > 0) {
     650         6987 :         if (addForward && !addBackward) {
     651         4694 :             numLanesForward = e->myNoLanesForward > 0 ? e->myNoLanesForward : e->myNoLanes;
     652         2293 :         } else if (!addForward && addBackward) {
     653            2 :             numLanesBackward = e->myNoLanesForward < 0 ? -e->myNoLanesForward : e->myNoLanes;
     654              :         } else {
     655         2291 :             if (e->myNoLanesForward > 0) {
     656              :                 numLanesForward = e->myNoLanesForward;
     657         1628 :             } else if (e->myNoLanesForward < 0) {
     658           26 :                 numLanesForward = e->myNoLanes + e->myNoLanesForward;
     659              :             } else {
     660         1602 :                 numLanesForward = (int) std::ceil(e->myNoLanes / 2.0);
     661              :             }
     662         2291 :             numLanesBackward = e->myNoLanes - numLanesForward;
     663              :             // sometimes ways are tagged according to their physical width of a single
     664              :             // lane but they are intended for traffic in both directions
     665              :             numLanesForward = MAX2(1, numLanesForward);
     666              :             numLanesBackward = MAX2(1, numLanesBackward);
     667              :         }
     668        30353 :     } else if (e->myNoLanes == 0) {
     669            0 :         WRITE_WARNINGF(TL("Skipping edge '%' because it has zero lanes."), id);
     670              :         ok = false;
     671              :     } else {
     672              :         // the total number of lanes is not known but at least one direction
     673        30353 :         if (e->myNoLanesForward > 0) {
     674              :             numLanesForward = e->myNoLanesForward;
     675        30353 :         } else if ((e->myBuswayType & WAY_FORWARD) != 0 && (extraDis & SVC_PASSENGER) == 0) {
     676              :             // if we have a busway lane, yet cars may drive this implies at least two lanes
     677              :             numLanesForward = MAX2(numLanesForward, 2);
     678              :         }
     679        30353 :         if (e->myNoLanesForward < 0) {
     680            0 :             numLanesBackward = -e->myNoLanesForward;
     681        30353 :         } else if ((e->myBuswayType & WAY_BACKWARD) != 0 && (extraDis & SVC_PASSENGER) == 0) {
     682              :             // if we have a busway lane, yet cars may drive this implies at least two lanes
     683              :             numLanesBackward = MAX2(numLanesForward, 2);
     684              :         }
     685        30353 :         if (myAnnotateDefaults && e->myNoLanesForward == 0) {
     686          119 :             defaults.push_back(SUMO_ATTR_NUMLANES);
     687              :         }
     688              :     }
     689              :     // deal with busways that run in the opposite direction of a one-way street
     690        37340 :     if (!addForward && (e->myBuswayType & WAY_FORWARD) != 0) {
     691              :         addForward = true;
     692              :         forwardPermissions = SVC_BUS;
     693              :         numLanesForward = 1;
     694              :     }
     695        37340 :     if (!addBackward && (e->myBuswayType & WAY_BACKWARD) != 0) {
     696              :         addBackward = true;
     697              :         backwardPermissions = SVC_BUS;
     698              :         numLanesBackward = 1;
     699              :     }
     700              :     // with is meant for raw lane count before adding sidewalks or cycleways
     701        37349 :     const int taggedLanes = (addForward ? numLanesForward : 0) + (addBackward ? numLanesBackward : 0);
     702         1408 :     if (e->myWidth > 0 && e->myWidthLanesForward.size() == 0 && e->myWidthLanesBackward.size() == 0 && taggedLanes != 0
     703        40338 :             && !OptionsCont::getOptions().getBool("ignore-widths")) {
     704              :         // width is tagged excluding sidewalks and cycleways
     705         1226 :         forwardWidth = e->myWidth / taggedLanes;
     706              :         backwardWidth = forwardWidth;
     707              :     }
     708              : 
     709              :     // if we had been able to extract the maximum speed, override the type's default
     710        37340 :     if (e->myMaxSpeed != MAXSPEED_UNGIVEN) {
     711              :         speed = e->myMaxSpeed;
     712        25078 :     } else if (myAnnotateDefaults) {
     713          124 :         defaults.push_back(SUMO_ATTR_SPEED);
     714              :     }
     715              :     double speedBackward = speed;
     716        37340 :     if (e->myMaxSpeedBackward != MAXSPEED_UNGIVEN) {
     717              :         speedBackward = e->myMaxSpeedBackward;
     718              :     }
     719        37340 :     if (speed <= 0 || speedBackward <= 0) {
     720            0 :         WRITE_WARNINGF(TL("Skipping edge '%' because it has speed %."), id, speed);
     721              :         ok = false;
     722              :     }
     723              :     // deal with cycleways that run in the opposite direction of a one-way street
     724        37340 :     WayType cyclewayType = e->myCyclewayType; // make a copy because we do some temporary modifications
     725        37340 :     if (addBikeLane) {
     726          464 :         if (!addForward && (cyclewayType & WAY_FORWARD) != 0) {
     727              :             addForward = true;
     728              :             forwardPermissions = SVC_BICYCLE;
     729              :             forwardWidth = bikeLaneWidth;
     730              :             numLanesForward = 1;
     731              :             // do not add an additional cycle lane
     732              :             cyclewayType = (WayType)(cyclewayType & ~WAY_FORWARD);
     733              :         }
     734          464 :         if (!addBackward && (cyclewayType & WAY_BACKWARD) != 0) {
     735              :             addBackward = true;
     736              :             backwardPermissions = SVC_BICYCLE;
     737              :             backwardWidth = bikeLaneWidth;
     738              :             numLanesBackward = 1;
     739              :             // do not add an additional cycle lane
     740              :             cyclewayType = (WayType)(cyclewayType & ~WAY_BACKWARD);
     741              :         }
     742              :     }
     743              :     // deal with sidewalks that run in the opposite direction of a one-way street
     744        37340 :     WayType sidewalkType = e->mySidewalkType; // make a copy because we do some temporary modifications
     745        37340 :     if (sidewalkType == WAY_UNKNOWN && (e->myExtraAllowed & SVC_PEDESTRIAN) != 0 && (permissions & SVC_PASSENGER) != 0) {
     746              :         // do not assume shared space unless sidewalk is actively disabled
     747           41 :         if (myOnewayDualSidewalk) {
     748              :             sidewalkType = WAY_BOTH;
     749              :         }
     750              :     }
     751        37340 :     if (addSidewalk || (myImportSidewalks && (permissions & SVC_ROAD_CLASSES) != 0 && defaultPermissions != SVC_PEDESTRIAN)) {
     752         3253 :         if (!addForward && (sidewalkType & WAY_FORWARD) != 0) {
     753              :             addForward = true;
     754              :             forwardPermissions = SVC_PEDESTRIAN;
     755            0 :             forwardWidth = tc.getEdgeTypeSidewalkWidth(type);
     756              :             numLanesForward = 1;
     757              :             // do not add an additional sidewalk
     758            0 :             sidewalkType = (WayType)(sidewalkType & ~WAY_FORWARD);  //clang tidy thinks "!WAY_FORWARD" is always false
     759         3253 :         } else if (addSidewalk && addForward && (sidewalkType & WAY_BOTH) == 0
     760          232 :                    && numLanesForward == 1 && numLanesBackward <= 1
     761          184 :                    && (e->myExtraDisallowed & SVC_PEDESTRIAN) == 0) {
     762              :             // our typemap says pedestrians should walk here but the data says
     763              :             // there is no sidewalk at all. If the road is small, pedestrians can just walk
     764              :             // on the road
     765          154 :             forwardPermissions |= SVC_PEDESTRIAN;
     766              :         }
     767         3253 :         if (!addBackward && (sidewalkType & WAY_BACKWARD) != 0) {
     768              :             addBackward = true;
     769              :             backwardPermissions = SVC_PEDESTRIAN;
     770          101 :             backwardWidth = tc.getEdgeTypeSidewalkWidth(type);
     771              :             numLanesBackward = 1;
     772              :             // do not add an additional cycle lane
     773          101 :             sidewalkType = (WayType)(sidewalkType & ~WAY_BACKWARD); //clang tidy thinks "!WAY_BACKWARD" is always false
     774         3152 :         } else if (addSidewalk && addBackward && (sidewalkType & WAY_BOTH) == 0
     775          128 :                    && numLanesBackward == 1 && numLanesForward <= 1
     776          110 :                    && (e->myExtraDisallowed & SVC_PEDESTRIAN) == 0) {
     777              :             // our typemap says pedestrians should walk here but the data says
     778              :             // there is no sidewalk at all. If the road is small, pedestrians can just walk
     779              :             // on the road
     780          103 :             backwardPermissions |= SVC_PEDESTRIAN;
     781              :         }
     782              :     }
     783              : 
     784        37340 :     const std::string origID = OptionsCont::getOptions().getBool("output.original-names") ? toString(e->id) : "";
     785        37340 :     if (ok) {
     786        37340 :         const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
     787        37340 :         const int offsetFactor = lefthand ? -1 : 1;
     788        37340 :         LaneSpreadFunction lsf = (addBackward || OptionsCont::getOptions().getBool("osm.oneway-spread-right")) &&
     789        37340 :                                  (e->myRailDirection == WAY_UNKNOWN || explicitTwoWay)  ? LaneSpreadFunction::RIGHT : LaneSpreadFunction::CENTER;
     790        70283 :         if (addBackward && lsf == LaneSpreadFunction::RIGHT && OptionsCont::getOptions().getString("default.spreadtype") == toString(LaneSpreadFunction::ROADCENTER)) {
     791              :             lsf = LaneSpreadFunction::ROADCENTER;
     792              :         }
     793        37340 :         if (tc.getEdgeTypeSpreadType(type) != LaneSpreadFunction::RIGHT) {
     794              :             // user defined value overrides defaults
     795           31 :             lsf = tc.getEdgeTypeSpreadType(type);
     796              :         }
     797        37340 :         if (defaults.size() > 0) {
     798          248 :             e->setParameter("osmDefaults", joinToString(defaults, " "));
     799              :         }
     800              : 
     801        37340 :         id = StringUtils::escapeXML(id);
     802        37340 :         const std::string reverseID = "-" + id;
     803        37340 :         const bool markOSMDirection =  from->getType() == SumoXMLNodeType::RAIL_SIGNAL || to->getType() == SumoXMLNodeType::RAIL_SIGNAL;
     804        37340 :         if (addForward) {
     805              :             assert(numLanesForward > 0);
     806              :             NBEdge* nbe = new NBEdge(id, from, to, type, speed, NBEdge::UNSPECIFIED_FRICTION, numLanesForward, tc.getEdgeTypePriority(type),
     807              :                                      forwardWidth, NBEdge::UNSPECIFIED_OFFSET, shape, lsf,
     808       149324 :                                      StringUtils::escapeXML(streetName), origID, true);
     809        37331 :             if (markOSMDirection) {
     810         2806 :                 nbe->setParameter(NBTrafficLightDefinition::OSM_DIRECTION, "forward");
     811              :             }
     812        37331 :             nbe->setPermissions(forwardPermissions, -1);
     813        37331 :             if ((e->myBuswayType & WAY_FORWARD) != 0) {
     814           18 :                 nbe->setPermissions(SVC_BUS, 0);
     815              :             }
     816        37331 :             applyChangeProhibition(nbe, e->myChangeForward);
     817        37331 :             applyLaneUse(nbe, e, true);
     818        37331 :             applyTurnSigns(nbe, e->myTurnSignsForward);
     819              :             nbe->setTurnSignTarget(last->getID());
     820        37331 :             if (addBikeLane && (cyclewayType == WAY_UNKNOWN || (cyclewayType & WAY_FORWARD) != 0)) {
     821          427 :                 nbe->addBikeLane(bikeLaneWidth * offsetFactor);
     822        36904 :             } else if (nbe->getPermissions(0) == SVC_BUS) {
     823              :                 // bikes drive on buslanes if no separate cycle lane is available
     824           69 :                 nbe->setPermissions(SVC_BUS | SVC_BICYCLE, 0);
     825              :             }
     826        37331 :             if ((addSidewalk && (sidewalkType == WAY_UNKNOWN || (sidewalkType & WAY_FORWARD) != 0))
     827        36465 :                     || (myImportSidewalks && (sidewalkType & WAY_FORWARD) != 0 && defaultPermissions != SVC_PEDESTRIAN)) {
     828         2021 :                 nbe->addSidewalk(sidewalkWidth * offsetFactor);
     829              :             }
     830        37331 :             if (!addBackward && (e->myExtraAllowed & SVC_PEDESTRIAN) != 0 && (nbe->getPermissions(0) & SVC_PEDESTRIAN) == 0) {
     831              :                 // Pedestrians are explicitly allowed (maybe through foot="yes") but did not get a sidewalk (maybe through sidewalk="no").
     832              :                 // Since we do not have a backward edge, we need to make sure they can at least walk somewhere, see #14124
     833            3 :                 nbe->setPermissions(nbe->getPermissions(0) | SVC_PEDESTRIAN, 0);
     834              :             }
     835        37331 :             nbe->updateParameters(e->getParametersMap());
     836              :             nbe->setDistance(distanceStart);
     837        37331 :             if (e->myAmInRoundabout) {
     838              :                 // ensure roundabout edges have the precedence
     839           59 :                 nbe->setJunctionPriority(to, NBEdge::JunctionPriority::ROUNDABOUT);
     840           59 :                 nbe->setJunctionPriority(from, NBEdge::JunctionPriority::ROUNDABOUT);
     841              :             }
     842              : 
     843              :             // process forward lanes width
     844        37331 :             const int numForwardLanesFromWidthKey = (int)e->myWidthLanesForward.size();
     845        37341 :             if (numForwardLanesFromWidthKey > 0 && !OptionsCont::getOptions().getBool("ignore-widths")) {
     846           10 :                 if ((int)nbe->getLanes().size() != numForwardLanesFromWidthKey) {
     847            0 :                     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."),
     848              :                                    id, nbe->getLanes().size(), numForwardLanesFromWidthKey);
     849              :                 } else {
     850           32 :                     for (int i = 0; i < numForwardLanesFromWidthKey; i++) {
     851           22 :                         const double actualWidth = e->myWidthLanesForward[i] <= 0 ? forwardWidth : e->myWidthLanesForward[i];
     852           22 :                         const int laneIndex = lefthand ? i : numForwardLanesFromWidthKey - i - 1;
     853           22 :                         nbe->setLaneWidth(laneIndex, actualWidth);
     854              :                     }
     855              :                 }
     856              :             }
     857              : 
     858        37331 :             if (!ec.insert(nbe)) {
     859            0 :                 delete nbe;
     860            0 :                 throw ProcessError(TLF("Could not add edge '%'.", id));
     861              :             }
     862              :         }
     863        37340 :         if (addBackward) {
     864              :             assert(numLanesBackward > 0);
     865              :             NBEdge* nbe = new NBEdge(reverseID, to, from, type, speedBackward, NBEdge::UNSPECIFIED_FRICTION, numLanesBackward, tc.getEdgeTypePriority(type),
     866        23068 :                                      backwardWidth, NBEdge::UNSPECIFIED_OFFSET, shape.reverse(), lsf,
     867        46136 :                                      StringUtils::escapeXML(streetName), origID, true);
     868        11534 :             if (markOSMDirection) {
     869          974 :                 nbe->setParameter(NBTrafficLightDefinition::OSM_DIRECTION, "backward");
     870              :             }
     871        11534 :             nbe->setPermissions(backwardPermissions);
     872        11534 :             if ((e->myBuswayType & WAY_BACKWARD) != 0) {
     873           69 :                 nbe->setPermissions(SVC_BUS, 0);
     874              :             }
     875        11534 :             applyChangeProhibition(nbe, e->myChangeBackward);
     876        11534 :             applyLaneUse(nbe, e, false);
     877        11534 :             applyTurnSigns(nbe, e->myTurnSignsBackward);
     878              :             nbe->setTurnSignTarget(first->getID());
     879        11534 :             if (addBikeLane && (cyclewayType == WAY_UNKNOWN || (cyclewayType & WAY_BACKWARD) != 0)) {
     880          157 :                 nbe->addBikeLane(bikeLaneWidth * offsetFactor);
     881        11377 :             } else if (nbe->getPermissions(0) == SVC_BUS) {
     882              :                 // bikes drive on buslanes if no separate cycle lane is available
     883           63 :                 nbe->setPermissions(SVC_BUS | SVC_BICYCLE, 0);
     884              :             }
     885        11534 :             if ((addSidewalk && (sidewalkType == WAY_UNKNOWN || (sidewalkType & WAY_BACKWARD) != 0))
     886        11033 :                     || (myImportSidewalks && (sidewalkType & WAY_BACKWARD) != 0 && defaultPermissions != SVC_PEDESTRIAN)) {
     887         1095 :                 nbe->addSidewalk(sidewalkWidth * offsetFactor);
     888              :             }
     889        11534 :             nbe->updateParameters(e->getParametersMap());
     890              :             nbe->setDistance(distanceEnd);
     891        11534 :             if (e->myAmInRoundabout) {
     892              :                 // ensure roundabout edges have the precedence
     893            0 :                 nbe->setJunctionPriority(from, NBEdge::JunctionPriority::ROUNDABOUT);
     894            0 :                 nbe->setJunctionPriority(to, NBEdge::JunctionPriority::ROUNDABOUT);
     895              :             }
     896              :             // process backward lanes width
     897        11534 :             const int numBackwardLanesFromWidthKey = (int)e->myWidthLanesBackward.size();
     898        11536 :             if (numBackwardLanesFromWidthKey > 0 && !OptionsCont::getOptions().getBool("ignore-widths")) {
     899            2 :                 if ((int)nbe->getLanes().size() != numBackwardLanesFromWidthKey) {
     900            0 :                     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."),
     901              :                                    id, nbe->getLanes().size(), numBackwardLanesFromWidthKey);
     902              :                 } else {
     903            8 :                     for (int i = 0; i < numBackwardLanesFromWidthKey; i++) {
     904            6 :                         const double actualWidth = e->myWidthLanesBackward[i] <= 0 ? backwardWidth : e->myWidthLanesBackward[i];
     905            6 :                         const int laneIndex = lefthand ? i : numBackwardLanesFromWidthKey - i - 1;
     906            6 :                         nbe->setLaneWidth(laneIndex, actualWidth);
     907              :                     }
     908              :                 }
     909              :             }
     910              : 
     911        11534 :             if (!ec.insert(nbe)) {
     912            0 :                 delete nbe;
     913            0 :                 throw ProcessError(TLF("Could not add edge '-%'.", id));
     914              :             }
     915              :         }
     916        38155 :         if ((e->myParkingType & PARKING_BOTH) != 0 && OptionsCont::getOptions().isSet("parking-output")) {
     917          216 :             if ((e->myParkingType & PARKING_RIGHT) != 0) {
     918          216 :                 if (addForward) {
     919          648 :                     nb.getParkingCont().push_back(NBParking(id, id));
     920              :                 } else {
     921              :                     /// XXX parking area should be added on the left side of a reverse one-way street
     922            0 :                     if ((e->myParkingType & PARKING_LEFT) == 0 && !addBackward) {
     923              :                         /// put it on the wrong side (better than nothing)
     924            0 :                         nb.getParkingCont().push_back(NBParking(reverseID, reverseID));
     925              :                     }
     926              :                 }
     927              :             }
     928          216 :             if ((e->myParkingType & PARKING_LEFT) != 0) {
     929           78 :                 if (addBackward) {
     930          234 :                     nb.getParkingCont().push_back(NBParking(reverseID, reverseID));
     931              :                 } else {
     932              :                     /// XXX parking area should be added on the left side of an one-way street
     933            0 :                     if ((e->myParkingType & PARKING_RIGHT) == 0 && !addForward) {
     934              :                         /// put it on the wrong side (better than nothing)
     935            0 :                         nb.getParkingCont().push_back(NBParking(id, id));
     936              :                     }
     937              :                 }
     938              :             }
     939              :         }
     940              :     }
     941              :     return newIndex;
     942        37340 : }
     943              : 
     944              : 
     945              : void
     946            0 : NIImporter_OpenStreetMap::reconstructLayerElevation(const double layerElevation, NBNetBuilder& nb) {
     947              :     NBNodeCont& nc = nb.getNodeCont();
     948              :     NBEdgeCont& ec = nb.getEdgeCont();
     949              :     // reconstruct elevation from layer info
     950              :     // build a map of raising and lowering forces (attractor and distance)
     951              :     // for all nodes unknownElevation
     952              :     std::map<NBNode*, std::vector<std::pair<double, double> > > layerForces;
     953              : 
     954              :     // collect all nodes that belong to a way with layer information
     955              :     std::set<NBNode*> knownElevation;
     956            0 :     for (auto& myEdge : myEdges) {
     957            0 :         Edge* e = myEdge.second;
     958            0 :         if (e->myLayer != 0) {
     959            0 :             for (auto j = e->myCurrentNodes.begin(); j != e->myCurrentNodes.end(); ++j) {
     960            0 :                 NBNode* node = nc.retrieve(toString(*j));
     961            0 :                 if (node != nullptr) {
     962              :                     knownElevation.insert(node);
     963            0 :                     layerForces[node].emplace_back(e->myLayer * layerElevation, POSITION_EPS);
     964              :                 }
     965              :             }
     966              :         }
     967              :     }
     968              : #ifdef DEBUG_LAYER_ELEVATION
     969              :     std::cout << "known elevations:\n";
     970              :     for (std::set<NBNode*>::iterator it = knownElevation.begin(); it != knownElevation.end(); ++it) {
     971              :         const std::vector<std::pair<double, double> >& primaryLayers = layerForces[*it];
     972              :         std::cout << "  node=" << (*it)->getID() << " ele=";
     973              :         for (std::vector<std::pair<double, double> >::const_iterator it_ele = primaryLayers.begin(); it_ele != primaryLayers.end(); ++it_ele) {
     974              :             std::cout << it_ele->first << " ";
     975              :         }
     976              :         std::cout << "\n";
     977              :     }
     978              : #endif
     979              :     // layer data only provides a lower bound on elevation since it is used to
     980              :     // resolve the relation among overlapping ways.
     981              :     // Perform a sanity check for steep inclines and raise the knownElevation if necessary
     982              :     std::map<NBNode*, double> knownEleMax;
     983            0 :     for (auto it : knownElevation) {
     984              :         double eleMax = -std::numeric_limits<double>::max();
     985            0 :         const std::vector<std::pair<double, double> >& primaryLayers = layerForces[it];
     986            0 :         for (const auto& primaryLayer : primaryLayers) {
     987            0 :             eleMax = MAX2(eleMax, primaryLayer.first);
     988              :         }
     989            0 :         knownEleMax[it] = eleMax;
     990              :     }
     991            0 :     const double gradeThreshold = OptionsCont::getOptions().getFloat("osm.layer-elevation.max-grade") / 100;
     992              :     bool changed = true;
     993            0 :     while (changed) {
     994              :         changed = false;
     995            0 :         for (auto it = knownElevation.begin(); it != knownElevation.end(); ++it) {
     996              :             std::map<NBNode*, std::pair<double, double> > neighbors = getNeighboringNodes(*it,
     997            0 :                     knownEleMax[*it]
     998            0 :                     / gradeThreshold * 3,
     999            0 :                     knownElevation);
    1000            0 :             for (auto& neighbor : neighbors) {
    1001              :                 if (knownElevation.count(neighbor.first) != 0) {
    1002            0 :                     const double grade = fabs(knownEleMax[*it] - knownEleMax[neighbor.first])
    1003            0 :                                          / MAX2(POSITION_EPS, neighbor.second.first);
    1004              : #ifdef DEBUG_LAYER_ELEVATION
    1005              :                     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";
    1006              : #endif
    1007            0 :                     if (grade > gradeThreshold * 50 / 3.6 / neighbor.second.second) {
    1008              :                         // raise the lower node to the higher level
    1009            0 :                         const double eleMax = MAX2(knownEleMax[*it], knownEleMax[neighbor.first]);
    1010            0 :                         if (knownEleMax[*it] < eleMax) {
    1011            0 :                             knownEleMax[*it] = eleMax;
    1012              :                         } else {
    1013            0 :                             knownEleMax[neighbor.first] = eleMax;
    1014              :                         }
    1015              :                         changed = true;
    1016              :                     }
    1017              :                 }
    1018              :             }
    1019              :         }
    1020              :     }
    1021              : 
    1022              :     // collect all nodes within a grade-dependent range around knownElevation-nodes and apply knowElevation forces
    1023              :     std::set<NBNode*> unknownElevation;
    1024            0 :     for (auto it = knownElevation.begin(); it != knownElevation.end(); ++it) {
    1025            0 :         const double eleMax = knownEleMax[*it];
    1026            0 :         const double maxDist = fabs(eleMax) * 100 / layerElevation;
    1027            0 :         std::map<NBNode*, std::pair<double, double> > neighbors = getNeighboringNodes(*it, maxDist, knownElevation);
    1028            0 :         for (auto& neighbor : neighbors) {
    1029              :             if (knownElevation.count(neighbor.first) == 0) {
    1030            0 :                 unknownElevation.insert(neighbor.first);
    1031            0 :                 layerForces[neighbor.first].emplace_back(eleMax, neighbor.second.first);
    1032              :             }
    1033              :         }
    1034              :     }
    1035              : 
    1036              :     // apply forces to ground-level nodes (neither in knownElevation nor unknownElevation)
    1037            0 :     for (auto it = unknownElevation.begin(); it != unknownElevation.end(); ++it) {
    1038              :         double eleMax = -std::numeric_limits<double>::max();
    1039            0 :         const std::vector<std::pair<double, double> >& primaryLayers = layerForces[*it];
    1040            0 :         for (const auto& primaryLayer : primaryLayers) {
    1041            0 :             eleMax = MAX2(eleMax, primaryLayer.first);
    1042              :         }
    1043            0 :         const double maxDist = fabs(eleMax) * 100 / layerElevation;
    1044            0 :         std::map<NBNode*, std::pair<double, double> > neighbors = getNeighboringNodes(*it, maxDist, knownElevation);
    1045            0 :         for (auto& neighbor : neighbors) {
    1046              :             if (knownElevation.count(neighbor.first) == 0 && unknownElevation.count(neighbor.first) == 0) {
    1047            0 :                 layerForces[*it].emplace_back(0, neighbor.second.first);
    1048              :             }
    1049              :         }
    1050              :     }
    1051              :     // compute the elevation for each node as the weighted average of all forces
    1052              : #ifdef DEBUG_LAYER_ELEVATION
    1053              :     std::cout << "summation of forces\n";
    1054              : #endif
    1055              :     std::map<NBNode*, double> nodeElevation;
    1056            0 :     for (auto& layerForce : layerForces) {
    1057              :         const std::vector<std::pair<double, double> >& forces = layerForce.second;
    1058              :         if (knownElevation.count(layerForce.first) != 0) {
    1059              :             // use the maximum value
    1060              :             /*
    1061              :             double eleMax = -std::numeric_limits<double>::max();
    1062              :             for (std::vector<std::pair<double, double> >::const_iterator it_force = forces.begin(); it_force != forces.end(); ++it_force) {
    1063              :                 eleMax = MAX2(eleMax, it_force->first);
    1064              :             }
    1065              :             */
    1066              : #ifdef DEBUG_LAYER_ELEVATION
    1067              :             std::cout << "   node=" << it->first->getID() << " knownElevation=" << knownEleMax[it->first] << "\n";
    1068              : #endif
    1069            0 :             nodeElevation[layerForce.first] = knownEleMax[layerForce.first];
    1070            0 :         } else if (forces.size() == 1) {
    1071            0 :             nodeElevation[layerForce.first] = forces.front().first;
    1072              :         } else {
    1073              :             // use the weighted sum
    1074              :             double distSum = 0;
    1075            0 :             for (const auto& force : forces) {
    1076            0 :                 distSum += force.second;
    1077              :             }
    1078              :             double weightSum = 0;
    1079              :             double elevation = 0;
    1080              : #ifdef DEBUG_LAYER_ELEVATION
    1081              :             std::cout << "   node=" << it->first->getID() << "  distSum=" << distSum << "\n";
    1082              : #endif
    1083            0 :             for (const auto& force : forces) {
    1084            0 :                 const double weight = (distSum - force.second) / distSum;
    1085            0 :                 weightSum += weight;
    1086            0 :                 elevation += force.first * weight;
    1087              : 
    1088              : #ifdef DEBUG_LAYER_ELEVATION
    1089              :                 std::cout << "       force=" << it_force->first << " dist=" << it_force->second << "  weight=" << weight << " ele=" << elevation << "\n";
    1090              : #endif
    1091              :             }
    1092            0 :             nodeElevation[layerForce.first] = elevation / weightSum;
    1093              :         }
    1094              :     }
    1095              : #ifdef DEBUG_LAYER_ELEVATION
    1096              :     std::cout << "final elevations:\n";
    1097              :     for (std::map<NBNode*, double>::iterator it = nodeElevation.begin(); it != nodeElevation.end(); ++it) {
    1098              :         std::cout << "  node=" << (it->first)->getID() << " ele=" << it->second << "\n";
    1099              :     }
    1100              : #endif
    1101              :     // apply node elevations
    1102            0 :     for (auto& it : nodeElevation) {
    1103            0 :         NBNode* n = it.first;
    1104            0 :         n->reinit(n->getPosition() + Position(0, 0, it.second), n->getType());
    1105              :     }
    1106              : 
    1107              :     // apply way elevation to all edges that had layer information
    1108            0 :     for (const auto& it : ec) {
    1109            0 :         NBEdge* edge = it.second;
    1110              :         const PositionVector& geom = edge->getGeometry();
    1111            0 :         const double length = geom.length2D();
    1112            0 :         const double zFrom = nodeElevation[edge->getFromNode()];
    1113            0 :         const double zTo = nodeElevation[edge->getToNode()];
    1114              :         // XXX if the from- or to-node was part of multiple ways with
    1115              :         // different layers, reconstruct the layer value from origID
    1116              :         double dist = 0;
    1117            0 :         PositionVector newGeom;
    1118            0 :         for (auto it_pos = geom.begin(); it_pos != geom.end(); ++it_pos) {
    1119            0 :             if (it_pos != geom.begin()) {
    1120            0 :                 dist += (*it_pos).distanceTo2D(*(it_pos - 1));
    1121              :             }
    1122            0 :             newGeom.push_back((*it_pos) + Position(0, 0, zFrom + (zTo - zFrom) * dist / length));
    1123              :         }
    1124            0 :         edge->setGeometry(newGeom);
    1125            0 :     }
    1126            0 : }
    1127              : 
    1128              : std::map<NBNode*, std::pair<double, double> >
    1129            0 : NIImporter_OpenStreetMap::getNeighboringNodes(NBNode* node, double maxDist, const std::set<NBNode*>& knownElevation) {
    1130              :     std::map<NBNode*, std::pair<double, double> > result;
    1131              :     std::set<NBNode*> visited;
    1132              :     std::vector<NBNode*> open;
    1133            0 :     open.push_back(node);
    1134            0 :     result[node] = std::make_pair(0, 0);
    1135            0 :     while (!open.empty()) {
    1136            0 :         NBNode* n = open.back();
    1137              :         open.pop_back();
    1138            0 :         if (visited.count(n) != 0) {
    1139            0 :             continue;
    1140              :         }
    1141              :         visited.insert(n);
    1142            0 :         const EdgeVector& edges = n->getEdges();
    1143            0 :         for (auto e : edges) {
    1144            0 :             NBNode* s = nullptr;
    1145            0 :             if (n->hasIncoming(e)) {
    1146            0 :                 s = e->getFromNode();
    1147              :             } else {
    1148            0 :                 s = e->getToNode();
    1149              :             }
    1150            0 :             const double dist = result[n].first + e->getGeometry().length2D();
    1151            0 :             const double speed = MAX2(e->getSpeed(), result[n].second);
    1152              :             if (result.count(s) == 0) {
    1153            0 :                 result[s] = std::make_pair(dist, speed);
    1154              :             } else {
    1155            0 :                 result[s] = std::make_pair(MIN2(dist, result[s].first), MAX2(speed, result[s].second));
    1156              :             }
    1157            0 :             if (dist < maxDist && knownElevation.count(s) == 0) {
    1158            0 :                 open.push_back(s);
    1159              :             }
    1160              :         }
    1161              :     }
    1162              :     result.erase(node);
    1163            0 :     return result;
    1164            0 : }
    1165              : 
    1166              : 
    1167              : std::string
    1168        58663 : NIImporter_OpenStreetMap::usableType(const std::string& type, const std::string& id, NBTypeCont& tc) {
    1169        58663 :     if (tc.knows(type)) {
    1170              :         return type;
    1171              :     }
    1172              :     if (myUnusableTypes.count(type) > 0) {
    1173         1464 :         return "";
    1174              :     }
    1175              :     if (myKnownCompoundTypes.count(type) > 0) {
    1176        10599 :         return myKnownCompoundTypes[type];
    1177              :     }
    1178              :     // this edge has a type which does not yet exist in the TypeContainer
    1179         1386 :     StringTokenizer tok = StringTokenizer(type, compoundTypeSeparator);
    1180              :     std::vector<std::string> types;
    1181         2001 :     while (tok.hasNext()) {
    1182         1308 :         std::string t = tok.next();
    1183         1308 :         if (tc.knows(t)) {
    1184          577 :             if (std::find(types.begin(), types.end(), t) == types.end()) {
    1185          574 :                 types.push_back(t);
    1186              :             }
    1187          731 :         } else if (tok.size() > 1) {
    1188         1176 :             if (!StringUtils::startsWith(t, "service.")) {
    1189         1137 :                 WRITE_WARNINGF(TL("Discarding unknown compound '%' in type '%' (first occurrence for edge '%')."), t, type, id);
    1190              :             }
    1191              :         }
    1192              :     }
    1193          693 :     if (types.empty()) {
    1194          330 :         if (!StringUtils::startsWith(type, "service.")) {
    1195          474 :             WRITE_WARNINGF(TL("Discarding unusable type '%' (first occurrence for edge '%')."), type, id);
    1196              :         }
    1197              :         myUnusableTypes.insert(type);
    1198          165 :         return "";
    1199              :     }
    1200          528 :     const std::string newType = joinToString(types, "|");
    1201          528 :     if (tc.knows(newType)) {
    1202          484 :         myKnownCompoundTypes[type] = newType;
    1203              :         return newType;
    1204              :     } else if (myKnownCompoundTypes.count(newType) > 0) {
    1205            0 :         return myKnownCompoundTypes[newType];
    1206              :     } else {
    1207              :         // build a new type by merging all values
    1208              :         int numLanes = 0;
    1209              :         double maxSpeed = 0;
    1210              :         int prio = 0;
    1211           44 :         double width = NBEdge::UNSPECIFIED_WIDTH;
    1212              :         double sidewalkWidth = NBEdge::UNSPECIFIED_WIDTH;
    1213              :         double bikelaneWidth = NBEdge::UNSPECIFIED_WIDTH;
    1214              :         bool defaultIsOneWay = true;
    1215              :         SVCPermissions permissions = 0;
    1216              :         LaneSpreadFunction spreadType = LaneSpreadFunction::RIGHT;
    1217              :         bool discard = true;
    1218              :         bool hadDiscard = false;
    1219          134 :         for (auto& type2 : types) {
    1220           90 :             if (!tc.getEdgeTypeShallBeDiscarded(type2)) {
    1221           85 :                 numLanes = MAX2(numLanes, tc.getEdgeTypeNumLanes(type2));
    1222           85 :                 maxSpeed = MAX2(maxSpeed, tc.getEdgeTypeSpeed(type2));
    1223           85 :                 prio = MAX2(prio, tc.getEdgeTypePriority(type2));
    1224           85 :                 defaultIsOneWay &= tc.getEdgeTypeIsOneWay(type2);
    1225              :                 //std::cout << "merging component " << type2 << " into type " << newType << " allows=" << getVehicleClassNames(tc.getPermissions(type2)) << " oneway=" << defaultIsOneWay << "\n";
    1226           85 :                 permissions |= tc.getEdgeTypePermissions(type2);
    1227           85 :                 spreadType = tc.getEdgeTypeSpreadType(type2);
    1228           85 :                 width = MAX2(width, tc.getEdgeTypeWidth(type2));
    1229           85 :                 sidewalkWidth = MAX2(sidewalkWidth, tc.getEdgeTypeSidewalkWidth(type2));
    1230           85 :                 bikelaneWidth = MAX2(bikelaneWidth, tc.getEdgeTypeBikeLaneWidth(type2));
    1231              :                 discard = false;
    1232              :             } else {
    1233              :                 hadDiscard = true;
    1234              :             }
    1235              :         }
    1236           44 :         if (hadDiscard && permissions == 0) {
    1237              :             discard = true;
    1238              :         }
    1239           41 :         if (discard) {
    1240            9 :             WRITE_WARNINGF(TL("Discarding compound type '%' (first occurrence for edge '%')."), newType, id);
    1241              :             myUnusableTypes.insert(newType);
    1242            3 :             return "";
    1243              :         }
    1244           41 :         if (width != NBEdge::UNSPECIFIED_WIDTH) {
    1245              :             width = MAX2(width, SUMO_const_laneWidth);
    1246              :         }
    1247              :         // ensure pedestrians don't run into trains
    1248           41 :         if (sidewalkWidth == NBEdge::UNSPECIFIED_WIDTH
    1249           29 :                 && (permissions & SVC_PEDESTRIAN) != 0
    1250           23 :                 && (permissions & SVC_RAIL_CLASSES) != 0) {
    1251              :             //std::cout << "patching sidewalk for type '" << newType << "' which allows=" << getVehicleClassNames(permissions) << "\n";
    1252           40 :             sidewalkWidth = OptionsCont::getOptions().getFloat("default.sidewalk-width");
    1253              :         }
    1254              : 
    1255          123 :         WRITE_MESSAGEF(TL("Adding new type '%' (first occurrence for edge '%')."), type, id);
    1256           41 :         tc.insertEdgeType(newType, numLanes, maxSpeed, prio, permissions, spreadType, width,
    1257              :                           defaultIsOneWay, sidewalkWidth, bikelaneWidth, 0, 0, 0);
    1258          125 :         for (auto& type3 : types) {
    1259           84 :             if (!tc.getEdgeTypeShallBeDiscarded(type3)) {
    1260           84 :                 tc.copyEdgeTypeRestrictionsAndAttrs(type3, newType);
    1261              :             }
    1262              :         }
    1263           41 :         myKnownCompoundTypes[type] = newType;
    1264              :         return newType;
    1265              :     }
    1266          693 : }
    1267              : 
    1268              : void
    1269        20261 : NIImporter_OpenStreetMap::extendRailwayDistances(Edge* e, NBTypeCont& tc) {
    1270        20261 :     const std::string id = toString(e->id);
    1271        20261 :     std::string type = usableType(e->myHighWayType, id, tc);
    1272        20261 :     if (type != "" && isRailway(tc.getEdgeTypePermissions(type))) {
    1273              :         std::vector<NIOSMNode*> nodes;
    1274              :         std::vector<double> usablePositions;
    1275              :         std::vector<int> usableIndex;
    1276        28936 :         for (long long int n : e->myCurrentNodes) {
    1277        26122 :             NIOSMNode* node = myOSMNodes[n];
    1278        26122 :             node->positionMeters = interpretDistance(node);
    1279        26122 :             if (node->positionMeters != std::numeric_limits<double>::max()) {
    1280          343 :                 usablePositions.push_back(node->positionMeters);
    1281          343 :                 usableIndex.push_back((int)nodes.size());
    1282              :             }
    1283        26122 :             nodes.push_back(node);
    1284              :         }
    1285         2814 :         if (usablePositions.size() == 0) {
    1286              :             return;
    1287              :         } else {
    1288              :             bool forward = true;
    1289          233 :             if (usablePositions.size() == 1) {
    1290          525 :                 WRITE_WARNINGF(TL("Ambiguous railway kilometrage direction for way '%' (assuming forward)"), id);
    1291              :             } else {
    1292           58 :                 forward = usablePositions.front() < usablePositions.back();
    1293              :             }
    1294              :             // check for consistency
    1295          343 :             for (int i = 1; i < (int)usablePositions.size(); i++) {
    1296          110 :                 if ((usablePositions[i - 1] < usablePositions[i]) != forward) {
    1297            0 :                     WRITE_WARNINGF(TL("Inconsistent railway kilometrage direction for way '%': % (skipping)"), id, toString(usablePositions));
    1298            0 :                     return;
    1299              :                 }
    1300              :             }
    1301          233 :             if (nodes.size() > usablePositions.size()) {
    1302              :                 // complete missing values
    1303          233 :                 PositionVector shape;
    1304         3240 :                 for (NIOSMNode* node : nodes) {
    1305         3007 :                     shape.push_back(Position(node->lon, node->lat, 0));
    1306              :                 }
    1307          233 :                 if (!NBNetBuilder::transformCoordinates(shape)) {
    1308              :                     return; // error will be given later
    1309              :                 }
    1310          233 :                 double sign = forward ? 1 : -1;
    1311              :                 // extend backward before first usable value
    1312         1485 :                 for (int i = usableIndex.front() - 1; i >= 0; i--) {
    1313         1252 :                     nodes[i]->positionMeters = nodes[i + 1]->positionMeters - sign * shape[i].distanceTo2D(shape[i + 1]);
    1314              :                 }
    1315              :                 // extend forward
    1316         1755 :                 for (int i = usableIndex.front() + 1; i < (int)nodes.size(); i++) {
    1317         1522 :                     if (nodes[i]->positionMeters == std::numeric_limits<double>::max()) {
    1318         1412 :                         nodes[i]->positionMeters = nodes[i - 1]->positionMeters + sign * shape[i].distanceTo2D(shape[i - 1]);
    1319              :                     }
    1320              :                 }
    1321              :                 //std::cout << " way=" << id << " usable=" << toString(usablePositions) << "\n indices=" << toString(usableIndex)
    1322              :                 //    << " final:\n";
    1323              :                 //for (auto n : nodes) {
    1324              :                 //    std::cout << "    " << n->id << " " << n->positionMeters << " " << n->position<< "\n";
    1325              :                 //}
    1326          233 :             }
    1327              :         }
    1328         2814 :     }
    1329              : }
    1330              : 
    1331              : 
    1332              : double
    1333        26122 : NIImporter_OpenStreetMap::interpretDistance(NIOSMNode* node) {
    1334        26122 :     if (node->position.size() > 0) {
    1335              :         try {
    1336          690 :             if (StringUtils::startsWith(node->position, "mi:")) {
    1337            0 :                 return StringUtils::toDouble(node->position.substr(3)) * 1609.344; // meters per mile
    1338              :             } else {
    1339          345 :                 return StringUtils::toDouble(node->position) * 1000;
    1340              :             }
    1341            2 :         } catch (...) {
    1342            6 :             WRITE_WARNINGF(TL("Value of railway:position is not numeric ('%') in node '%'."), node->position, toString(node->id));
    1343            2 :         }
    1344              :     }
    1345              :     return std::numeric_limits<double>::max();
    1346              : }
    1347              : 
    1348              : SUMOVehicleClass
    1349         7901 : NIImporter_OpenStreetMap::interpretTransportType(const std::string& type, NIOSMNode* toSet) {
    1350              :     SUMOVehicleClass result = SVC_IGNORING;
    1351         7901 :     if (type == "train") {
    1352              :         result = SVC_RAIL;
    1353         7420 :     } else if (type == "subway") {
    1354              :         result = SVC_SUBWAY;
    1355         7200 :     } else if (type == "aerialway") {
    1356              :         result = SVC_CABLE_CAR;
    1357         7198 :     } else if (type == "light_rail" || type == "monorail") {
    1358              :         result = SVC_RAIL_URBAN;
    1359         6831 :     } else if (type == "share_taxi") {
    1360              :         result = SVC_TAXI;
    1361         6829 :     } else if (type == "minibus") {
    1362              :         result = SVC_BUS;
    1363         6827 :     } else if (type == "trolleybus") {
    1364              :         result = SVC_BUS;
    1365              :     } else if (SumoVehicleClassStrings.hasString(type)) {
    1366         2509 :         result = SumoVehicleClassStrings.get(type);
    1367              :     }
    1368         7901 :     std::string stop = "";
    1369         7901 :     if (result == SVC_TRAM) {
    1370              :         stop = ".tram";
    1371         7248 :     } else if (result == SVC_BUS) {
    1372              :         stop = ".bus";
    1373         5380 :     } else if (isRailway(result)) {
    1374              :         stop = ".train";
    1375              :     }
    1376         7901 :     if (toSet != nullptr && result != SVC_IGNORING) {
    1377         2251 :         toSet->permissions |= result;
    1378         2251 :         toSet->ptStopLength = OptionsCont::getOptions().getFloat("osm.stop-output.length" + stop);
    1379              :     }
    1380         7901 :     return result;
    1381              : }
    1382              : 
    1383              : 
    1384              : void
    1385        48865 : NIImporter_OpenStreetMap::applyChangeProhibition(NBEdge* e, int changeProhibition) {
    1386              :     bool multiLane = changeProhibition > 3;
    1387              :     //std::cout << "applyChangeProhibition e=" << e->getID() << " changeProhibition=" << std::bitset<32>(changeProhibition) << " val=" << changeProhibition << "\n";
    1388        49146 :     for (int lane = 0; changeProhibition > 0 && lane < e->getNumLanes(); lane++) {
    1389          281 :         int code = changeProhibition % 4; // only look at the last 2 bits
    1390          281 :         SVCPermissions changeLeft = (code & CHANGE_NO_LEFT) == 0 ? SVCAll : (SVCPermissions)SVC_AUTHORITY;
    1391          281 :         SVCPermissions changeRight = (code & CHANGE_NO_RIGHT) == 0 ? SVCAll : (SVCPermissions)SVC_AUTHORITY;
    1392          281 :         e->setPermittedChanging(lane, changeLeft, changeRight);
    1393          281 :         if (multiLane) {
    1394          208 :             changeProhibition = changeProhibition >> 2;
    1395              :         }
    1396              :     }
    1397        48865 : }
    1398              : 
    1399              : 
    1400              : void
    1401        48865 : NIImporter_OpenStreetMap::applyLaneUse(NBEdge* e, NIImporter_OpenStreetMap::Edge* nie, const bool forward) {
    1402        48865 :     if (myImportLaneAccess) {
    1403              :         const int numLanes = e->getNumLanes();
    1404         2455 :         const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
    1405         2455 :         const std::vector<bool>& designated = forward ? nie->myDesignatedLaneForward : nie->myDesignatedLaneBackward;
    1406         2455 :         const std::vector<SVCPermissions>& allowed = forward ? nie->myAllowedLaneForward : nie->myAllowedLaneBackward;
    1407         2455 :         const std::vector<SVCPermissions>& disallowed = forward ? nie->myDisallowedLaneForward : nie->myDisallowedLaneBackward;
    1408         5057 :         for (int lane = 0; lane < numLanes; lane++) {
    1409              :             // laneUse stores from left to right
    1410         2602 :             const int i = lefthand ? lane : numLanes - 1 - lane;
    1411              :             // Extra allowed SVCs for this lane or none if no info was present for the lane
    1412         2602 :             const SVCPermissions extraAllowed = i < (int)allowed.size() ? allowed[i] : (SVCPermissions)SVC_IGNORING;
    1413              :             // Extra disallowed SVCs for this lane or none if no info was present for the lane
    1414         2602 :             const SVCPermissions extraDisallowed = i < (int)disallowed.size() ? disallowed[i] : (SVCPermissions)SVC_IGNORING;
    1415         2774 :             if (i < (int)designated.size() && designated[i]) {
    1416              :                 // if designated, delete all permissions
    1417           68 :                 e->setPermissions(SVC_IGNORING, lane);
    1418           68 :                 e->preferVehicleClass(lane, extraAllowed);
    1419              :             }
    1420         2602 :             e->setPermissions((e->getPermissions(lane) | extraAllowed) & (~extraDisallowed), lane);
    1421              :         }
    1422              :     }
    1423        48865 : }
    1424              : 
    1425              : void
    1426          941 : NIImporter_OpenStreetMap::mergeTurnSigns(std::vector<int>& signs, std::vector<int> signs2) {
    1427          941 :     if (signs.empty()) {
    1428          937 :         signs.insert(signs.begin(), signs2.begin(), signs2.end());
    1429              :     } else {
    1430           18 :         for (int i = 0; i < (int)MIN2(signs.size(), signs2.size()); i++) {
    1431           14 :             signs[i] |= signs2[i];
    1432              :         }
    1433              :     }
    1434          941 : }
    1435              : 
    1436              : 
    1437              : void
    1438        48865 : NIImporter_OpenStreetMap::applyTurnSigns(NBEdge* e, const std::vector<int>& turnSigns) {
    1439        48865 :     if (myImportTurnSigns && turnSigns.size() > 0) {
    1440              :         // no sidewalks and bike lanes have been added yet
    1441           89 :         if ((int)turnSigns.size() == e->getNumLanes()) {
    1442              :             //std::cout << "apply turnSigns for " << e->getID() << " turnSigns=" << toString(turnSigns) << "\n";
    1443          279 :             for (int i = 0; i < (int)turnSigns.size(); i++) {
    1444              :                 // laneUse stores from left to right
    1445          196 :                 const int laneIndex = e->getNumLanes() - 1 - i;
    1446              :                 NBEdge::Lane& lane = e->getLaneStruct(laneIndex);
    1447          196 :                 lane.turnSigns = turnSigns[i];
    1448              :             }
    1449              :         } else {
    1450           18 :             WRITE_WARNINGF(TL("Ignoring turn sign information for % lanes on edge % with % driving lanes"), turnSigns.size(), e->getID(), e->getNumLanes());
    1451              :         }
    1452              :     }
    1453        48865 : }
    1454              : 
    1455              : 
    1456              : // ---------------------------------------------------------------------------
    1457              : // definitions of NIImporter_OpenStreetMap::NodesHandler-methods
    1458              : // ---------------------------------------------------------------------------
    1459          185 : NIImporter_OpenStreetMap::NodesHandler::NodesHandler(std::map<long long int, NIOSMNode*>& toFill,
    1460          185 :         std::set<NIOSMNode*, CompareNodes>& uniqueNodes, const OptionsCont& oc) :
    1461              :     SUMOSAXHandler("osm - file"),
    1462          185 :     myToFill(toFill),
    1463          185 :     myCurrentNode(nullptr),
    1464          185 :     myIsStation(false),
    1465          185 :     myHierarchyLevel(0),
    1466          185 :     myUniqueNodes(uniqueNodes),
    1467          185 :     myImportElevation(oc.getBool("osm.elevation")),
    1468          185 :     myDuplicateNodes(0),
    1469          370 :     myOptionsCont(oc) {
    1470              :     // init rail signal rules
    1471          557 :     for (std::string kv : oc.getStringVector("osm.railsignals")) {
    1472          187 :         if (kv == "DEFAULT") {
    1473          183 :             myRailSignalRules.push_back("railway:signal:main=");
    1474          366 :             myRailSignalRules.push_back("railway:signal:combined=");
    1475            4 :         } else if (kv == "ALL") {
    1476            2 :             myRailSignalRules.push_back("railway=signal");
    1477              :         } else {
    1478            6 :             myRailSignalRules.push_back("railway:signal:" + kv);
    1479              :         }
    1480              :     }
    1481          185 : }
    1482              : 
    1483              : 
    1484          185 : NIImporter_OpenStreetMap::NodesHandler::~NodesHandler() = default;
    1485              : 
    1486              : void
    1487       539552 : NIImporter_OpenStreetMap::NodesHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) {
    1488       539552 :     ++myHierarchyLevel;
    1489       539552 :     if (element == SUMO_TAG_NODE) {
    1490       319999 :         bool ok = true;
    1491       319999 :         myLastNodeID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
    1492       319999 :         if (myHierarchyLevel != 2) {
    1493            0 :             WRITE_ERROR("Node element on wrong XML hierarchy level (id='" + myLastNodeID +
    1494              :                         "', level='" + toString(myHierarchyLevel) + "').");
    1495        14667 :             return;
    1496              :         }
    1497       319999 :         const std::string& action = attrs.getOpt<std::string>(SUMO_ATTR_ACTION, myLastNodeID.c_str(), ok);
    1498       319999 :         if (action == "delete" || !ok) {
    1499              :             return;
    1500              :         }
    1501              :         try {
    1502              :             // we do not use attrs.get here to save some time on parsing
    1503       305335 :             const long long int id = StringUtils::toLong(myLastNodeID);
    1504       305334 :             myCurrentNode = nullptr;
    1505       305334 :             const auto insertionIt = myToFill.lower_bound(id);
    1506       305334 :             if (insertionIt == myToFill.end() || insertionIt->first != id) {
    1507              :                 // assume we are loading multiple files, so we won't report duplicate nodes
    1508       303811 :                 const double tlon = attrs.get<double>(SUMO_ATTR_LON, myLastNodeID.c_str(), ok);
    1509       303811 :                 const double tlat = attrs.get<double>(SUMO_ATTR_LAT, myLastNodeID.c_str(), ok);
    1510       303811 :                 if (!ok) {
    1511              :                     return;
    1512              :                 }
    1513       303809 :                 myCurrentNode = new NIOSMNode(id, tlon, tlat);
    1514       303809 :                 auto similarNode = myUniqueNodes.find(myCurrentNode);
    1515       303809 :                 if (similarNode == myUniqueNodes.end()) {
    1516              :                     myUniqueNodes.insert(myCurrentNode);
    1517              :                 } else {
    1518           28 :                     delete myCurrentNode;
    1519           28 :                     myCurrentNode = *similarNode;
    1520           28 :                     myDuplicateNodes++;
    1521              :                 }
    1522       303809 :                 myToFill.emplace_hint(insertionIt, id, myCurrentNode);
    1523              :             }
    1524            1 :         } catch (FormatException&) {
    1525            1 :             WRITE_ERROR(TL("Attribute 'id' in the definition of a node is not of type long long int."));
    1526              :             return;
    1527            1 :         }
    1528              :     }
    1529       524885 :     if (element == SUMO_TAG_TAG && myCurrentNode != nullptr) {
    1530       211448 :         if (myHierarchyLevel != 3) {
    1531            1 :             WRITE_ERROR(TL("Tag element on wrong XML hierarchy level."));
    1532            1 :             return;
    1533              :         }
    1534       211447 :         bool ok = true;
    1535       211447 :         const std::string& key = attrs.get<std::string>(SUMO_ATTR_K, myLastNodeID.c_str(), ok, false);
    1536              :         // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
    1537       206858 :         if (key == "highway" || key == "ele" || key == "crossing" || key == "railway" || key == "public_transport"
    1538       195367 :                 || key == "name" || key == "train" || key == "bus" || key == "tram" || key == "light_rail" || key == "subway" || key == "station" || key == "noexit"
    1539       183322 :                 || key == "crossing:barrier"
    1540       182972 :                 || key == "crossing:light"
    1541       182833 :                 || key == "railway:ref"
    1542       394211 :                 || StringUtils::startsWith(key, "railway:signal")
    1543       589603 :                 || StringUtils::startsWith(key, "railway:position")
    1544              :            ) {
    1545        40518 :             const std::string& value = attrs.get<std::string>(SUMO_ATTR_V, myLastNodeID.c_str(), ok, false);
    1546        45107 :             if (key == "highway" && value.find("traffic_signal") != std::string::npos) {
    1547         1382 :                 myCurrentNode->tlsControlled = true;
    1548        41712 :             } else if (key == "crossing" && value.find("traffic_signals") != std::string::npos) {
    1549         1676 :                 myCurrentNode->tlsControlled = true;
    1550        40667 :             } else if (key == "highway" && value.find("crossing") != std::string::npos) {
    1551         1928 :                 myCurrentNode->pedestrianCrossing = true;
    1552           35 :             } else if ((key == "noexit" && value == "yes")
    1553        35532 :                        || (key == "railway" && value == "buffer_stop")) {
    1554           96 :                 myCurrentNode->railwayBufferStop = true;
    1555        40542 :             } else if (key == "railway" && value.find("crossing") != std::string::npos) {
    1556         1512 :                 myCurrentNode->railwayCrossing = true;
    1557        33924 :             } else if (key == "crossing:barrier") {
    1558          700 :                 myCurrentNode->setParameter("crossing:barrier", value);
    1559        33574 :             } else if (key == "crossing:light") {
    1560          278 :                 myCurrentNode->setParameter("crossing:light", value);
    1561        33435 :             } else if (key == "railway:signal:direction") {
    1562         1348 :                 if (value == "both") {
    1563           35 :                     myCurrentNode->myRailDirection = WAY_BOTH;
    1564         1313 :                 } else if (value == "backward") {
    1565          402 :                     myCurrentNode->myRailDirection = WAY_BACKWARD;
    1566          911 :                 } else if (value == "forward") {
    1567          911 :                     myCurrentNode->myRailDirection = WAY_FORWARD;
    1568              :                 }
    1569        64174 :             } else if (StringUtils::startsWith(key, "railway:signal") || (key == "railway" && value == "signal")) {
    1570        11513 :                 std::string kv = key + "=" + value;
    1571        11513 :                 std::string kglob = key + "=";
    1572        11513 :                 if ((std::find(myRailSignalRules.begin(), myRailSignalRules.end(), kv) != myRailSignalRules.end())
    1573        11513 :                         || (std::find(myRailSignalRules.begin(), myRailSignalRules.end(), kglob) != myRailSignalRules.end())) {
    1574          883 :                     myCurrentNode->railwaySignal = true;
    1575              :                 }
    1576        41148 :             } else if (StringUtils::startsWith(key, "railway:position") && value.size() > myCurrentNode->position.size()) {
    1577              :                 // use the entry with the highest precision (more digits)
    1578          367 :                 myCurrentNode->position = value;
    1579        20207 :             } else if ((key == "public_transport" && value == "stop_position") ||
    1580        18685 :                        (key == "highway" && value == "bus_stop")) {
    1581         1991 :                 myCurrentNode->ptStopPosition = true;
    1582         1991 :                 if (myCurrentNode->ptStopLength == 0) {
    1583              :                     // default length
    1584          856 :                     myCurrentNode->ptStopLength = myOptionsCont.getFloat("osm.stop-output.length");
    1585              :                 }
    1586        18216 :             } else if (key == "name") {
    1587        10060 :                 myCurrentNode->name = value;
    1588         8156 :             } else if (myImportElevation && key == "ele") {
    1589              :                 try {
    1590         1546 :                     const double elevation = StringUtils::parseDist(value);
    1591         1545 :                     if (std::isnan(elevation)) {
    1592            0 :                         WRITE_WARNINGF(TL("Value of key '%' is invalid ('%') in node '%'."), key, value, myLastNodeID);
    1593              :                     } else {
    1594         1545 :                         myCurrentNode->ele = elevation;
    1595              :                     }
    1596            1 :                 } catch (...) {
    1597            3 :                     WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in node '%'."), key, value, myLastNodeID);
    1598            1 :                 }
    1599         6610 :             } else if (key == "station") {
    1600           84 :                 interpretTransportType(value, myCurrentNode);
    1601           84 :                 myIsStation = true;
    1602         6526 :             } else if (key == "railway:ref") {
    1603           69 :                 myRailwayRef = value;
    1604              :             } else {
    1605              :                 // v="yes"
    1606         6457 :                 interpretTransportType(key, myCurrentNode);
    1607              :             }
    1608              :         }
    1609       214249 :         if (myAllAttributes && (myExtraAttributes.count(key) != 0 || myExtraAttributes.size() == 0)) {
    1610          428 :             const std::string info = "node=" + toString(myCurrentNode->id) + ", k=" + key;
    1611          856 :             myCurrentNode->setParameter(key, attrs.get<std::string>(SUMO_ATTR_V, info.c_str(), ok, false));
    1612              :         }
    1613              :     }
    1614              : }
    1615              : 
    1616              : 
    1617              : void
    1618       539365 : NIImporter_OpenStreetMap::NodesHandler::myEndElement(int element) {
    1619       539365 :     if (element == SUMO_TAG_NODE && myHierarchyLevel == 2) {
    1620       319999 :         if (myIsStation && myRailwayRef != "") {
    1621           44 :             myCurrentNode->setParameter("railway:ref", myRailwayRef);
    1622              :         }
    1623       319999 :         myCurrentNode = nullptr;
    1624       319999 :         myIsStation = false;
    1625       319999 :         myRailwayRef = "";
    1626              :     }
    1627       539365 :     --myHierarchyLevel;
    1628       539365 : }
    1629              : 
    1630              : 
    1631              : // ---------------------------------------------------------------------------
    1632              : // definitions of NIImporter_OpenStreetMap::EdgesHandler-methods
    1633              : // ---------------------------------------------------------------------------
    1634          183 : NIImporter_OpenStreetMap::EdgesHandler::EdgesHandler(
    1635              :     const std::map<long long int, NIOSMNode*>& osmNodes,
    1636              :     std::map<long long int, Edge*>& toFill, std::map<long long int, Edge*>& platformShapes,
    1637          183 :     const NBTypeCont& tc):
    1638              :     SUMOSAXHandler("osm - file"),
    1639          183 :     myOSMNodes(osmNodes),
    1640          183 :     myEdgeMap(toFill),
    1641          183 :     myPlatformShapesMap(platformShapes),
    1642          366 :     myTypeCont(tc) {
    1643              : 
    1644          183 :     const double unlimitedSpeed = OptionsCont::getOptions().getFloat("osm.speedlimit-none");
    1645              : 
    1646          183 :     mySpeedMap["nan"] = MAXSPEED_UNGIVEN;
    1647          183 :     mySpeedMap["sign"] = MAXSPEED_UNGIVEN;
    1648          183 :     mySpeedMap["signals"] = MAXSPEED_UNGIVEN;
    1649          183 :     mySpeedMap["none"] = unlimitedSpeed;
    1650          183 :     mySpeedMap["no"] = unlimitedSpeed;
    1651          183 :     mySpeedMap["walk"] = 5. / 3.6;
    1652              :     // https://wiki.openstreetmap.org/wiki/Key:source:maxspeed#Commonly_used_values
    1653          183 :     mySpeedMap["AT:urban"] = 50. / 3.6;
    1654          183 :     mySpeedMap["AT:rural"] = 100. / 3.6;
    1655          183 :     mySpeedMap["AT:trunk"] = 100. / 3.6;
    1656          183 :     mySpeedMap["AT:motorway"] = 130. / 3.6;
    1657          183 :     mySpeedMap["AU:urban"] = 50. / 3.6;
    1658          183 :     mySpeedMap["BE:urban"] = 50. / 3.6;
    1659          183 :     mySpeedMap["BE:zone"] = 30. / 3.6;
    1660          183 :     mySpeedMap["BE:motorway"] = 120. / 3.6;
    1661          183 :     mySpeedMap["BE:zone30"] = 30. / 3.6;
    1662          183 :     mySpeedMap["BE-VLG:rural"] = 70. / 3.6;
    1663          183 :     mySpeedMap["BE-WAL:rural"] = 90. / 3.6;
    1664          183 :     mySpeedMap["BE:school"] = 30. / 3.6;
    1665          183 :     mySpeedMap["CZ:motorway"] = 130. / 3.6;
    1666          183 :     mySpeedMap["CZ:trunk"] = 110. / 3.6;
    1667          183 :     mySpeedMap["CZ:rural"] = 90. / 3.6;
    1668          183 :     mySpeedMap["CZ:urban_motorway"] = 80. / 3.6;
    1669          183 :     mySpeedMap["CZ:urban_trunk"] = 80. / 3.6;
    1670          183 :     mySpeedMap["CZ:urban"] = 50. / 3.6;
    1671          183 :     mySpeedMap["DE:motorway"] = unlimitedSpeed;
    1672          183 :     mySpeedMap["DE:rural"] = 100. / 3.6;
    1673          183 :     mySpeedMap["DE:urban"] = 50. / 3.6;
    1674          183 :     mySpeedMap["DE:bicycle_road"] = 30. / 3.6;
    1675          183 :     mySpeedMap["DK:motorway"] = 130. / 3.6;
    1676          183 :     mySpeedMap["DK:rural"] = 80. / 3.6;
    1677          183 :     mySpeedMap["DK:urban"] = 50. / 3.6;
    1678          183 :     mySpeedMap["EE:urban"] = 50. / 3.6;
    1679          183 :     mySpeedMap["EE:rural"] = 90. / 3.6;
    1680          183 :     mySpeedMap["ES:urban"] = 50. / 3.6;
    1681          183 :     mySpeedMap["ES:zone30"] = 30. / 3.6;
    1682          183 :     mySpeedMap["FR:motorway"] = 130. / 3.6; // 110 (raining)
    1683          183 :     mySpeedMap["FR:rural"] = 80. / 3.6;
    1684          183 :     mySpeedMap["FR:urban"] = 50. / 3.6;
    1685          183 :     mySpeedMap["FR:zone30"] = 30. / 3.6;
    1686          183 :     mySpeedMap["HU:living_street"] = 20. / 3.6;
    1687          183 :     mySpeedMap["HU:motorway"] = 130. / 3.6;
    1688          183 :     mySpeedMap["HU:rural"] = 90. / 3.6;
    1689          183 :     mySpeedMap["HU:trunk"] = 110. / 3.6;
    1690          183 :     mySpeedMap["HU:urban"] = 50. / 3.6;
    1691          183 :     mySpeedMap["IT:rural"] = 90. / 3.6;
    1692          183 :     mySpeedMap["IT:motorway"] = 130. / 3.6;
    1693          183 :     mySpeedMap["IT:urban"] = 50. / 3.6;
    1694          183 :     mySpeedMap["JP:nsl"] = 60. / 3.6;
    1695          183 :     mySpeedMap["JP:express"] = 100. / 3.6;
    1696          183 :     mySpeedMap["LT:rural"] = 90. / 3.6;
    1697          183 :     mySpeedMap["LT:urban"] = 50. / 3.6;
    1698          183 :     mySpeedMap["NO:rural"] = 80. / 3.6;
    1699          183 :     mySpeedMap["NO:urban"] = 50. / 3.6;
    1700          183 :     mySpeedMap["ON:urban"] = 50. / 3.6;
    1701          183 :     mySpeedMap["ON:rural"] = 80. / 3.6;
    1702          183 :     mySpeedMap["PT:motorway"] = 120. / 3.6;
    1703          183 :     mySpeedMap["PT:rural"] = 90. / 3.6;
    1704          183 :     mySpeedMap["PT:trunk"] = 100. / 3.6;
    1705          183 :     mySpeedMap["PT:urban"] = 50. / 3.6;
    1706          183 :     mySpeedMap["RO:motorway"] = 130. / 3.6;
    1707          183 :     mySpeedMap["RO:rural"] = 90. / 3.6;
    1708          183 :     mySpeedMap["RO:trunk"] = 100. / 3.6;
    1709          183 :     mySpeedMap["RO:urban"] = 50. / 3.6;
    1710          183 :     mySpeedMap["RS:living_street"] = 30. / 3.6;
    1711          183 :     mySpeedMap["RS:motorway"] = 130. / 3.6;
    1712          183 :     mySpeedMap["RS:rural"] = 80. / 3.6;
    1713          183 :     mySpeedMap["RS:trunk"] = 100. / 3.6;
    1714          183 :     mySpeedMap["RS:urban"] = 50. / 3.6;
    1715          183 :     mySpeedMap["RU:living_street"] = 20. / 3.6;
    1716          183 :     mySpeedMap["RU:urban"] = 60. / 3.6;
    1717          183 :     mySpeedMap["RU:rural"] = 90. / 3.6;
    1718          183 :     mySpeedMap["RU:motorway"] = 110. / 3.6;
    1719          183 :     const double seventy = StringUtils::parseSpeed("70mph");
    1720          183 :     const double sixty = StringUtils::parseSpeed("60mph");
    1721          183 :     mySpeedMap["GB:motorway"] = seventy;
    1722          183 :     mySpeedMap["GB:nsl_dual"] = seventy;
    1723          183 :     mySpeedMap["GB:nsl_single"] = sixty;
    1724          183 :     mySpeedMap["UK:motorway"] = seventy;
    1725          183 :     mySpeedMap["UK:nsl_dual"] = seventy;
    1726          183 :     mySpeedMap["UK:nsl_single"] = sixty;
    1727          183 :     mySpeedMap["UZ:living_street"] = 30. / 3.6;
    1728          183 :     mySpeedMap["UZ:urban"] = 70. / 3.6;
    1729          183 :     mySpeedMap["UZ:rural"] = 100. / 3.6;
    1730          183 :     mySpeedMap["UZ:motorway"] = 110. / 3.6;
    1731          183 : }
    1732              : 
    1733          183 : NIImporter_OpenStreetMap::EdgesHandler::~EdgesHandler() = default;
    1734              : 
    1735              : void
    1736       674776 : NIImporter_OpenStreetMap::EdgesHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) {
    1737       674776 :     if (element == SUMO_TAG_WAY) {
    1738        45937 :         bool ok = true;
    1739        45937 :         const long long int id = attrs.get<long long int>(SUMO_ATTR_ID, nullptr, ok);
    1740        45937 :         const std::string& action = attrs.getOpt<std::string>(SUMO_ATTR_ACTION, nullptr, ok);
    1741        45937 :         if (action == "delete" || !ok) {
    1742         2878 :             myCurrentEdge = nullptr;
    1743              :             return;
    1744              :         }
    1745        43059 :         myCurrentEdge = new Edge(id);
    1746              :     }
    1747              :     // parse "nd" (node) elements
    1748       671898 :     if (element == SUMO_TAG_ND && myCurrentEdge != nullptr) {
    1749       388613 :         bool ok = true;
    1750       388613 :         long long int ref = attrs.get<long long int>(SUMO_ATTR_REF, nullptr, ok);
    1751       388613 :         if (ok) {
    1752       388613 :             auto node = myOSMNodes.find(ref);
    1753       388613 :             if (node == myOSMNodes.end()) {
    1754        19504 :                 WRITE_WARNINGF(TL("The referenced geometry information (ref='%') is not known"), toString(ref));
    1755              :                 return;
    1756              :             }
    1757              : 
    1758       378861 :             ref = node->second->id; // node may have been substituted
    1759       378861 :             if (myCurrentEdge->myCurrentNodes.empty() ||
    1760       336907 :                     myCurrentEdge->myCurrentNodes.back() != ref) { // avoid consecutive duplicates
    1761       378846 :                 myCurrentEdge->myCurrentNodes.push_back(ref);
    1762              :             }
    1763              : 
    1764              :         }
    1765              :     }
    1766       662146 :     if (element == SUMO_TAG_TAG && myCurrentEdge != nullptr) {
    1767       216401 :         bool ok = true;
    1768       432802 :         std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myCurrentEdge->id).c_str(), ok, false);
    1769       370173 :         if (key.size() > 6 && StringUtils::startsWith(key, "busway:")) {
    1770              :             // handle special busway keys
    1771           17 :             const std::string buswaySpec = key.substr(7);
    1772              :             key = "busway";
    1773           17 :             if (buswaySpec == "right") {
    1774           13 :                 myCurrentEdge->myBuswayType = (WayType)(myCurrentEdge->myBuswayType | WAY_FORWARD);
    1775            4 :             } else if (buswaySpec == "left") {
    1776            4 :                 myCurrentEdge->myBuswayType = (WayType)(myCurrentEdge->myBuswayType | WAY_BACKWARD);
    1777            0 :             } else if (buswaySpec == "both") {
    1778            0 :                 myCurrentEdge->myBuswayType = (WayType)(myCurrentEdge->myBuswayType | WAY_BOTH);
    1779              :             } else {
    1780              :                 key = "ignore";
    1781              :             }
    1782              :         }
    1783       220526 :         if (myAllAttributes && (myExtraAttributes.count(key) != 0 || myExtraAttributes.size() == 0)) {
    1784          998 :             const std::string info = "way=" + toString(myCurrentEdge->id) + ", k=" + key;
    1785         1996 :             myCurrentEdge->setParameter(key, attrs.get<std::string>(SUMO_ATTR_V, info.c_str(), ok, false));
    1786              :         }
    1787              :         // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
    1788       432802 :         if (!StringUtils::endsWith(key, "way")
    1789       404680 :                 && !StringUtils::startsWith(key, "lanes")
    1790       183749 :                 && key != "maxspeed" && key != "maxspeed:type"
    1791       176861 :                 && key != "zone:maxspeed"
    1792       176819 :                 && key != "maxspeed:forward" && key != "maxspeed:backward"
    1793       176788 :                 && key != "junction" && key != "name" && key != "tracks" && key != "layer"
    1794       162300 :                 && key != "route"
    1795       378695 :                 && !StringUtils::startsWith(key, "cycleway")
    1796       375096 :                 && !StringUtils::startsWith(key, "sidewalk")
    1797       154450 :                 && key != "ref"
    1798       151378 :                 && key != "highspeed"
    1799       367769 :                 && !StringUtils::startsWith(key, "parking")
    1800       364707 :                 && !StringUtils::startsWith(key, "change")
    1801       364623 :                 && !StringUtils::startsWith(key, "vehicle:lanes")
    1802       148161 :                 && key != "postal_code"
    1803       143514 :                 && key != "railway:preferred_direction"
    1804       143321 :                 && key != "railway:bidirectional"
    1805       143317 :                 && key != "railway:track_ref"
    1806       143197 :                 && key != "usage"
    1807       141604 :                 && key != "access"
    1808       140073 :                 && key != "emergency"
    1809       140033 :                 && key != "service"
    1810       138542 :                 && key != "electrified"
    1811       135439 :                 && key != "segregated"
    1812       135078 :                 && key != "bus"
    1813       134538 :                 && key != "psv"
    1814       134385 :                 && key != "foot"
    1815       131986 :                 && key != "bicycle"
    1816       129985 :                 && key != "oneway:bicycle"
    1817       129765 :                 && key != "oneway:bus"
    1818       129750 :                 && key != "oneway:psv"
    1819       129739 :                 && key != "bus:lanes"
    1820       129701 :                 && key != "bus:lanes:forward"
    1821       129661 :                 && key != "bus:lanes:backward"
    1822       129631 :                 && key != "psv:lanes"
    1823       129623 :                 && key != "psv:lanes:forward"
    1824       129620 :                 && key != "psv:lanes:backward"
    1825       129617 :                 && key != "bicycle:lanes"
    1826       129612 :                 && key != "bicycle:lanes:forward"
    1827       129599 :                 && key != "bicycle:lanes:backward"
    1828       345994 :                 && !StringUtils::startsWith(key, "width")
    1829       475250 :                 && !(StringUtils::startsWith(key, "turn:") && key.find(":lanes") != std::string::npos)
    1830       344414 :                 && key != "public_transport") {
    1831              :             return;
    1832              :         }
    1833        89232 :         const std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentEdge->id).c_str(), ok, false);
    1834              : 
    1835       160651 :         if (key == "highway" || key == "railway" || key == "waterway" || StringUtils::startsWith(key, "cycleway")
    1836       211547 :                 || key == "busway" || key == "route" || StringUtils::startsWith(key, "sidewalk") || key == "highspeed"
    1837       148262 :                 || key == "aeroway" || key == "aerialway" || key == "usage" || key == "service") {
    1838              :             // build type id
    1839        86726 :             if (key != "highway" || myTypeCont.knows(key + "." + value)) {
    1840        33168 :                 myCurrentEdge->myCurrentIsRoad = true;
    1841              :             }
    1842              :             // special cycleway stuff https://wiki.openstreetmap.org/wiki/Key:cycleway
    1843        33287 :             if (key == "cycleway") {
    1844          748 :                 if (value == "no" || value == "none" || value == "separate") {
    1845           41 :                     myCurrentEdge->myCyclewayType = WAY_NONE;
    1846          707 :                 } else if (value == "both") {
    1847            0 :                     myCurrentEdge->myCyclewayType = WAY_BOTH;
    1848          707 :                 } else if (value == "right") {
    1849            0 :                     myCurrentEdge->myCyclewayType = WAY_FORWARD;
    1850          707 :                 } else if (value == "left") {
    1851            0 :                     myCurrentEdge->myCyclewayType = WAY_BACKWARD;
    1852          707 :                 } else if (value == "opposite_track") {
    1853            6 :                     myCurrentEdge->myCyclewayType = WAY_BACKWARD;
    1854          701 :                 } else if (value == "opposite_lane") {
    1855            5 :                     myCurrentEdge->myCyclewayType = WAY_BACKWARD;
    1856          696 :                 } else if (value == "opposite") {
    1857              :                     // according to the wiki ref above, this should rather be a bidi lane, see #13438
    1858          110 :                     myCurrentEdge->myCyclewayType = WAY_BACKWARD;
    1859              :                 }
    1860              :             }
    1861        33287 :             if (key == "cycleway:left") {
    1862          475 :                 if (myCurrentEdge->myCyclewayType == WAY_UNKNOWN) {
    1863          475 :                     myCurrentEdge->myCyclewayType = WAY_NONE;
    1864              :                 }
    1865          475 :                 if (value == "yes" || value == "lane" || value == "track") {
    1866           73 :                     myCurrentEdge->myCyclewayType = (WayType)(myCurrentEdge->myCyclewayType | WAY_BACKWARD);
    1867              :                 }
    1868              :                 key = "cycleway"; // for type adaption
    1869              :             }
    1870        33287 :             if (key == "cycleway:right") {
    1871         1256 :                 if (myCurrentEdge->myCyclewayType == WAY_UNKNOWN) {
    1872          827 :                     myCurrentEdge->myCyclewayType = WAY_NONE;
    1873              :                 }
    1874         1256 :                 if (value == "yes" || value == "lane" || value == "track") {
    1875          824 :                     myCurrentEdge->myCyclewayType = (WayType)(myCurrentEdge->myCyclewayType | WAY_FORWARD);
    1876              :                 }
    1877              :                 key = "cycleway"; // for type adaption
    1878              :             }
    1879        33287 :             if (key == "cycleway:both") {
    1880          480 :                 if (myCurrentEdge->myCyclewayType == WAY_UNKNOWN) {
    1881          479 :                     if (value == "no" || value == "none" || value == "separate") {
    1882          395 :                         myCurrentEdge->myCyclewayType = WAY_NONE;
    1883              :                     }
    1884          479 :                     if (value == "yes" || value == "lane" || value == "track") {
    1885           77 :                         myCurrentEdge->myCyclewayType = WAY_BOTH;
    1886              :                     }
    1887              :                 }
    1888              :                 key = "cycleway"; // for type adaption
    1889              :             }
    1890        33287 :             if (key == "cycleway" && value != "lane" && value != "track" && value != "opposite_track" && value != "opposite_lane") {
    1891              :                 // typemap covers only the lane and track cases
    1892         7274 :                 return;
    1893              :             }
    1894        63362 :             if (StringUtils::startsWith(key, "cycleway:")) {
    1895              :                 // no need to extend the type id for other cycleway sub tags
    1896              :                 return;
    1897              :             }
    1898              :             // special sidewalk stuff
    1899        30288 :             if (key == "sidewalk") {
    1900         2703 :                 if (value == "no" || value == "none" || value == "separate") {
    1901          283 :                     myCurrentEdge->mySidewalkType = WAY_NONE;
    1902         2420 :                 } else if (value == "both") {
    1903         1392 :                     myCurrentEdge->mySidewalkType = WAY_BOTH;
    1904         1028 :                 } else if (value == "right") {
    1905          966 :                     myCurrentEdge->mySidewalkType = WAY_FORWARD;
    1906           62 :                 } else if (value == "left") {
    1907           62 :                     myCurrentEdge->mySidewalkType = WAY_BACKWARD;
    1908              :                 }
    1909              :             }
    1910        30288 :             if (key == "sidewalk:left") {
    1911          495 :                 if (myCurrentEdge->mySidewalkType == WAY_UNKNOWN) {
    1912          495 :                     myCurrentEdge->mySidewalkType = WAY_NONE;
    1913              :                 }
    1914          495 :                 if (value == "yes") {
    1915            2 :                     myCurrentEdge->mySidewalkType = (WayType)(myCurrentEdge->mySidewalkType | WAY_BACKWARD);
    1916              :                 }
    1917              :             }
    1918        30288 :             if (key == "sidewalk:right") {
    1919          500 :                 if (myCurrentEdge->mySidewalkType == WAY_UNKNOWN) {
    1920            6 :                     myCurrentEdge->mySidewalkType = WAY_NONE;
    1921              :                 }
    1922          500 :                 if (value == "yes") {
    1923           19 :                     myCurrentEdge->mySidewalkType = (WayType)(myCurrentEdge->mySidewalkType | WAY_FORWARD);
    1924              :                 }
    1925              :             }
    1926        30288 :             if (key == "sidewalk:both") {
    1927          231 :                 if (myCurrentEdge->mySidewalkType == WAY_UNKNOWN) {
    1928          231 :                     if (value == "no" || value == "none" || value == "separate") {
    1929          231 :                         myCurrentEdge->mySidewalkType = WAY_NONE;
    1930              :                     }
    1931          231 :                     if (value == "yes") {
    1932            0 :                         myCurrentEdge->mySidewalkType = WAY_BOTH;
    1933              :                     }
    1934              :                 }
    1935              :             }
    1936        60576 :             if (StringUtils::startsWith(key, "sidewalk")) {
    1937              :                 // no need to extend the type id
    1938              :                 return;
    1939              :             }
    1940              :             // special busway stuff
    1941        26043 :             if (key == "busway") {
    1942           24 :                 if (value == "no") {
    1943              :                     return;
    1944              :                 }
    1945           24 :                 if (value == "opposite_track") {
    1946            0 :                     myCurrentEdge->myBuswayType = WAY_BACKWARD;
    1947           24 :                 } else if (value == "opposite_lane") {
    1948            9 :                     myCurrentEdge->myBuswayType = WAY_BACKWARD;
    1949              :                 }
    1950              :                 // no need to extend the type id
    1951           24 :                 return;
    1952              :             }
    1953        26019 :             std::string singleTypeID = key + "." + value;
    1954        26019 :             if (key == "highspeed") {
    1955           10 :                 if (value == "no") {
    1956              :                     return;
    1957              :                 }
    1958              :                 singleTypeID = "railway.highspeed";
    1959              :             }
    1960        26013 :             addType(singleTypeID);
    1961              : 
    1962        55945 :         } else if (key == "bus" || key == "psv") {
    1963              :             // 'psv' includes taxi in the UK but not in germany
    1964              :             try {
    1965          693 :                 if (StringUtils::toBool(value)) {
    1966          648 :                     myCurrentEdge->myExtraAllowed |= SVC_BUS;
    1967          648 :                     addType(key);
    1968              :                 } else {
    1969            6 :                     myCurrentEdge->myExtraDisallowed |= SVC_BUS;
    1970              :                 }
    1971           39 :             } catch (const BoolFormatException&) {
    1972           39 :                 myCurrentEdge->myExtraAllowed |= SVC_BUS;
    1973           39 :                 addType(key);
    1974           39 :             }
    1975        55252 :         } else if (key == "emergency") {
    1976              :             try {
    1977           40 :                 if (StringUtils::toBool(value)) {
    1978           31 :                     myCurrentEdge->myExtraAllowed |= SVC_AUTHORITY | SVC_EMERGENCY;
    1979              :                 }
    1980            9 :             } catch (const BoolFormatException&) {
    1981            9 :                 myCurrentEdge->myExtraAllowed |= SVC_AUTHORITY | SVC_EMERGENCY;
    1982            9 :             }
    1983        55212 :         } else if (key == "access") {
    1984         1531 :             if (value == "no") {
    1985          194 :                 myCurrentEdge->myExtraDisallowed |= ~(SVC_PUBLIC_CLASSES | SVC_EMERGENCY | SVC_AUTHORITY);
    1986              :             }
    1987       107362 :         } else if (StringUtils::startsWith(key, "width:lanes")) {
    1988              :             try {
    1989           15 :                 const std::vector<std::string> values = StringTokenizer(value, "|").getVector();
    1990              :                 std::vector<double> widthLanes;
    1991           19 :                 for (std::string width : values) {
    1992           14 :                     const double parsedWidth = width == "" ? -1 : StringUtils::parseDist(width);
    1993           14 :                     widthLanes.push_back(parsedWidth);
    1994              :                 }
    1995              : 
    1996            5 :                 if (key == "width:lanes" || key == "width:lanes:forward") {
    1997            3 :                     myCurrentEdge->myWidthLanesForward = widthLanes;
    1998            2 :                 } else if (key == "width:lanes:backward") {
    1999            2 :                     myCurrentEdge->myWidthLanesBackward = widthLanes;
    2000              :                 } else {
    2001            0 :                     WRITE_WARNINGF(TL("Using default lane width for edge '%' as key '%' could not be parsed."), toString(myCurrentEdge->id), key);
    2002              :                 }
    2003            5 :             } catch (const NumberFormatException&) {
    2004            0 :                 WRITE_WARNINGF(TL("Using default lane width for edge '%' as value '%' could not be parsed."), toString(myCurrentEdge->id), value);
    2005            0 :             }
    2006        53676 :         } else if (key == "width") {
    2007              :             try {
    2008          634 :                 myCurrentEdge->myWidth = StringUtils::parseDist(value);
    2009            0 :             } catch (const NumberFormatException&) {
    2010            0 :                 WRITE_WARNINGF(TL("Using default width for edge '%' as value '%' could not be parsed."), toString(myCurrentEdge->id), value);
    2011            0 :             }
    2012        53042 :         } else if (key == "foot") {
    2013         2399 :             if (value == "use_sidepath" || value == "no") {
    2014         1370 :                 myCurrentEdge->myExtraDisallowed |= SVC_PEDESTRIAN;
    2015         1029 :             } else if (value == "yes" || value == "designated" || value == "permissive") {
    2016          973 :                 myCurrentEdge->myExtraAllowed |= SVC_PEDESTRIAN;
    2017              :             }
    2018        50643 :         } else if (key == "bicycle") {
    2019         2001 :             if (value == "use_sidepath" || value == "no") {
    2020          726 :                 myCurrentEdge->myExtraDisallowed |= SVC_BICYCLE;
    2021         1275 :             } else if (value == "yes" || value == "designated" || value == "permissive") {
    2022         1163 :                 myCurrentEdge->myExtraAllowed |= SVC_BICYCLE;
    2023              :             }
    2024        48642 :         } else if (key == "oneway:bicycle") {
    2025          440 :             myCurrentEdge->myExtraTags["oneway:bicycle"] = value;
    2026        48422 :         } else if (key == "oneway:bus" || key == "oneway:psv") {
    2027           26 :             if (value == "no") {
    2028              :                 // need to add a bus way in reversed direction of way
    2029           26 :                 myCurrentEdge->myBuswayType = WAY_BACKWARD;
    2030              :             }
    2031        48396 :         } else if (key == "lanes") {
    2032              :             try {
    2033         3654 :                 myCurrentEdge->myNoLanes = StringUtils::toInt(value);
    2034            1 :             } catch (NumberFormatException&) {
    2035              :                 // might be a list of values
    2036            3 :                 StringTokenizer st(value, ";", true);
    2037            1 :                 std::vector<std::string> list = st.getVector();
    2038            1 :                 if (list.size() >= 2) {
    2039              :                     int minLanes = std::numeric_limits<int>::max();
    2040              :                     try {
    2041            4 :                         for (auto& i : list) {
    2042            6 :                             const int numLanes = StringUtils::toInt(StringUtils::prune(i));
    2043              :                             minLanes = MIN2(minLanes, numLanes);
    2044              :                         }
    2045            1 :                         myCurrentEdge->myNoLanes = minLanes;
    2046            3 :                         WRITE_WARNINGF(TL("Using minimum lane number from list (%) for edge '%'."), value, toString(myCurrentEdge->id));
    2047            0 :                     } catch (NumberFormatException&) {
    2048            0 :                         WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
    2049            0 :                     }
    2050              :                 }
    2051            1 :             } catch (EmptyData&) {
    2052            0 :                 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
    2053            0 :             }
    2054        44742 :         } else if (key == "lanes:forward") {
    2055              :             try {
    2056          392 :                 const int numLanes = StringUtils::toInt(value);
    2057          392 :                 if (myCurrentEdge->myNoLanesForward < 0 && myCurrentEdge->myNoLanes < 0) {
    2058              :                     // fix lane count in case only lanes:forward and lanes:backward are set
    2059           31 :                     myCurrentEdge->myNoLanes = numLanes - myCurrentEdge->myNoLanesForward;
    2060              :                 }
    2061          392 :                 myCurrentEdge->myNoLanesForward = numLanes;
    2062            0 :             } catch (...) {
    2063            0 :                 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
    2064            0 :             }
    2065        44350 :         } else if (key == "lanes:backward") {
    2066              :             try {
    2067          375 :                 const int numLanes = StringUtils::toInt(value);
    2068          375 :                 if (myCurrentEdge->myNoLanesForward > 0 && myCurrentEdge->myNoLanes < 0) {
    2069              :                     // fix lane count in case only lanes:forward and lanes:backward are set
    2070            2 :                     myCurrentEdge->myNoLanes = numLanes + myCurrentEdge->myNoLanesForward;
    2071              :                 }
    2072              :                 // denote backwards count with a negative sign
    2073          375 :                 myCurrentEdge->myNoLanesForward = -numLanes;
    2074            0 :             } catch (...) {
    2075            0 :                 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
    2076            0 :             }
    2077        43975 :         } else if (myCurrentEdge->myMaxSpeed == MAXSPEED_UNGIVEN &&
    2078        26538 :                    (key == "maxspeed" || key == "maxspeed:type" || key == "maxspeed:forward" || key == "zone:maxspeed")) {
    2079              :             // both 'maxspeed' and 'maxspeed:type' may be given so we must take care not to overwrite an already seen value
    2080         6760 :             myCurrentEdge->myMaxSpeed = interpretSpeed(key, value);
    2081        37215 :         } else if (key == "maxspeed:backward" && myCurrentEdge->myMaxSpeedBackward == MAXSPEED_UNGIVEN) {
    2082           13 :             myCurrentEdge->myMaxSpeedBackward = interpretSpeed(key, value);
    2083        37202 :         } else if (key == "junction") {
    2084           55 :             if ((value == "roundabout" || value == "circular") && myCurrentEdge->myIsOneWay.empty()) {
    2085           36 :                 myCurrentEdge->myIsOneWay = "yes";
    2086              :             }
    2087           55 :             if (value == "roundabout") {
    2088           28 :                 myCurrentEdge->myAmInRoundabout = true;
    2089              :             }
    2090        37147 :         } else if (key == "oneway") {
    2091         4161 :             myCurrentEdge->myIsOneWay = value;
    2092        32986 :         } else if (key == "name") {
    2093        10240 :             myCurrentEdge->streetName = value;
    2094        22746 :         } else if (key == "ref") {
    2095         3072 :             myCurrentEdge->ref = value;
    2096         6144 :             myCurrentEdge->setParameter("ref", value);
    2097        19674 :         } else if (key == "layer") {
    2098              :             try {
    2099         3790 :                 myCurrentEdge->myLayer = StringUtils::toInt(value);
    2100            0 :             } catch (...) {
    2101            0 :                 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
    2102            0 :             }
    2103        15884 :         } else if (key == "tracks") {
    2104              :             try {
    2105          403 :                 if (StringUtils::toInt(value) == 1) {
    2106          373 :                     myCurrentEdge->myIsOneWay = "true";
    2107              :                 } else {
    2108           87 :                     WRITE_WARNINGF(TL("Ignoring track count % for edge '%'."), value, myCurrentEdge->id);
    2109              :                 }
    2110            1 :             } catch (...) {
    2111            3 :                 WRITE_WARNINGF(TL("Value of key '%' is not numeric ('%') in edge '%'."), key, value, myCurrentEdge->id);
    2112            1 :             }
    2113        15481 :         } else if (key == "railway:preferred_direction") {
    2114          193 :             if (value == "both") {
    2115           41 :                 myCurrentEdge->myRailDirection = WAY_BOTH;
    2116          152 :             } else if (myCurrentEdge->myRailDirection == WAY_UNKNOWN) {
    2117          150 :                 if (value == "backward") {
    2118            4 :                     myCurrentEdge->myRailDirection = WAY_BACKWARD;
    2119          146 :                 } else if (value == "forward") {
    2120          146 :                     myCurrentEdge->myRailDirection = WAY_FORWARD;
    2121              :                 }
    2122              :             }
    2123        15288 :         } else if (key == "railway:bidirectional") {
    2124            4 :             if (value == "regular") {
    2125            4 :                 myCurrentEdge->myRailDirection = WAY_BOTH;
    2126              :             }
    2127        15284 :         } else if (key == "electrified" || key == "segregated") {
    2128         3464 :             if (value != "no") {
    2129         3204 :                 myCurrentEdge->myExtraTags[key] = value;
    2130              :             }
    2131        11820 :         } else if (key == "railway:track_ref") {
    2132          120 :             myCurrentEdge->setParameter(key, value);
    2133        11700 :         } else if (key == "public_transport" && value == "platform") {
    2134         1660 :             myCurrentEdge->myExtraTags["platform"] = "yes";
    2135        12117 :         } else if ((key == "parking:both" || key == "parking:lane:both") && !StringUtils::startsWith(value, "no")) {
    2136          121 :             myCurrentEdge->myParkingType |= PARKING_BOTH;
    2137        11163 :         } else if ((key == "parking:left" || key == "parking:lane:left") && !StringUtils::startsWith(value, "no")) {
    2138           84 :             myCurrentEdge->myParkingType |= PARKING_LEFT;
    2139        11135 :         } else if ((key == "parking:right" || key == "parking:lane:right") && !StringUtils::startsWith(value, "no")) {
    2140          220 :             myCurrentEdge->myParkingType |= PARKING_RIGHT;
    2141        10445 :         } else if (key == "change" || key == "change:lanes") {
    2142           14 :             myCurrentEdge->myChangeForward = myCurrentEdge->myChangeBackward = interpretChangeType(value);
    2143        10431 :         } else if (key == "change:forward" || key == "change:lanes:forward") {
    2144           35 :             myCurrentEdge->myChangeForward = interpretChangeType(value);
    2145        10396 :         } else if (key == "change:backward" || key == "change:lanes:backward") {
    2146           35 :             myCurrentEdge->myChangeBackward = interpretChangeType(value);
    2147        10361 :         } else if (key == "vehicle:lanes" || key == "vehicle:lanes:forward") {
    2148           44 :             interpretLaneUse(value, SVC_PASSENGER, true);
    2149           44 :             interpretLaneUse(value, SVC_PRIVATE, true);
    2150        10317 :         } else if (key == "vehicle:lanes:backward") {
    2151           16 :             interpretLaneUse(value, SVC_PASSENGER, false);
    2152           16 :             interpretLaneUse(value, SVC_PRIVATE, false);
    2153        10301 :         } else if (key == "bus:lanes" || key == "bus:lanes:forward") {
    2154           78 :             interpretLaneUse(value, SVC_BUS, true);
    2155        10223 :         } else if (key == "bus:lanes:backward") {
    2156           30 :             interpretLaneUse(value, SVC_BUS, false);
    2157        10193 :         } else if (key == "psv:lanes" || key == "psv:lanes:forward") {
    2158           11 :             interpretLaneUse(value, SVC_BUS, true);
    2159           11 :             interpretLaneUse(value, SVC_TAXI, true);
    2160        10182 :         } else if (key == "psv:lanes:backward") {
    2161            3 :             interpretLaneUse(value, SVC_BUS, false);
    2162            3 :             interpretLaneUse(value, SVC_TAXI, false);
    2163        10179 :         } else if (key == "bicycle:lanes" || key == "bicycle:lanes:forward") {
    2164           18 :             interpretLaneUse(value, SVC_BICYCLE, true);
    2165        10161 :         } else if (key == "bicycle:lanes:backward") {
    2166            6 :             interpretLaneUse(value, SVC_BICYCLE, false);
    2167        21251 :         } else if (StringUtils::startsWith(key, "turn:") && key.find(":lanes") != std::string::npos) {
    2168              :             int shift = 0;
    2169              :             // use the first 8 bit to encode permitted directions for all classes
    2170              :             // and the successive 8 bit blocks for selected classes
    2171         1878 :             if (StringUtils::startsWith(key, "turn:bus") || StringUtils::startsWith(key, "turn:psv:")) {
    2172              :                 shift = NBEdge::TURN_SIGN_SHIFT_BUS;
    2173         1874 :             } else if (StringUtils::startsWith(key, "turn:taxi")) {
    2174              :                 shift = NBEdge::TURN_SIGN_SHIFT_TAXI;
    2175         1874 :             } else if (StringUtils::startsWith(key, "turn:bicycle")) {
    2176              :                 shift = NBEdge::TURN_SIGN_SHIFT_BICYCLE;
    2177              :             }
    2178         2823 :             const std::vector<std::string> values = StringTokenizer(value, "|").getVector();
    2179              :             std::vector<int> turnCodes;
    2180         3478 :             for (std::string codeList : values) {
    2181         7611 :                 const std::vector<std::string> codes = StringTokenizer(codeList, ";").getVector();
    2182         2537 :                 int turnCode = 0;
    2183         2537 :                 if (codes.size() == 0) {
    2184           24 :                     turnCode = (int)LinkDirection::STRAIGHT;
    2185              :                 }
    2186         5443 :                 for (std::string code : codes) {
    2187         2906 :                     if (code == "" || code == "none" || code == "through") {
    2188         1451 :                         turnCode |= (int)LinkDirection::STRAIGHT << shift ;
    2189         1455 :                     } else if (code == "left" || code == "sharp_left") {
    2190          707 :                         turnCode |= (int)LinkDirection::LEFT << shift;
    2191          748 :                     } else if (code == "right" || code == "sharp_right") {
    2192          592 :                         turnCode |= (int)LinkDirection::RIGHT << shift;
    2193          156 :                     } else if (code == "slight_left") {
    2194           62 :                         turnCode |= (int)LinkDirection::PARTLEFT << shift;
    2195           94 :                     } else if (code == "slight_right") {
    2196           53 :                         turnCode |= (int)LinkDirection::PARTRIGHT << shift;
    2197           41 :                     } else if (code == "reverse") {
    2198            0 :                         turnCode |= (int)LinkDirection::TURN << shift;
    2199           41 :                     } else if (code == "merge_to_left" || code == "merge_to_right") {
    2200           37 :                         turnCode |= (int)LinkDirection::NODIR << shift;
    2201              :                     }
    2202              :                 }
    2203         2537 :                 turnCodes.push_back(turnCode);
    2204         2537 :             }
    2205         1224 :             if (StringUtils::endsWith(key, "lanes") || StringUtils::endsWith(key, "lanes:forward")) {
    2206          828 :                 mergeTurnSigns(myCurrentEdge->myTurnSignsForward, turnCodes);
    2207          226 :             } else if (StringUtils::endsWith(key, "lanes:backward")) {
    2208          113 :                 mergeTurnSigns(myCurrentEdge->myTurnSignsBackward, turnCodes);
    2209            0 :             } else if (StringUtils::endsWith(key, "lanes:both_ways")) {
    2210            0 :                 mergeTurnSigns(myCurrentEdge->myTurnSignsForward, turnCodes);
    2211            0 :                 mergeTurnSigns(myCurrentEdge->myTurnSignsBackward, turnCodes);
    2212              :             }
    2213          941 :         }
    2214              :     }
    2215              : }
    2216              : 
    2217              : 
    2218              : void
    2219        26700 : NIImporter_OpenStreetMap::EdgesHandler::addType(const std::string& singleTypeID) {
    2220              :     // special case: never build compound type for highspeed rail
    2221        26700 :     if (!myCurrentEdge->myHighWayType.empty() && singleTypeID != "railway.highspeed") {
    2222         4773 :         if (myCurrentEdge->myHighWayType == "railway.highspeed") {
    2223            8 :             return;
    2224              :         }
    2225              :         // osm-ways may be used by more than one mode (eg railway.tram + highway.residential. this is relevant for multimodal traffic)
    2226              :         // we create a new type for this kind of situation which must then be resolved in insertEdge()
    2227        19060 :         std::vector<std::string> types = StringTokenizer(myCurrentEdge->myHighWayType,
    2228         4765 :                                          compoundTypeSeparator).getVector();
    2229         4765 :         types.push_back(singleTypeID);
    2230         4765 :         myCurrentEdge->myHighWayType = joinToStringSorting(types, compoundTypeSeparator);
    2231         4765 :     } else {
    2232        21927 :         myCurrentEdge->myHighWayType = singleTypeID;
    2233              :     }
    2234              : }
    2235              : 
    2236              : 
    2237              : double
    2238         6773 : NIImporter_OpenStreetMap::EdgesHandler::interpretSpeed(const std::string& key, std::string value) {
    2239         6773 :     if (mySpeedMap.find(value) != mySpeedMap.end()) {
    2240           32 :         return mySpeedMap[value];
    2241              :     } else {
    2242              :         // handle symbolic names of the form DE:30 / DE:zone30
    2243         6741 :         if (value.size() > 3 && value[2] == ':') {
    2244            6 :             if (value.substr(3, 4) == "zone") {
    2245            2 :                 value = value.substr(7);
    2246              :             } else {
    2247           10 :                 value = value.substr(3);
    2248              :             }
    2249              :         }
    2250              :         try {
    2251         6741 :             return StringUtils::parseSpeed(value);
    2252            4 :         } catch (...) {
    2253           16 :             WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
    2254              :                           toString(myCurrentEdge->id) + "'.");
    2255              :             return MAXSPEED_UNGIVEN;
    2256            4 :         }
    2257              :     }
    2258              : }
    2259              : 
    2260              : 
    2261              : int
    2262           84 : NIImporter_OpenStreetMap::EdgesHandler::interpretChangeType(const std::string& value) const {
    2263              :     int result = 0;
    2264          252 :     const std::vector<std::string> values = StringTokenizer(value, "|").getVector();
    2265          233 :     for (const std::string& val : values) {
    2266          149 :         if (val == "no") {
    2267           35 :             result += CHANGE_NO;
    2268          114 :         } else if (val == "not_left") {
    2269           64 :             result += CHANGE_NO_LEFT;
    2270           50 :         } else if (val == "not_right") {
    2271           11 :             result += CHANGE_NO_RIGHT;
    2272              :         }
    2273          149 :         result = result << 2;
    2274              :     }
    2275              :     // last shift was superfluous
    2276           84 :     result = result >> 2;
    2277              : 
    2278           84 :     if (values.size() > 1) {
    2279           49 :         result += 2 << 29; // mark multi-value input
    2280              :     }
    2281              :     //std::cout << " way=" << myCurrentEdge->id << " value=" << value << " result=" << std::bitset<32>(result) << "\n";
    2282           84 :     return result;
    2283           84 : }
    2284              : 
    2285              : 
    2286              : void
    2287          280 : NIImporter_OpenStreetMap::EdgesHandler::interpretLaneUse(const std::string& value, SUMOVehicleClass svc, const bool forward) const {
    2288          840 :     const std::vector<std::string> values = StringTokenizer(value, "|").getVector();
    2289          280 :     std::vector<bool>& designated = forward ? myCurrentEdge->myDesignatedLaneForward : myCurrentEdge->myDesignatedLaneBackward;
    2290          280 :     std::vector<SVCPermissions>& allowed = forward ? myCurrentEdge->myAllowedLaneForward : myCurrentEdge->myAllowedLaneBackward;
    2291          280 :     std::vector<SVCPermissions>& disallowed = forward ? myCurrentEdge->myDisallowedLaneForward : myCurrentEdge->myDisallowedLaneBackward;
    2292          280 :     designated.resize(MAX2(designated.size(), values.size()), false);
    2293          280 :     allowed.resize(MAX2(allowed.size(), values.size()), SVC_IGNORING);
    2294          280 :     disallowed.resize(MAX2(disallowed.size(), values.size()), SVC_IGNORING);
    2295              :     int i = 0;
    2296          997 :     for (const std::string& val : values) {
    2297          717 :         if (val == "yes" || val == "permissive") {
    2298          286 :             allowed[i] |= svc;
    2299          431 :         } else if (val == "lane" || val == "designated") {
    2300          152 :             allowed[i] |= svc;
    2301              :             designated[i] = true;
    2302          279 :         } else if (val == "no") {
    2303          233 :             disallowed[i] |= svc;
    2304              :         } else {
    2305          138 :             WRITE_WARNINGF(TL("Unknown lane use specifier '%' ignored for way '%'"), val, myCurrentEdge->id);
    2306              :         }
    2307          717 :         i++;
    2308              :     }
    2309          280 : }
    2310              : 
    2311              : 
    2312              : void
    2313       674847 : NIImporter_OpenStreetMap::EdgesHandler::myEndElement(int element) {
    2314       674847 :     if (element == SUMO_TAG_WAY && myCurrentEdge != nullptr) {
    2315        43059 :         if (myCurrentEdge->myCurrentIsRoad) {
    2316        21418 :             const auto insertionIt = myEdgeMap.lower_bound(myCurrentEdge->id);
    2317        21418 :             if (insertionIt == myEdgeMap.end() || insertionIt->first != myCurrentEdge->id) {
    2318              :                 // assume we are loading multiple files, so we won't report duplicate edges
    2319        21344 :                 myEdgeMap.emplace_hint(insertionIt, myCurrentEdge->id, myCurrentEdge);
    2320              :             } else {
    2321           74 :                 delete myCurrentEdge;
    2322              :             }
    2323        43282 :         } else if (myCurrentEdge->myExtraTags.count("platform") != 0) {
    2324          473 :             const auto insertionIt = myPlatformShapesMap.lower_bound(myCurrentEdge->id);
    2325          473 :             if (insertionIt == myPlatformShapesMap.end() || insertionIt->first != myCurrentEdge->id) {
    2326              :                 // assume we are loading multiple files, so we won't report duplicate platforms
    2327          467 :                 myPlatformShapesMap.emplace_hint(insertionIt, myCurrentEdge->id, myCurrentEdge);
    2328              :             } else {
    2329            6 :                 delete myCurrentEdge;
    2330              :             }
    2331              :         } else {
    2332        21168 :             delete myCurrentEdge;
    2333              :         }
    2334        43059 :         myCurrentEdge = nullptr;
    2335              :     }
    2336       674847 : }
    2337              : 
    2338              : 
    2339              : // ---------------------------------------------------------------------------
    2340              : // definitions of NIImporter_OpenStreetMap::RelationHandler-methods
    2341              : // ---------------------------------------------------------------------------
    2342          183 : NIImporter_OpenStreetMap::RelationHandler::RelationHandler(
    2343              :     const std::map<long long int, NIOSMNode*>& osmNodes,
    2344              :     const std::map<long long int, Edge*>& osmEdges, NBPTStopCont* nbptStopCont,
    2345              :     const std::map<long long int, Edge*>& platformShapes,
    2346              :     NBPTLineCont* nbptLineCont,
    2347          183 :     const OptionsCont& oc) :
    2348              :     SUMOSAXHandler("osm - file"),
    2349          183 :     myOSMNodes(osmNodes),
    2350          183 :     myOSMEdges(osmEdges),
    2351          183 :     myPlatformShapes(platformShapes),
    2352          183 :     myNBPTStopCont(nbptStopCont),
    2353          183 :     myNBPTLineCont(nbptLineCont),
    2354          366 :     myOptionsCont(oc) {
    2355          183 :     resetValues();
    2356          183 : }
    2357              : 
    2358              : 
    2359          366 : NIImporter_OpenStreetMap::RelationHandler::~RelationHandler() = default;
    2360              : 
    2361              : 
    2362              : void
    2363         4822 : NIImporter_OpenStreetMap::RelationHandler::resetValues() {
    2364         4822 :     myCurrentRelation = INVALID_ID;
    2365         4822 :     myIsRestriction = false;
    2366         4822 :     myRestrictionException = SVC_IGNORING;
    2367         4822 :     myFromWay = INVALID_ID;
    2368         4822 :     myToWay = INVALID_ID;
    2369         4822 :     myViaNode = INVALID_ID;
    2370         4822 :     myViaWay = INVALID_ID;
    2371         4822 :     myStation = INVALID_ID;
    2372         4822 :     myRestrictionType = RestrictionType::UNKNOWN;
    2373              :     myPlatforms.clear();
    2374              :     myStops.clear();
    2375              :     myPlatformStops.clear();
    2376              :     myWays.clear();
    2377         4822 :     myIsStopArea = false;
    2378         4822 :     myIsRoute = false;
    2379         4822 :     myPTRouteType = "";
    2380         4822 :     myRouteColor.setValid(false);
    2381         4822 : }
    2382              : 
    2383              : 
    2384              : void
    2385       453522 : NIImporter_OpenStreetMap::RelationHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) {
    2386       453522 :     if (element == SUMO_TAG_RELATION) {
    2387         4639 :         bool ok = true;
    2388         4639 :         myCurrentRelation = attrs.get<long long int>(SUMO_ATTR_ID, nullptr, ok);
    2389         4639 :         const std::string& action = attrs.getOpt<std::string>(SUMO_ATTR_ACTION, nullptr, ok);
    2390         4639 :         if (action == "delete" || !ok) {
    2391            0 :             myCurrentRelation = INVALID_ID;
    2392              :         }
    2393         4639 :         myName = "";
    2394         4639 :         myRef = "";
    2395         4639 :         myInterval = -1;
    2396         4639 :         myNightService = "";
    2397              :         return;
    2398              :     }
    2399       448883 :     if (myCurrentRelation == INVALID_ID) {
    2400              :         return;
    2401              :     }
    2402       448882 :     if (element == SUMO_TAG_MEMBER) {
    2403       409462 :         bool ok = true;
    2404      1228386 :         std::string role = attrs.hasAttribute("role") ? attrs.getStringSecure("role", "") : "";
    2405       409462 :         const long long int ref = attrs.get<long long int>(SUMO_ATTR_REF, nullptr, ok);
    2406       409462 :         if (role == "via") {
    2407              :             // u-turns for divided ways may be given with 2 via-nodes or 1 via-way
    2408          391 :             std::string memberType = attrs.get<std::string>(SUMO_ATTR_TYPE, nullptr, ok);
    2409          391 :             if (memberType == "way" && checkEdgeRef(ref)) {
    2410           11 :                 myViaWay = ref;
    2411          380 :             } else if (memberType == "node") {
    2412          752 :                 if (myOSMNodes.find(ref) != myOSMNodes.end()) {
    2413          371 :                     myViaNode = ref;
    2414              :                 } else {
    2415           10 :                     WRITE_WARNINGF(TL("No node found for reference '%' in relation '%'."), toString(ref), toString(myCurrentRelation));
    2416              :                 }
    2417              :             }
    2418       409071 :         } else if (role == "from" && checkEdgeRef(ref)) {
    2419          374 :             myFromWay = ref;
    2420       408697 :         } else if (role == "to" && checkEdgeRef(ref)) {
    2421          334 :             myToWay = ref;
    2422       816726 :         } else if (StringUtils::startsWith(role, "stop")) {
    2423              :             // permit _entry_only and _exit_only variants
    2424        31335 :             myStops.push_back(ref);
    2425       754056 :         } else if (StringUtils::startsWith(role, "platform")) {
    2426              :             // permit _entry_only and _exit_only variants
    2427        29951 :             std::string memberType = attrs.get<std::string>(SUMO_ATTR_TYPE, nullptr, ok);
    2428        29951 :             if (memberType == "way") {
    2429        21888 :                 const std::map<long long int, NIImporter_OpenStreetMap::Edge*>::const_iterator& wayIt = myPlatformShapes.find(ref);
    2430        21888 :                 if (wayIt != myPlatformShapes.end()) {
    2431              :                     NIIPTPlatform platform;
    2432         1200 :                     platform.isWay = true;
    2433         1200 :                     platform.ref = ref;
    2434         1200 :                     myPlatforms.push_back(platform);
    2435              :                 }
    2436         8063 :             } else if (memberType == "node") {
    2437              :                 // myIsStopArea may not be set yet
    2438         5633 :                 myStops.push_back(ref);
    2439              :                 myPlatformStops.insert(ref);
    2440              :                 NIIPTPlatform platform;
    2441         5633 :                 platform.isWay = false;
    2442         5633 :                 platform.ref = ref;
    2443         5633 :                 myPlatforms.push_back(platform);
    2444              :             }
    2445              : 
    2446       347077 :         } else if (role == "station") {
    2447            5 :             myStation = ref;
    2448       347072 :         } else if (role.empty()) {
    2449       303716 :             std::string memberType = attrs.get<std::string>(SUMO_ATTR_TYPE, nullptr, ok);
    2450       303716 :             if (memberType == "way") {
    2451       297353 :                 myWays.push_back(ref);
    2452         6363 :             } else if (memberType == "node") {
    2453         4947 :                 auto it = myOSMNodes.find(ref);
    2454         5911 :                 if (it != myOSMNodes.end() && it->second->hasParameter("railway:ref")) {
    2455           20 :                     myStation = ref;
    2456              :                 } else {
    2457         4927 :                     myStops.push_back(ref);
    2458              :                 }
    2459              :             }
    2460              :         }
    2461              :         return;
    2462              :     }
    2463              :     // parse values
    2464        39420 :     if (element == SUMO_TAG_TAG) {
    2465        39420 :         bool ok = true;
    2466        39420 :         std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myCurrentRelation).c_str(), ok, false);
    2467              :         // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
    2468        39420 :         if (key == "type" || key == "restriction") {
    2469         5005 :             std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
    2470         5005 :             if (key == "type" && value == "restriction") {
    2471          374 :                 myIsRestriction = true;
    2472          374 :                 return;
    2473              :             }
    2474         4631 :             if (key == "type" && value == "route") {
    2475         1608 :                 myIsRoute = true;
    2476         1608 :                 return;
    2477              :             }
    2478         3023 :             if (key == "restriction") {
    2479              :                 // @note: the 'right/left/straight' part is ignored since the information is
    2480              :                 // redundantly encoded in the 'from', 'to' and 'via' members
    2481          373 :                 if (value.substr(0, 5) == "only_") {
    2482          200 :                     myRestrictionType = RestrictionType::ONLY;
    2483          173 :                 } else if (value.substr(0, 3) == "no_") {
    2484          173 :                     myRestrictionType = RestrictionType::NO;
    2485              :                 } else {
    2486            0 :                     WRITE_WARNINGF(TL("Found unknown restriction type '%' in relation '%'"), value, toString(myCurrentRelation));
    2487              :                 }
    2488          373 :                 return;
    2489              :             }
    2490        34415 :         } else if (key == "except") {
    2491           27 :             std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
    2492          117 :             for (const std::string& v : StringTokenizer(value, ";").getVector()) {
    2493           36 :                 if (v == "psv") {
    2494           16 :                     myRestrictionException |= SVC_BUS;
    2495           20 :                 } else if (v == "bicycle") {
    2496           12 :                     myRestrictionException |= SVC_BICYCLE;
    2497            8 :                 } else if (v == "hgv") {
    2498            0 :                     myRestrictionException |= SVC_TRUCK | SVC_TRAILER;
    2499            8 :                 } else if (v == "motorcar") {
    2500            2 :                     myRestrictionException |= SVC_PASSENGER | SVC_TAXI;
    2501            6 :                 } else if (v == "emergency") {
    2502            1 :                     myRestrictionException |= SVC_EMERGENCY;
    2503              :                 }
    2504           27 :             }
    2505        34388 :         } else if (key == "public_transport") {
    2506          469 :             std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
    2507          469 :             if (value == "stop_area") {
    2508          375 :                 myIsStopArea = true;
    2509              :             }
    2510        33919 :         } else if (key == "route") {
    2511         1614 :             std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
    2512         1394 :             if (value == "train" || value == "subway" || value == "light_rail" || value == "monorail" || value == "tram" || value == "bus"
    2513         1917 :                     || value == "trolleybus" || value == "aerialway" || value == "ferry" || value == "share_taxi" || value == "minibus") {
    2514         1344 :                 myPTRouteType = value;
    2515              :             }
    2516              : 
    2517        32305 :         } else if (key == "name") {
    2518         5594 :             myName = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
    2519        29508 :         } else if (key == "colour") {
    2520         1788 :             std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
    2521              :             try {
    2522         1787 :                 myRouteColor = RGBColor::parseColor(value);
    2523            1 :             } catch (...) {
    2524            3 :                 WRITE_WARNINGF(TL("Invalid color value '%' in relation %"), value, myCurrentRelation);
    2525            1 :             }
    2526        28614 :         } else if (key == "ref") {
    2527         3958 :             myRef = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
    2528        26635 :         } else if (key == "interval" || key == "headway") {
    2529          493 :             myInterval = attrs.get<int>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
    2530        26142 :         } else if (key == "by_night") {
    2531          170 :             myNightService = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
    2532              :         }
    2533              :     }
    2534              : }
    2535              : 
    2536              : 
    2537              : bool
    2538          937 : NIImporter_OpenStreetMap::RelationHandler::checkEdgeRef(long long int ref) const {
    2539         1874 :     if (myOSMEdges.find(ref) != myOSMEdges.end()) {
    2540              :         return true;
    2541              :     }
    2542          436 :     WRITE_WARNINGF(TL("No way found for reference '%' in relation '%'"), toString(ref), toString(myCurrentRelation));
    2543          218 :     return false;
    2544              : }
    2545              : 
    2546              : 
    2547              : void
    2548       453638 : NIImporter_OpenStreetMap::RelationHandler::myEndElement(int element) {
    2549       453638 :     if (element == SUMO_TAG_RELATION) {
    2550         4639 :         if (myIsRestriction) {
    2551              :             assert(myCurrentRelation != INVALID_ID);
    2552              :             bool ok = true;
    2553          374 :             if (myRestrictionType == RestrictionType::UNKNOWN) {
    2554            2 :                 WRITE_WARNINGF(TL("Ignoring restriction relation '%' with unknown type."), toString(myCurrentRelation));
    2555              :                 ok = false;
    2556              :             }
    2557          374 :             if (myFromWay == INVALID_ID) {
    2558          112 :                 WRITE_WARNINGF(TL("Ignoring restriction relation '%' with unknown from-way."), toString(myCurrentRelation));
    2559              :                 ok = false;
    2560              :             }
    2561          374 :             if (myToWay == INVALID_ID) {
    2562          128 :                 WRITE_WARNINGF(TL("Ignoring restriction relation '%' with unknown to-way."), toString(myCurrentRelation));
    2563              :                 ok = false;
    2564              :             }
    2565          374 :             if (myViaNode == INVALID_ID && myViaWay == INVALID_ID) {
    2566           32 :                 WRITE_WARNINGF(TL("Ignoring restriction relation '%' with unknown via."), toString(myCurrentRelation));
    2567              :                 ok = false;
    2568              :             }
    2569          358 :             if (ok && !applyRestriction()) {
    2570           34 :                 WRITE_WARNINGF(TL("Ignoring restriction relation '%'."), toString(myCurrentRelation));
    2571              :             }
    2572         4265 :         } else if (myIsStopArea) {
    2573         1740 :             for (long long ref : myStops) {
    2574         1365 :                 myStopAreas[ref] = myCurrentRelation;
    2575         2730 :                 if (myOSMNodes.find(ref) == myOSMNodes.end()) {
    2576              :                     //WRITE_WARNING(
    2577              :                     //    "Referenced node: '" + toString(ref) + "' in relation: '" + toString(myCurrentRelation)
    2578              :                     //    + "' does not exist. Probably OSM file is incomplete.");
    2579          472 :                     continue;
    2580              :                 }
    2581              : 
    2582         1128 :                 NIOSMNode* n = myOSMNodes.find(ref)->second;
    2583         2256 :                 std::shared_ptr<NBPTStop> ptStop = myNBPTStopCont->get(toString(n->id));
    2584         1128 :                 if (ptStop == nullptr) {
    2585              :                     //WRITE_WARNING(
    2586              :                     //    "Relation '" + toString(myCurrentRelation) + "' refers to a non existing pt stop at node: '"
    2587              :                     //    + toString(n->id) + "'. Probably OSM file is incomplete.");
    2588              :                     continue;
    2589              :                 }
    2590         2131 :                 for (NIIPTPlatform& myPlatform : myPlatforms) {
    2591         1238 :                     if (myPlatform.isWay) {
    2592              :                         assert(myPlatformShapes.find(myPlatform.ref) != myPlatformShapes.end()); //already tested earlier
    2593         1902 :                         Edge* edge = (*myPlatformShapes.find(myPlatform.ref)).second;
    2594          951 :                         if (edge->myCurrentNodes.size() > 1 && edge->myCurrentNodes[0] == *(edge->myCurrentNodes.end() - 1)) {
    2595           88 :                             WRITE_WARNINGF(TL("Platform '%' in relation: '%' is given as polygon, which currently is not supported."), myPlatform.ref, myCurrentRelation);
    2596           93 :                             continue;
    2597              : 
    2598              :                         }
    2599          863 :                         PositionVector p;
    2600         2933 :                         for (auto nodeRef : edge->myCurrentNodes) {
    2601         4140 :                             if (myOSMNodes.find(nodeRef) == myOSMNodes.end()) {
    2602              :                                 //WRITE_WARNING(
    2603              :                                 //    "Referenced node: '" + toString(ref) + "' in relation: '" + toString(myCurrentRelation)
    2604              :                                 //    + "' does not exist. Probably OSM file is incomplete.");
    2605            0 :                                 continue;
    2606              :                             }
    2607         2070 :                             NIOSMNode* pNode = myOSMNodes.find(nodeRef)->second;
    2608         2070 :                             Position pNodePos(pNode->lon, pNode->lat, pNode->ele);
    2609         2070 :                             if (!NBNetBuilder::transformCoordinate(pNodePos)) {
    2610            0 :                                 WRITE_ERRORF("Unable to project coordinates for node '%'.", pNode->id);
    2611            0 :                                 continue;
    2612              :                             }
    2613         2070 :                             p.push_back(pNodePos);
    2614              :                         }
    2615          863 :                         if (p.size() == 0) {
    2616           10 :                             WRITE_WARNINGF(TL("Referenced platform: '%' in relation: '%' is corrupt. Probably OSM file is incomplete."),
    2617              :                                            toString(myPlatform.ref), toString(myCurrentRelation));
    2618              :                             continue;
    2619              :                         }
    2620          858 :                         NBPTPlatform platform(p[(int)p.size() / 2], p.length());
    2621          858 :                         ptStop->addPlatformCand(platform);
    2622          863 :                     } else {
    2623          574 :                         if (myOSMNodes.find(myPlatform.ref) == myOSMNodes.end()) {
    2624              :                             //WRITE_WARNING(
    2625              :                             //    "Referenced node: '" + toString(ref) + "' in relation: '" + toString(myCurrentRelation)
    2626              :                             //    + "' does not exist. Probably OSM file is incomplete.");
    2627           83 :                             continue;
    2628              :                         }
    2629          204 :                         NIOSMNode* pNode = myOSMNodes.find(myPlatform.ref)->second;
    2630          204 :                         Position platformPos(pNode->lon, pNode->lat, pNode->ele);
    2631          204 :                         if (!NBNetBuilder::transformCoordinate(platformPos)) {
    2632            0 :                             WRITE_ERRORF("Unable to project coordinates for node '%'.", pNode->id);
    2633              :                         }
    2634          408 :                         NBPTPlatform platform(platformPos, myOptionsCont.getFloat("osm.stop-output.length"));
    2635          204 :                         ptStop->addPlatformCand(platform);
    2636              : 
    2637              :                     }
    2638              :                 }
    2639          893 :                 ptStop->setIsMultipleStopPositions(myStops.size() > 1, myCurrentRelation);
    2640          893 :                 if (myStation != INVALID_ID) {
    2641           48 :                     const auto& nodeIt = myOSMNodes.find(myStation);
    2642           48 :                     if (nodeIt != myOSMNodes.end()) {
    2643           44 :                         NIOSMNode* station = nodeIt->second;
    2644           44 :                         if (station != nullptr) {
    2645           88 :                             if (station->hasParameter("railway:ref")) {
    2646          126 :                                 ptStop->setParameter("stationRef", station->getParameter("railway:ref"));
    2647              :                             }
    2648              :                         }
    2649              :                     }
    2650              :                 }
    2651              :             }
    2652         3890 :         } else if (myPTRouteType != "" && myIsRoute) {
    2653         1340 :             NBPTLine* ptLine = new NBPTLine(toString(myCurrentRelation), myName, myPTRouteType, myRef, myInterval, myNightService,
    2654         1340 :                                             interpretTransportType(myPTRouteType), myRouteColor);
    2655              :             bool hadGap = false;
    2656              :             int missingBefore = 0;
    2657              :             int missingAfter = 0;
    2658        35848 :             for (long long ref : myStops) {
    2659        34571 :                 const auto& nodeIt = myOSMNodes.find(ref);
    2660        34571 :                 if (nodeIt == myOSMNodes.end()) {
    2661        31526 :                     if (ptLine->getStops().empty()) {
    2662        17206 :                         missingBefore++;
    2663              :                     } else {
    2664        14320 :                         missingAfter++;
    2665              :                         if (!hadGap) {
    2666              :                             hadGap = true;
    2667              :                         }
    2668              :                     }
    2669        31526 :                     continue;
    2670              :                 }
    2671         3045 :                 if (hadGap) {
    2672          126 :                     WRITE_WARNINGF(TL("PT line '%' in relation % seems to be split, only keeping first part."), myName, myCurrentRelation);
    2673           63 :                     missingAfter = (int)myStops.size() - missingBefore - (int)ptLine->getStops().size();
    2674           63 :                     break;
    2675              :                 }
    2676              : 
    2677         2982 :                 const NIOSMNode* const n = nodeIt->second;
    2678         5964 :                 std::shared_ptr<NBPTStop> ptStop = myNBPTStopCont->get(toString(n->id));
    2679         2982 :                 if (ptStop == nullptr) {
    2680              :                     // loose stop, which must later be mapped onto a line way
    2681          134 :                     Position ptPos(n->lon, n->lat, n->ele);
    2682          134 :                     if (!NBNetBuilder::transformCoordinate(ptPos)) {
    2683            0 :                         WRITE_ERRORF("Unable to project coordinates for node '%'.", n->id);
    2684              :                     }
    2685          134 :                     ptStop = std::make_shared<NBPTStop>(toString(n->id), ptPos, "", "", n->ptStopLength, n->name, n->permissions);
    2686          268 :                     myNBPTStopCont->insert(ptStop);
    2687              :                     if (myStopAreas.count(n->id)) {
    2688           11 :                         ptStop->setIsMultipleStopPositions(false, myStopAreas[n->id]);
    2689              :                     }
    2690              :                     if (myPlatformStops.count(n->id) > 0) {
    2691              :                         ptStop->setIsPlatform();
    2692              :                     }
    2693              :                 }
    2694         5964 :                 ptLine->addPTStop(ptStop);
    2695              :             }
    2696       208632 :             for (long long& myWay : myWays) {
    2697       207292 :                 auto entr = myOSMEdges.find(myWay);
    2698       207292 :                 if (entr != myOSMEdges.end()) {
    2699        14026 :                     Edge* edge = entr->second;
    2700       103545 :                     for (long long& myCurrentNode : edge->myCurrentNodes) {
    2701        89519 :                         ptLine->addWayNode(myWay, myCurrentNode);
    2702              :                     }
    2703              :                 }
    2704              :             }
    2705         1340 :             ptLine->setNumOfStops((int)myStops.size(), missingBefore, missingAfter);
    2706         1340 :             if (ptLine->getStops().empty()) {
    2707          219 :                 WRITE_WARNINGF(TL("PT line in relation % with no stops ignored. Probably OSM file is incomplete."), myCurrentRelation);
    2708          219 :                 delete ptLine;
    2709          219 :                 resetValues();
    2710          219 :                 return;
    2711              :             }
    2712         1121 :             if (!myNBPTLineCont->insert(ptLine)) {
    2713            6 :                 WRITE_WARNINGF(TL("Ignoring duplicate PT line '%'."), myCurrentRelation);
    2714            6 :                 delete ptLine;
    2715              :             }
    2716              :         }
    2717              :         // other relations might use similar subelements so reset in any case
    2718         4420 :         resetValues();
    2719              :     }
    2720              : }
    2721              : 
    2722              : bool
    2723          284 : NIImporter_OpenStreetMap::RelationHandler::applyRestriction() const {
    2724              :     // since OSM ways are bidirectional we need the via to figure out which direction was meant
    2725          284 :     if (myViaNode != INVALID_ID) {
    2726          274 :         NBNode* viaNode = myOSMNodes.find(myViaNode)->second->node;
    2727          274 :         if (viaNode == nullptr) {
    2728            0 :             WRITE_WARNINGF(TL("Via-node '%' was not instantiated"), toString(myViaNode));
    2729            0 :             return false;
    2730              :         }
    2731          274 :         NBEdge* from = findEdgeRef(myFromWay, viaNode->getIncomingEdges());
    2732          274 :         NBEdge* to = findEdgeRef(myToWay, viaNode->getOutgoingEdges());
    2733          274 :         if (from == nullptr) {
    2734            6 :             WRITE_WARNINGF(TL("from-edge '%' of restriction relation could not be determined"), toString(myFromWay));
    2735            3 :             return false;
    2736              :         }
    2737          271 :         if (to == nullptr) {
    2738            8 :             WRITE_WARNINGF(TL("to-edge '%' of restriction relation could not be determined"), toString(myToWay));
    2739            4 :             return false;
    2740              :         }
    2741          267 :         if (myRestrictionType == RestrictionType::ONLY) {
    2742          156 :             from->addEdge2EdgeConnection(to, true);
    2743              :             // make sure that these connections remain disabled even if network
    2744              :             // modifications (ramps.guess) reset existing connections
    2745          528 :             for (NBEdge* cand : from->getToNode()->getOutgoingEdges()) {
    2746          372 :                 if (!from->isConnectedTo(cand)) {
    2747          214 :                     if (myRestrictionException == SVC_IGNORING) {
    2748          201 :                         from->removeFromConnections(cand, -1, -1, true);
    2749              :                     } else {
    2750           13 :                         from->addEdge2EdgeConnection(cand, true, myRestrictionException);
    2751              :                     }
    2752              :                 }
    2753              :             }
    2754              :         } else {
    2755          111 :             if (myRestrictionException == SVC_IGNORING) {
    2756          107 :                 from->removeFromConnections(to, -1, -1, true);
    2757              :             } else {
    2758            4 :                 from->addEdge2EdgeConnection(to, true, myRestrictionException);
    2759           18 :                 for (NBEdge* cand : from->getToNode()->getOutgoingEdges()) {
    2760           14 :                     if (!from->isConnectedTo(cand)) {
    2761           10 :                         from->addEdge2EdgeConnection(cand, true);
    2762              :                     }
    2763              :                 }
    2764              :             }
    2765              :         }
    2766              :     } else {
    2767              :         // XXX interpreting via-ways or via-node lists not yet implemented
    2768           10 :         WRITE_WARNINGF(TL("direction of restriction relation could not be determined%"), "");
    2769           10 :         return false;
    2770              :     }
    2771              :     return true;
    2772              : }
    2773              : 
    2774              : NBEdge*
    2775          548 : NIImporter_OpenStreetMap::RelationHandler::findEdgeRef(long long int wayRef,
    2776              :         const std::vector<NBEdge*>& candidates) const {
    2777          548 :     const std::string prefix = toString(wayRef);
    2778          548 :     const std::string backPrefix = "-" + prefix;
    2779              :     NBEdge* result = nullptr;
    2780              :     int found = 0;
    2781         1979 :     for (auto candidate : candidates) {
    2782         2862 :         if ((candidate->getID().substr(0, prefix.size()) == prefix) ||
    2783         2430 :                 (candidate->getID().substr(0, backPrefix.size()) == backPrefix)) {
    2784              :             result = candidate;
    2785          540 :             found++;
    2786              :         }
    2787              :     }
    2788          548 :     if (found > 1) {
    2789            0 :         WRITE_WARNINGF(TL("Ambiguous way reference '%' in restriction relation"), prefix);
    2790              :         result = nullptr;
    2791              :     }
    2792          548 :     return result;
    2793              : }
    2794              : 
    2795              : 
    2796              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1