SUMO - Simulation of Urban MObility
NIImporter_OpenStreetMap.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // Importer for networks stored in OpenStreetMap format
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 #include <algorithm>
28 #include <set>
29 #include <functional>
30 #include <sstream>
31 #include <limits>
35 #include <utils/common/ToString.h>
39 #include <netbuild/NBEdge.h>
40 #include <netbuild/NBEdgeCont.h>
41 #include <netbuild/NBNode.h>
42 #include <netbuild/NBNodeCont.h>
43 #include <netbuild/NBNetBuilder.h>
44 #include <netbuild/NBOwnTLDef.h>
50 #include <utils/xml/XMLSubSys.h>
51 #include <netbuild/NBPTLine.h>
52 #include <netbuild/NBPTLineCont.h>
53 #include "NILoader.h"
55 
56 //#define DEBUG_LAYER_ELEVATION
57 
58 // ---------------------------------------------------------------------------
59 // static members
60 // ---------------------------------------------------------------------------
62 
63 const long long int NIImporter_OpenStreetMap::INVALID_ID = std::numeric_limits<long long int>::max();
64 
65 // ===========================================================================
66 // Private classes
67 // ===========================================================================
68 
72 public:
73  bool operator()(const Edge* e1, const Edge* e2) const {
74  if (e1->myHighWayType != e2->myHighWayType) {
75  return e1->myHighWayType > e2->myHighWayType;
76  }
77  if (e1->myNoLanes != e2->myNoLanes) {
78  return e1->myNoLanes > e2->myNoLanes;
79  }
80  if (e1->myNoLanesForward != e2->myNoLanesForward) {
81  return e1->myNoLanesForward > e2->myNoLanesForward;
82  }
83  if (e1->myMaxSpeed != e2->myMaxSpeed) {
84  return e1->myMaxSpeed > e2->myMaxSpeed;
85  }
86  if (e1->myIsOneWay != e2->myIsOneWay) {
87  return e1->myIsOneWay > e2->myIsOneWay;
88  }
89  return e1->myCurrentNodes > e2->myCurrentNodes;
90  }
91 };
92 
93 // ===========================================================================
94 // method definitions
95 // ===========================================================================
96 // ---------------------------------------------------------------------------
97 // static methods
98 // ---------------------------------------------------------------------------
99 const std::string NIImporter_OpenStreetMap::compoundTypeSeparator("|"); //clang-tidy says: "compundTypeSeparator with
100 // static storage duration my throw an exception that cannot be caught
101 
102 void
104  NIImporter_OpenStreetMap importer;
105  importer.load(oc, nb);
106 }
107 
109 
111  // delete nodes
112  for (auto myUniqueNode : myUniqueNodes) {
113  delete myUniqueNode;
114  }
115  // delete edges
116  for (auto& myEdge : myEdges) {
117  delete myEdge.second;
118  }
119  // delete platform shapes
120  for (auto& myPlatformShape : myPlatformShapes) {
121  delete myPlatformShape.second;
122  }
123 }
124 
125 void
127  // check whether the option is set (properly)
128  if (!oc.isSet("osm-files")) {
129  return;
130  }
131  /* Parse file(s)
132  * Each file is parsed twice: first for nodes, second for edges. */
133  std::vector<std::string> files = oc.getStringVector("osm-files");
134  // load nodes, first
135  NodesHandler nodesHandler(myOSMNodes, myUniqueNodes, oc);
136  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
137  // nodes
138  if (!FileHelpers::isReadable(*file)) {
139  WRITE_ERROR("Could not open osm-file '" + *file + "'.");
140  return;
141  }
142  nodesHandler.setFileName(*file);
143  PROGRESS_BEGIN_MESSAGE("Parsing nodes from osm-file '" + *file + "'");
144  if (!XMLSubSys::runParser(nodesHandler, *file)) {
145  return;
146  }
148  }
149  // load edges, then
151  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
152  // edges
153  edgesHandler.setFileName(*file);
154  PROGRESS_BEGIN_MESSAGE("Parsing edges from osm-file '" + *file + "'");
155  XMLSubSys::runParser(edgesHandler, *file);
157  }
158 
159  /* Remove duplicate edges with the same shape and attributes */
160  if (!oc.getBool("osm.skip-duplicates-check")) {
161  PROGRESS_BEGIN_MESSAGE("Removing duplicate edges");
162  if (myEdges.size() > 1) {
163  std::set<const Edge*, CompareEdges> dupsFinder;
164  for (auto it = myEdges.begin(); it != myEdges.end();) {
165  if (dupsFinder.count(it->second) > 0) {
166  WRITE_MESSAGE("Found duplicate edges. Removing " + toString(it->first));
167  delete it->second;
168  myEdges.erase(it++);
169  } else {
170  dupsFinder.insert(it->second);
171  it++;
172  }
173  }
174  }
176  }
177 
178  /* Mark which nodes are used (by edges or traffic lights).
179  * This is necessary to detect which OpenStreetMap nodes are for
180  * geometry only */
181  std::map<long long int, int> nodeUsage;
182  // Mark which nodes are used by edges (begin and end)
183  for (std::map<long long int, Edge*>::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
184  Edge* e = (*i).second;
185  assert(e->myCurrentIsRoad);
186  for (std::vector<long long int>::const_iterator j = e->myCurrentNodes.begin();
187  j != e->myCurrentNodes.end();
188  ++j) {
189  if (nodeUsage.find(*j) == nodeUsage.end()) {
190  nodeUsage[*j] = 0;
191  }
192  nodeUsage[*j] = nodeUsage[*j] + 1;
193  }
194  }
195  // Mark which nodes are used by traffic lights
196  for (std::map<long long int, NIOSMNode*>::const_iterator nodesIt = myOSMNodes.begin();
197  nodesIt != myOSMNodes.end();
198  ++nodesIt) {
199  if (nodesIt->second->tlsControlled || nodesIt->second->railwaySignal /* || nodesIt->second->railwayCrossing*/) {
200  // If the key is not found in the map, the value is automatically
201  // initialized with 0.
202  nodeUsage[nodesIt->first] += 1;
203  }
204  }
205 
206  /* Instantiate edges
207  * Only those nodes in the middle of an edge which are used by more than
208  * one edge are instantiated. Other nodes are considered as geometry nodes. */
209  NBNodeCont& nc = nb.getNodeCont();
211  for (auto& myEdge : myEdges) {
212  Edge* e = myEdge.second;
213  assert(e->myCurrentIsRoad);
214  if (e->myCurrentNodes.size() < 2) {
215  WRITE_WARNING("Discarding way '" + toString(e->id) + "' because it has only " +
216  toString(e->myCurrentNodes.size()) + " node(s)");
217  continue;
218  }
219  // build nodes;
220  // - the from- and to-nodes must be built in any case
221  // - the in-between nodes are only built if more than one edge references them
222  NBNode* currentFrom = insertNodeChecking(*e->myCurrentNodes.begin(), nc, tlsc);
223  NBNode* last = insertNodeChecking(*(e->myCurrentNodes.end() - 1), nc, tlsc);
224  int running = 0;
225  std::vector<long long int> passed;
226  for (auto j = e->myCurrentNodes.begin(); j != e->myCurrentNodes.end(); ++j) {
227  passed.push_back(*j);
228  if (nodeUsage[*j] > 1 && j != e->myCurrentNodes.end() - 1 && j != e->myCurrentNodes.begin()) {
229  NBNode* currentTo = insertNodeChecking(*j, nc, tlsc);
230  running = insertEdge(e, running, currentFrom, currentTo, passed, nb);
231  currentFrom = currentTo;
232  passed.clear();
233  passed.push_back(*j);
234  }
235  }
236  if (running == 0) {
237  running = -1;
238  }
239  insertEdge(e, running, currentFrom, last, passed, nb);
240  }
241 
242  const double layerElevation = oc.getFloat("osm.layer-elevation");
243  if (layerElevation > 0) {
244  reconstructLayerElevation(layerElevation, nb);
245  }
246 
247  //revise pt stops; remove stops on deleted edges
248  if (OptionsCont::getOptions().isSet("ptstop-output")) {
250  }
251 
252  // load relations (after edges are built since we want to apply
253  // turn-restrictions directly to NBEdges)
254  RelationHandler relationHandler(myOSMNodes, myEdges, &(nb.getPTStopCont()), myPlatformShapes,
255  &(nb.getPTLineCont()), oc);
256  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
257  // relations
258  relationHandler.setFileName(*file);
259  PROGRESS_BEGIN_MESSAGE("Parsing relations from osm-file '" + *file + "'");
260  XMLSubSys::runParser(relationHandler, *file);
262  }
263 }
264 
265 NBNode*
267  NBNode* node = nc.retrieve(toString(id));
268  if (node == nullptr) {
269  NIOSMNode* n = myOSMNodes.find(id)->second;
270  Position pos(n->lon, n->lat, n->ele);
271  if (!NBNetBuilder::transformCoordinate(pos, true)) {
272  WRITE_ERROR("Unable to project coordinates for junction '" + toString(id) + "'.");
273  return nullptr;
274  }
275  node = new NBNode(toString(id), pos);
276  if (!nc.insert(node)) {
277  WRITE_ERROR("Could not insert junction '" + toString(id) + "'.");
278  delete node;
279  return nullptr;
280  }
281  n->node = node;
282  if (n->railwayCrossing) {
283  node->reinit(pos, NODETYPE_RAIL_CROSSING);
284  } else if (n->railwaySignal) {
285  node->reinit(pos, NODETYPE_RAIL_SIGNAL);
286  } else if (n->tlsControlled) {
287  // ok, this node is a traffic light node where no other nodes
288  // participate
289  // @note: The OSM-community has not settled on a schema for differentiating between fixed and actuated lights
291  OptionsCont::getOptions().getString("tls.default-type"));
292  NBOwnTLDef* tlDef = new NBOwnTLDef(toString(id), node, 0, type);
293  if (!tlsc.insert(tlDef)) {
294  // actually, nothing should fail here
295  delete tlDef;
296  throw ProcessError("Could not allocate tls '" + toString(id) + "'.");
297  }
298  }
299  if (n->railwayBufferStop) {
300  node->setParameter("buffer_stop", "true");
301  }
302  }
303  return node;
304 }
305 
306 int
308  const std::vector<long long int>& passed, NBNetBuilder& nb) {
309  NBNodeCont& nc = nb.getNodeCont();
310  NBEdgeCont& ec = nb.getEdgeCont();
311  NBTypeCont& tc = nb.getTypeCont();
312  NBPTStopCont& sc = nb.getPTStopCont();
313 
315  // patch the id
316  std::string id = toString(e->id);
317  if (from == nullptr || to == nullptr) {
318  WRITE_ERROR("Discarding edge '" + id + "' because the nodes could not be built.");
319  return index;
320  }
321  if (index >= 0) {
322  id = id + "#" + toString(index);
323  } else {
324  index = 0;
325  }
326  if (from == to) {
327  assert(passed.size() >= 2);
328  if (passed.size() == 2) {
329  WRITE_WARNING("Discarding edge '" + id + "' which connects two identical nodes without geometry.");
330  return index;
331  }
332  // in the special case of a looped way split again using passed
333  int intermediateIndex = (int) passed.size() / 2;
334  NBNode* intermediate = insertNodeChecking(passed[intermediateIndex], nc, tlsc);
335  std::vector<long long int> part1(passed.begin(), passed.begin() + intermediateIndex + 1);
336  std::vector<long long int> part2(passed.begin() + intermediateIndex, passed.end());
337  index = insertEdge(e, index, from, intermediate, part1, nb);
338  return insertEdge(e, index, intermediate, to, part2, nb);
339  }
340  const int newIndex = index + 1;
341 
342  // convert the shape
343  PositionVector shape;
344  for (long long i : passed) {
345  NIOSMNode* n = myOSMNodes.find(i)->second;
346 
347  if (n->ptStopPosition) {
348  NBPTStop* existingPtStop = sc.get(toString(n->id));
349  if (existingPtStop != nullptr) {
350  existingPtStop->registerAdditionalEdge(toString(e->id), id);
351  } else {
352  Position ptPos(n->lon, n->lat, n->ele);
353  if (!NBNetBuilder::transformCoordinate(ptPos)) {
354  WRITE_ERROR("Unable to project coordinates for node '" + toString(n->id) + "'.");
355  }
356  NBPTStop* ptStop = new NBPTStop(toString(n->id), ptPos, id, toString(e->id), n->ptStopLength, n->name,
357  n->permissions);
358 
359  sc.insert(ptStop);
360  }
361  }
362  Position pos(n->lon, n->lat, n->ele);
363  shape.push_back(pos);
364  }
366  WRITE_ERROR("Unable to project coordinates for edge '" + id + "'.");
367  }
368 // shape.in
369 
370  std::string type = e->myHighWayType;
371  if (!tc.knows(type)) {
372  if (myUnusableTypes.count(type) > 0) {
373  return newIndex;
374  }
375  if (myKnownCompoundTypes.count(type) > 0) {
376  type = myKnownCompoundTypes[type];
377  } else {
378  // this edge has a type which does not yet exist in the TypeContainer
380  std::vector<std::string> types;
381  while (tok.hasNext()) {
382  std::string t = tok.next();
383  if (tc.knows(t)) {
384  if (std::find(types.begin(), types.end(), t) == types.end()) {
385  types.push_back(t);
386  }
387  } else if (tok.size() > 1) {
389  "Discarding unknown compound '" + t + "' in type '" + type + "' (first occurence for edge '"
390  + id
391  + "').");
392  }
393  }
394  if (types.empty()) {
395  WRITE_WARNING("Discarding unusable type '" + type + "' (first occurence for edge '" + id + "').");
396  myUnusableTypes.insert(type);
397  return newIndex;
398  }
399 
400  const std::string newType = joinToString(types, "|");
401  if (tc.knows(newType)) {
402  myKnownCompoundTypes[type] = newType;
403  type = newType;
404  } else if (myKnownCompoundTypes.count(newType) > 0) {
405  type = myKnownCompoundTypes[newType];
406  } else {
407  // build a new type by merging all values
408  int numLanes = 0;
409  double maxSpeed = 0;
410  int prio = 0;
411  double width = NBEdge::UNSPECIFIED_WIDTH;
412  double sidewalkWidth = NBEdge::UNSPECIFIED_WIDTH;
413  double bikelaneWidth = NBEdge::UNSPECIFIED_WIDTH;
414  bool defaultIsOneWay = false;
415  SVCPermissions permissions = 0;
416  bool discard = true;
417  for (auto& type2 : types) {
418  if (!tc.getShallBeDiscarded(type2)) {
419  numLanes = MAX2(numLanes, tc.getNumLanes(type2));
420  maxSpeed = MAX2(maxSpeed, tc.getSpeed(type2));
421  prio = MAX2(prio, tc.getPriority(type2));
422  defaultIsOneWay &= tc.getIsOneWay(type2);
423  //std::cout << "merging component " << type2 << " into type " << newType << " allows=" << getVehicleClassNames(tc.getPermissions(type2)) << "\n";
424  permissions |= tc.getPermissions(type2);
425  width = MAX2(width, tc.getWidth(type2));
426  sidewalkWidth = MAX2(sidewalkWidth, tc.getSidewalkWidth(type2));
427  bikelaneWidth = MAX2(bikelaneWidth, tc.getBikeLaneWidth(type2));
428  discard = false;
429  }
430  }
431  if (width != NBEdge::UNSPECIFIED_WIDTH) {
432  width = MAX2(width, SUMO_const_laneWidth);
433  }
434  // ensure pedestrians don't run into trains
435  if (sidewalkWidth == NBEdge::UNSPECIFIED_WIDTH
436  && (permissions & SVC_PEDESTRIAN) != 0
437  && (permissions & SVC_RAIL_CLASSES) != 0) {
438  //std::cout << "patching sidewalk for type '" << newType << "' which allows=" << getVehicleClassNames(permissions) << "\n";
439  sidewalkWidth = OptionsCont::getOptions().getFloat("default.sidewalk-width");
440  }
441 
442  if (discard) {
444  "Discarding compound type '" + newType + "' (first occurence for edge '" + id + "').");
445  myUnusableTypes.insert(newType);
446  return newIndex;
447  }
448 
449  WRITE_MESSAGE("Adding new type '" + type + "' (first occurence for edge '" + id + "').");
450  tc.insert(newType, numLanes, maxSpeed, prio, permissions, width, defaultIsOneWay, sidewalkWidth,
451  bikelaneWidth);
452  for (auto& type3 : types) {
453  if (!tc.getShallBeDiscarded(type3)) {
454  tc.copyRestrictionsAndAttrs(type3, newType);
455  }
456  }
457  myKnownCompoundTypes[type] = newType;
458  type = newType;
459 
460  }
461 
462  }
463  }
464 
465  // otherwise it is not an edge and will be ignored
466  bool ok = true;
467  int numLanesForward = tc.getNumLanes(type);
468  int numLanesBackward = tc.getNumLanes(type);
469  double speed = tc.getSpeed(type);
470  bool defaultsToOneWay = tc.getIsOneWay(type);
471  SVCPermissions forwardPermissions = tc.getPermissions(type);
472  SVCPermissions backwardPermissions = tc.getPermissions(type);
473  double forwardWidth = tc.getWidth(type);
474  double backwardWidth = tc.getWidth(type);
475  const bool addSidewalk = (tc.getSidewalkWidth(type) != NBEdge::UNSPECIFIED_WIDTH);
476  const bool addBikeLane = (tc.getBikeLaneWidth(type) != NBEdge::UNSPECIFIED_WIDTH);
477  // check directions
478  bool addForward = true;
479  bool addBackward = true;
480  if (e->myIsOneWay == "true" || e->myIsOneWay == "yes" || e->myIsOneWay == "1"
481  || (defaultsToOneWay && e->myIsOneWay != "no" && e->myIsOneWay != "false" && e->myIsOneWay != "0" &&
482  e->getParameter("railway:preferred_direction", "") != "both")) {
483  addBackward = false;
484  }
485  if (e->myIsOneWay == "-1" || e->myIsOneWay == "reverse") {
486  // one-way in reversed direction of way
487  addForward = false;
488  addBackward = true;
489  }
490  if (!e->myIsOneWay.empty() && e->myIsOneWay != "false" && e->myIsOneWay != "no" && e->myIsOneWay != "true"
491  && e->myIsOneWay != "yes" && e->myIsOneWay != "-1" && e->myIsOneWay != "1" && e->myIsOneWay != "reverse") {
492  WRITE_WARNING("New value for oneway found: " + e->myIsOneWay);
493  }
494  // if we had been able to extract the number of lanes, override the highway type default
495  if (e->myNoLanes > 0) {
496  if (addForward && !addBackward) {
497  numLanesForward = e->myNoLanes;
498  } else if (!addForward && addBackward) {
499  numLanesBackward = e->myNoLanes;
500  } else {
501  if (e->myNoLanesForward > 0) {
502  numLanesForward = e->myNoLanesForward;
503  } else if (e->myNoLanesForward < 0) {
504  numLanesForward = e->myNoLanes + e->myNoLanesForward;
505  } else {
506  numLanesForward = (int) std::ceil(e->myNoLanes / 2.0);
507  }
508  numLanesBackward = e->myNoLanes - numLanesForward;
509  // sometimes ways are tagged according to their physical width of a single
510  // lane but they are intended for traffic in both directions
511  numLanesForward = MAX2(1, numLanesForward);
512  numLanesBackward = MAX2(1, numLanesBackward);
513  }
514  } else if (e->myNoLanes == 0) {
515  WRITE_WARNING("Skipping edge '" + id + "' because it has zero lanes.");
516  ok = false;
517  }
518  // if we had been able to extract the maximum speed, override the type's default
519  if (e->myMaxSpeed != MAXSPEED_UNGIVEN) {
520  speed = (double)(e->myMaxSpeed / 3.6);
521  }
522  if (speed <= 0) {
523  WRITE_WARNING("Skipping edge '" + id + "' because it has speed " + toString(speed));
524  ok = false;
525  }
526  // deal with cycleways that run in the opposite direction of a one-way street
527  WayType cyclewayType = e->myCyclewayType; // make a copy because we do some temporary modifications
528  if (addBikeLane) {
529  if (!addForward && (cyclewayType & WAY_FORWARD) != 0) {
530  addForward = true;
531  forwardPermissions = SVC_BICYCLE;
532  forwardWidth = tc.getBikeLaneWidth(type);
533  numLanesForward = 1;
534  // do not add an additional cycle lane
535  cyclewayType = (WayType)(cyclewayType & ~WAY_FORWARD); //clang tidy thinks "!WAY_FORWARD" is always false
536  }
537  if (!addBackward && (cyclewayType & WAY_BACKWARD) != 0) {
538  addBackward = true;
539  backwardPermissions = SVC_BICYCLE;
540  backwardWidth = tc.getBikeLaneWidth(type);
541  numLanesBackward = 1;
542  // do not add an additional cycle lane
543  cyclewayType = (WayType)(cyclewayType & ~WAY_BACKWARD); //clang tidy thinks "!WAY_BACKWARD" is always false
544  }
545  }
546  // deal with sidewalks that run in the opposite direction of a one-way street
547  WayType sidewalkType = e->mySidewalkType; // make a copy because we do some temporary modifications
548  if (addSidewalk) {
549  if (!addForward && (sidewalkType & WAY_FORWARD) != 0) {
550  addForward = true;
551  forwardPermissions = SVC_PEDESTRIAN;
552  forwardWidth = tc.getSidewalkWidth(type);
553  numLanesForward = 1;
554  // do not add an additional sidewalk
555  sidewalkType = (WayType)(sidewalkType & ~WAY_FORWARD); //clang tidy thinks "!WAY_FORWARD" is always false
556  }
557  if (!addBackward && (sidewalkType & WAY_BACKWARD) != 0) {
558  addBackward = true;
559  backwardPermissions = SVC_PEDESTRIAN;
560  backwardWidth = tc.getSidewalkWidth(type);
561  numLanesBackward = 1;
562  // do not add an additional cycle lane
563  sidewalkType = (WayType)(sidewalkType & ~WAY_BACKWARD); //clang tidy thinks "!WAY_BACKWARD" is always false
564  }
565  }
566  // deal with busways that run in the opposite direction of a one-way street
567  if (!addForward && (e->myBuswayType & WAY_FORWARD) != 0) {
568  addForward = true;
569  forwardPermissions = SVC_BUS;
570  numLanesForward = 1;
571  }
572  if (!addBackward && (e->myBuswayType & WAY_BACKWARD) != 0) {
573  addBackward = true;
574  backwardPermissions = SVC_BUS;
575  numLanesBackward = 1;
576  }
577 
578  const std::string origID = OptionsCont::getOptions().getBool("output.original-names") ? toString(e->id) : "";
579  if (ok) {
580  LaneSpreadFunction lsf = (addBackward || OptionsCont::getOptions().getBool("osm.oneway-spread-right")) &&
581  e->getParameter("railway:preferred_direction", "") != "both" ? LANESPREAD_RIGHT : LANESPREAD_CENTER;
582 
583  id = StringUtils::escapeXML(id);
584  const std::string reverseID = "-" + id;
585 
586  if (addForward) {
587  assert(numLanesForward > 0);
588  NBEdge* nbe = new NBEdge(id, from, to, type, speed, numLanesForward, tc.getPriority(type),
589  forwardWidth, NBEdge::UNSPECIFIED_OFFSET, shape,
590  StringUtils::escapeXML(e->streetName), origID, lsf, true);
591  nbe->setPermissions(forwardPermissions);
592  if ((e->myBuswayType & WAY_FORWARD) != 0) {
593  nbe->setPermissions(SVC_BUS, 0);
594  }
595  if (addBikeLane && (cyclewayType == WAY_UNKNOWN || (cyclewayType & WAY_FORWARD) != 0)) {
596  nbe->addBikeLane(tc.getBikeLaneWidth(type));
597  } else if (nbe->getPermissions(0) == SVC_BUS) {
598  // bikes drive on buslanes if no separate cycle lane is available
600  }
601  if (addSidewalk && (sidewalkType == WAY_UNKNOWN || (sidewalkType & WAY_FORWARD) != 0)) {
602  nbe->addSidewalk(tc.getSidewalkWidth(type));
603  }
605  if (!ec.insert(nbe)) {
606  delete nbe;
607  throw ProcessError("Could not add edge '" + id + "'.");
608  }
609  }
610  if (addBackward) {
611  assert(numLanesBackward > 0);
612  NBEdge* nbe = new NBEdge(reverseID, to, from, type, speed, numLanesBackward, tc.getPriority(type),
613  backwardWidth, NBEdge::UNSPECIFIED_OFFSET, shape.reverse(),
614  StringUtils::escapeXML(e->streetName), origID, lsf, true);
615  nbe->setPermissions(backwardPermissions);
616  if ((e->myBuswayType & WAY_BACKWARD) != 0) {
617  nbe->setPermissions(SVC_BUS, 0);
618  }
619  if (addBikeLane && (cyclewayType == WAY_UNKNOWN || (cyclewayType & WAY_BACKWARD) != 0)) {
620  nbe->addBikeLane(tc.getBikeLaneWidth(type));
621  } else if (nbe->getPermissions(0) == SVC_BUS) {
622  // bikes drive on buslanes if no separate cycle lane is available
624  }
625  if (addSidewalk && (sidewalkType == WAY_UNKNOWN || (sidewalkType & WAY_BACKWARD) != 0)) {
626  nbe->addSidewalk(tc.getSidewalkWidth(type));
627  }
629  if (!ec.insert(nbe)) {
630  delete nbe;
631  throw ProcessError("Could not add edge '-" + id + "'.");
632  }
633  }
634  if ((e->myParkingType & PARKING_BOTH) != 0 && OptionsCont::getOptions().isSet("parking-output")) {
635  if ((e->myParkingType & PARKING_RIGHT) != 0) {
636  if (addForward) {
637  nb.getParkingCont().push_back(NBParking(id, id));
638  } else {
640  if ((e->myParkingType & PARKING_LEFT) == 0 && !addBackward) {
642  nb.getParkingCont().push_back(NBParking(reverseID, reverseID));
643  }
644  }
645  }
646  if ((e->myParkingType & PARKING_LEFT) != 0) {
647  if (addBackward) {
648  nb.getParkingCont().push_back(NBParking(reverseID, reverseID));
649  } else {
651  if ((e->myParkingType & PARKING_RIGHT) == 0 && !addForward) {
653  nb.getParkingCont().push_back(NBParking(id, id));
654  }
655  }
656  }
657  }
658  }
659  return newIndex;
660 }
661 
662 // ---------------------------------------------------------------------------
663 // definitions of NIImporter_OpenStreetMap::NodesHandler-methods
664 // ---------------------------------------------------------------------------
665 NIImporter_OpenStreetMap::NodesHandler::NodesHandler(std::map<long long int, NIOSMNode*>& toFill,
666  std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
667  const OptionsCont& oc)
668 
669  :
670  SUMOSAXHandler("osm - file"),
671  myToFill(toFill),
672  myLastNodeID(-1),
673  myIsInValidNodeTag(false),
674  myHierarchyLevel(0),
675  myUniqueNodes(uniqueNodes),
676  myImportElevation(oc.getBool("osm.elevation")),
677  myOptionsCont(oc) {
678 }
679 
681 
682 void
685  if (element == SUMO_TAG_NODE) {
686  bool ok = true;
687  if (myHierarchyLevel != 2) {
688  WRITE_ERROR("Node element on wrong XML hierarchy level (id='" + toString(attrs.get<long
689  long
690  int>(SUMO_ATTR_ID,
691  nullptr, ok))
692  + "', level='" + toString(myHierarchyLevel) + "').");
693  return;
694  }
695  const long long int id = attrs.get<long long int>(SUMO_ATTR_ID, nullptr, ok);
696  const std::string action = attrs.hasAttribute("action") ? attrs.getStringSecure("action", "") : "";
697  if (action == "delete" || !ok) {
698  return;
699  }
700  myLastNodeID = -1;
701  if (myToFill.find(id) == myToFill.end()) {
702  myLastNodeID = id;
703  // assume we are loading multiple files...
704  // ... so we won't report duplicate nodes
705  bool ok2 = true;
706  double tlat, tlon;
707  std::istringstream lon(attrs.get<std::string>(SUMO_ATTR_LON, toString(id).c_str(), ok2));
708  if (!ok2) {
709  return;
710  }
711  lon >> tlon;
712  if (lon.fail()) {
713  WRITE_ERROR("Node's '" + toString(id) + "' lon information is not numeric.");
714  return;
715  }
716  std::istringstream lat(attrs.get<std::string>(SUMO_ATTR_LAT, toString(id).c_str(), ok2));
717  if (!ok2) {
718  return;
719  }
720  lat >> tlat;
721  if (lat.fail()) {
722  WRITE_ERROR("Node's '" + toString(id) + "' lat information is not numeric.");
723  return;
724  }
725  auto* toAdd = new NIOSMNode(id, tlon, tlat);
726  myIsInValidNodeTag = true;
727 
728  auto similarNode = myUniqueNodes.find(toAdd);
729  if (similarNode == myUniqueNodes.end()) {
730  myUniqueNodes.insert(toAdd);
731  } else {
732  delete toAdd;
733  toAdd = *similarNode;
734  WRITE_MESSAGE("Found duplicate nodes. Substituting " + toString(id) + " with " + toString(toAdd->id));
735  }
736  myToFill[id] = toAdd;
737  }
738  }
739  if (element == SUMO_TAG_TAG && myIsInValidNodeTag) {
740  if (myHierarchyLevel != 3) {
741  WRITE_ERROR("Tag element on wrong XML hierarchy level.");
742  return;
743  }
744  bool ok = true;
745  std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myLastNodeID).c_str(), ok, false);
746  // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
747  if (key == "highway" || key == "ele" || key == "crossing" || key == "railway" || key == "public_transport"
748  || key == "name" || key == "train" || key == "bus" || key == "tram" || key == "light_rail" || key == "subway" || key == "station" || key == "noexit"
749  || StringUtils::startsWith(key, "railway:signal")) {
750  std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myLastNodeID).c_str(), ok, false);
751  if (key == "highway" && value.find("traffic_signal") != std::string::npos) {
752  myToFill[myLastNodeID]->tlsControlled = true;
753  } else if (key == "crossing" && value.find("traffic_signals") != std::string::npos) {
754  myToFill[myLastNodeID]->tlsControlled = true;
755  } else if ((key == "noexit" && value == "yes")
756  || (key == "railway" && value == "buffer_stop")) {
757  myToFill[myLastNodeID]->railwayBufferStop = true;
758  } else if (key == "railway" && value.find("crossing") != std::string::npos) {
759  myToFill[myLastNodeID]->railwayCrossing = true;
760  } else if (StringUtils::startsWith(key, "railway:signal") && (
761  value == "block" || value == "entry" || value == "exit" || value == "intermediate")) {
762  myToFill[myLastNodeID]->railwaySignal = true;
763  } else if ((key == "public_transport" && value == "stop_position") ||
764  (key == "highway" && value == "bus_stop")) {
765  myToFill[myLastNodeID]->ptStopPosition = true;
766  if (myToFill[myLastNodeID]->ptStopLength == 0) {
767  // default length
768  myToFill[myLastNodeID]->ptStopLength = myOptionsCont.getFloat("osm.stop-output.length");
769  }
770  } else if (key == "name") {
771  myToFill[myLastNodeID]->name = value;
772  } else if (key == "train") {
773  myToFill[myLastNodeID]->permissions = SVC_RAIL;
774  myToFill[myLastNodeID]->ptStopLength = myOptionsCont.getFloat("osm.stop-output.length.train");
775  } else if (key == "subway" || key == "light_rail"
776  || (key == "station" && (value == "subway" || value == "light_rail"))) {
777  myToFill[myLastNodeID]->permissions = SVC_RAIL_URBAN;
778  myToFill[myLastNodeID]->ptStopLength = myOptionsCont.getFloat("osm.stop-output.length.train");
779  } else if (key == "bus") {
780  myToFill[myLastNodeID]->permissions = SVC_BUS;
781  myToFill[myLastNodeID]->ptStopLength = myOptionsCont.getFloat("osm.stop-output.length.bus");
782  } else if (key == "tram") {
783  myToFill[myLastNodeID]->permissions = SVC_TRAM;
784  myToFill[myLastNodeID]->ptStopLength = myOptionsCont.getFloat("osm.stop-output.length.tram");
785  } else if (myImportElevation && key == "ele") {
786  try {
788  } catch (...) {
789  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in node '" +
790  toString(myLastNodeID) + "'.");
791  }
792  }
793  }
794  }
795 }
796 
797 void
799  if (element == SUMO_TAG_NODE && myHierarchyLevel == 2) {
800  myLastNodeID = -1;
801  myIsInValidNodeTag = false;
802  }
804 }
805 
806 // ---------------------------------------------------------------------------
807 // definitions of NIImporter_OpenStreetMap::EdgesHandler-methods
808 // ---------------------------------------------------------------------------
810  const std::map<long long int, NIOSMNode*>& osmNodes,
811  std::map<long long int, Edge*>& toFill, std::map<long long int, Edge*>& platformShapes):
812  SUMOSAXHandler("osm - file"),
813  myOSMNodes(osmNodes),
814  myEdgeMap(toFill),
815  myPlatformShapesMap(platformShapes) {
816  mySpeedMap["signals"] = MAXSPEED_UNGIVEN;
817  mySpeedMap["none"] = 300.;
818  mySpeedMap["no"] = 300.;
819  mySpeedMap["walk"] = 5.;
820  mySpeedMap["DE:rural"] = 100.;
821  mySpeedMap["DE:urban"] = 50.;
822  mySpeedMap["DE:living_street"] = 10.;
823  myAllAttributes = OptionsCont::getOptions().getBool("osm.all-attributes");
824 
825 }
826 
828 
829 void
831  const SUMOSAXAttributes& attrs) {
832  myParentElements.push_back(element);
833  // parse "way" elements
834  if (element == SUMO_TAG_WAY) {
835  bool ok = true;
836  const long long int id = attrs.get<long long int>(SUMO_ATTR_ID, nullptr, ok);
837  std::string action = attrs.hasAttribute("action") ? attrs.getStringSecure("action", "") : "";
838  if (action == "delete" || !ok) {
839  myCurrentEdge = nullptr;
840  return;
841  }
842  myCurrentEdge = new Edge(id);
843  }
844  // parse "nd" (node) elements
845  if (element == SUMO_TAG_ND && myCurrentEdge != nullptr) {
846  bool ok = true;
847  long long int ref = attrs.get<long long int>(SUMO_ATTR_REF, nullptr, ok);
848  if (ok) {
849  auto node = myOSMNodes.find(ref);
850  if (node == myOSMNodes.end()) {
851  WRITE_WARNING("The referenced geometry information (ref='" + toString(ref) + "') is not known");
852  return;
853  }
854 
855  ref = node->second->id; // node may have been substituted
856  if (myCurrentEdge->myCurrentNodes.empty() ||
857  myCurrentEdge->myCurrentNodes.back() != ref) { // avoid consecutive duplicates
858  myCurrentEdge->myCurrentNodes.push_back(ref);
859  }
860 
861  }
862  }
863  // parse values
864  if (element == SUMO_TAG_TAG && myParentElements.size() > 2
865  && myParentElements[myParentElements.size() - 2] == SUMO_TAG_WAY) {
866  if (myCurrentEdge == nullptr) {
867  return;
868  }
869  bool ok = true;
870  std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myCurrentEdge->id).c_str(), ok, false);
871  if (key.size() > 8 && StringUtils::startsWith(key, "cycleway:")) {
872  // handle special cycleway keys
873  const std::string cyclewaySpec = key.substr(9);
874  key = "cycleway";
875  if (cyclewaySpec == "right") {
877  } else if (cyclewaySpec == "left") {
879  } else if (cyclewaySpec == "both") {
881  } else {
882  key = "ignore";
883  }
884  if ((myCurrentEdge->myCyclewayType & WAY_BOTH) != 0) {
885  // now we have some info on directionality
887  }
888  } else if (key.size() > 6 && StringUtils::startsWith(key, "busway:")) {
889  // handle special busway keys
890  const std::string buswaySpec = key.substr(7);
891  key = "busway";
892  if (buswaySpec == "right") {
894  } else if (buswaySpec == "left") {
896  } else if (buswaySpec == "both") {
898  } else {
899  key = "ignore";
900  }
901  }
902  if (myAllAttributes && (key == "bridge" || key == "tunnel")) {
903  myCurrentEdge->setParameter(key, "true"); // could be differentiated further if necessary
904  }
905  // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
906  if (!StringUtils::endsWith(key, "way") && !StringUtils::startsWith(key, "lanes")
907  && key != "maxspeed" && key != "junction" && key != "name" && key != "tracks" && key != "layer"
908  && key != "route"
909  && key != "sidewalk"
910  && !StringUtils::startsWith(key, "parking")
911  && key != "postal_code" && key != "railway:preferred_direction" && key != "public_transport") {
912  return;
913  }
914  std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentEdge->id).c_str(), ok, false);
915 
916  if ((key == "highway" && value != "platform") || key == "railway" || key == "waterway" || key == "cycleway"
917  || key == "busway" || key == "route" || key == "sidewalk") {
919  // special cycleway stuff
920  if (key == "cycleway") {
921  if (value == "no") {
922  return;
923  }
924  if (value == "opposite_track") {
926  } else if (value == "opposite_lane") {
928  }
929  }
930  // special sidewalk stuff
931  if (key == "sidewalk") {
932  if (value == "no" || value == "none") {
934  } else if (value == "both") {
936  } else if (value == "right") {
938  } else if (value == "left") {
940  }
941  // no need to extend the type id
942  return;
943  }
944  // special busway stuff
945  if (key == "busway") {
946  if (value == "no") {
947  return;
948  }
949  if (value == "opposite_track") {
951  } else if (value == "opposite_lane") {
953  }
954  // no need to extend the type id
955  return;
956  }
957  // build type id
958  const std::string singleTypeID = key + "." + value;
959  if (!myCurrentEdge->myHighWayType.empty()) {
960  // osm-ways may be used by more than one mode (eg railway.tram + highway.residential. this is relevant for multimodal traffic)
961  // we create a new type for this kind of situation which must then be resolved in insertEdge()
962  std::vector<std::string> types = StringTokenizer(myCurrentEdge->myHighWayType,
964  types.push_back(singleTypeID);
966  } else {
967  myCurrentEdge->myHighWayType = singleTypeID;
968  }
969  } else if (key == "lanes") {
970  try {
972  } catch (NumberFormatException&) {
973  // might be a list of values
974  StringTokenizer st(value, ";", true);
975  std::vector<std::string> list = st.getVector();
976  if (list.size() >= 2) {
977  int minLanes = std::numeric_limits<int>::max();
978  try {
979  for (auto& i : list) {
980  int numLanes = StringUtils::toInt(StringUtils::prune(i));
981  minLanes = MIN2(minLanes, numLanes);
982  }
983  myCurrentEdge->myNoLanes = minLanes;
985  "Using minimum lane number from list (" + value + ") for edge '"
987  + "'.");
988  } catch (NumberFormatException&) {
989  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
990  toString(myCurrentEdge->id) + "'.");
991  }
992  }
993  } catch (EmptyData&) {
994  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
995  toString(myCurrentEdge->id) + "'.");
996  }
997  } else if (key == "lanes:forward") {
998  try {
1000  } catch (...) {
1001  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
1002  toString(myCurrentEdge->id) + "'.");
1003  }
1004  } else if (key == "lanes:backward") {
1005  try {
1006  // denote backwards count with a negative sign
1008  } catch (...) {
1009  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
1010  toString(myCurrentEdge->id) + "'.");
1011  }
1012  } else if (key == "maxspeed") {
1013  if (mySpeedMap.find(value) != mySpeedMap.end()) {
1015  } else {
1016  double conversion = 1; // OSM default is km/h
1017  if (StringUtils::to_lower_case(value).find("km/h") != std::string::npos) {
1018  value = StringUtils::prune(value.substr(0, value.find_first_not_of("0123456789")));
1019  } else if (StringUtils::to_lower_case(value).find("mph") != std::string::npos) {
1020  value = StringUtils::prune(value.substr(0, value.find_first_not_of("0123456789")));
1021  conversion = 1.609344; // kilometers per mile
1022  }
1023  try {
1024  myCurrentEdge->myMaxSpeed = StringUtils::toDouble(value) * conversion;
1025  } catch (...) {
1026  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
1027  toString(myCurrentEdge->id) + "'.");
1028  }
1029  }
1030  } else if (key == "junction") {
1031  if ((value == "roundabout") && (myCurrentEdge->myIsOneWay.empty())) {
1032  myCurrentEdge->myIsOneWay = "yes";
1033  }
1034  } else if (key == "oneway") {
1035  myCurrentEdge->myIsOneWay = value;
1036  } else if (key == "name") {
1037  myCurrentEdge->streetName = value;
1038  } else if (key == "layer") {
1039  if (myAllAttributes) {
1040  myCurrentEdge->setParameter(key, value);
1041  }
1042  try {
1044  } catch (...) {
1045  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
1046  toString(myCurrentEdge->id) + "'.");
1047  }
1048  } else if (key == "tracks") {
1049  try {
1050  if (StringUtils::toInt(value) > 1) {
1051  myCurrentEdge->myIsOneWay = "false";
1052  } else {
1053  myCurrentEdge->myIsOneWay = "true";
1054  }
1055  } catch (...) {
1056  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
1057  toString(myCurrentEdge->id) + "'.");
1058  }
1059  } else if (myAllAttributes && key == "postal_code") {
1060  myCurrentEdge->setParameter(key, value);
1061  } else if (key == "railway:preferred_direction") {
1062  // this param is special because it influences network building (duplicate rail edges)
1063  myCurrentEdge->setParameter(key, value);
1064  } else if (key == "public_transport" && value == "platform") {
1066  } else if (key == "parking:lane:both" && !StringUtils::startsWith(value, "no")) {
1068  } else if (key == "parking:lane:left" && !StringUtils::startsWith(value, "no")) {
1070  } else if (key == "parking:lane:right" && !StringUtils::startsWith(value, "no")) {
1072  }
1073  }
1074 }
1075 
1076 void
1078  myParentElements.pop_back();
1079  if (element == SUMO_TAG_WAY && myCurrentEdge != nullptr) {
1082  } else if (myCurrentEdge->myCurrentIsPlatform) {
1084  } else {
1085  delete myCurrentEdge;
1086  }
1087  myCurrentEdge = nullptr;
1088  }
1089 }
1090 
1091 // ---------------------------------------------------------------------------
1092 // definitions of NIImporter_OpenStreetMap::RelationHandler-methods
1093 // ---------------------------------------------------------------------------
1095  const std::map<long long int, NIOSMNode*>& osmNodes,
1096  const std::map<long long int, Edge*>& osmEdges, NBPTStopCont* nbptStopCont,
1097  const std::map<long long int, Edge*>& platformShapes,
1098  NBPTLineCont* nbptLineCont,
1099  const OptionsCont& oc)
1100  :
1101  SUMOSAXHandler("osm - file"),
1102  myOSMNodes(osmNodes),
1103  myOSMEdges(osmEdges),
1104  myPlatformShapes(platformShapes),
1105  myNBPTStopCont(nbptStopCont),
1106  myNBPTLineCont(nbptLineCont),
1107  myOptionsCont(oc) {
1108  resetValues();
1109 }
1110 
1112 
1113 void
1116  myIsRestriction = false;
1118  myToWay = INVALID_ID;
1120  myViaWay = INVALID_ID;
1122  myPlatforms.clear();
1123  myStops.clear();
1124  myWays.clear();
1125  myIsStopArea = false;
1126  myIsRoute = false;
1127  myPTRouteType = "";
1128 }
1129 
1130 void
1132  const SUMOSAXAttributes& attrs) {
1133  myParentElements.push_back(element);
1134  // parse "way" elements
1135  if (element == SUMO_TAG_RELATION) {
1136  bool ok = true;
1137  myCurrentRelation = attrs.get<long long int>(SUMO_ATTR_ID, nullptr, ok);
1138  const std::string action = attrs.hasAttribute("action") ? attrs.getStringSecure("action", "") : "";
1139  if (action == "delete" || !ok) {
1141  }
1142  myName = "";
1143  myRef = "";
1144  myInterval = -1;
1145  myNightService = "";
1146  return;
1147  }
1148  if (myCurrentRelation == INVALID_ID) {
1149  return;
1150  }
1151  // parse member elements
1152  if (element == SUMO_TAG_MEMBER) {
1153  bool ok = true;
1154  std::string role = attrs.hasAttribute("role") ? attrs.getStringSecure("role", "") : "";
1155  auto ref = attrs.get<long
1156  long
1157  int>(SUMO_ATTR_REF, nullptr, ok);
1158  if (role == "via") {
1159  // u-turns for divided ways may be given with 2 via-nodes or 1 via-way
1160  std::string memberType = attrs.get<std::string>(SUMO_ATTR_TYPE, nullptr, ok);
1161  if (memberType == "way" && checkEdgeRef(ref)) {
1162  myViaWay = ref;
1163  } else if (memberType == "node") {
1164  if (myOSMNodes.find(ref) != myOSMNodes.end()) {
1165  myViaNode = ref;
1166  } else {
1167  WRITE_WARNING(
1168  "No node found for reference '" + toString(ref) + "' in relation '"
1170  + "'");
1171  }
1172  }
1173  } else if (role == "from" && checkEdgeRef(ref)) {
1174  myFromWay = ref;
1175  } else if (role == "to" && checkEdgeRef(ref)) {
1176  myToWay = ref;
1177  } else if (role == "stop") {
1178  myStops.push_back(ref);
1179  } else if (role == "platform") {
1180  std::string memberType = attrs.get<std::string>(SUMO_ATTR_TYPE, nullptr, ok);
1181  if (memberType == "way") {
1182  const std::map<long long int,
1183  NIImporter_OpenStreetMap::Edge*>::const_iterator& wayIt = myPlatformShapes.find(ref);
1184  if (wayIt != myPlatformShapes.end()) {
1185 
1186  NIIPTPlatform platform;
1187  platform.isWay = true;
1188  platform.ref = ref;
1189  myPlatforms.push_back(platform);
1190  }
1191  } else if (memberType == "node") {
1192  NIIPTPlatform platform;
1193  platform.isWay = false;
1194  platform.ref = ref;
1195  myPlatforms.push_back(platform);
1196  }
1197 
1198  } else if (role.empty()) {
1199  std::string memberType = attrs.get<std::string>(SUMO_ATTR_TYPE, nullptr, ok);
1200  if (memberType == "way") {
1201  myWays.push_back(ref);
1202  }
1203  }
1204  return;
1205  }
1206  // parse values
1207  if (element == SUMO_TAG_TAG) {
1208  bool ok = true;
1209  std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myCurrentRelation).c_str(), ok, false);
1210  // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
1211  if (key == "type" || key == "restriction") {
1212  std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
1213  if (key == "type" && value == "restriction") {
1214  myIsRestriction = true;
1215  return;
1216  }
1217  if (key == "type" && value == "route") {
1218  myIsRoute = true;
1219  return;
1220  }
1221  if (key == "restriction") {
1222  // @note: the 'right/left/straight' part is ignored since the information is
1223  // redundantly encoded in the 'from', 'to' and 'via' members
1224  if (value.substr(0, 5) == "only_") {
1226  } else if (value.substr(0, 3) == "no_") {
1228  } else {
1229  WRITE_WARNING(
1230  "Found unknown restriction type '" + value + "' in relation '" + toString(myCurrentRelation)
1231  + "'");
1232  }
1233  return;
1234  }
1235  } else if (key == "public_transport") {
1236  std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
1237  if (value == "stop_area") {
1238  myIsStopArea = true;
1239  }
1240  } else if (key == "route") {
1241  std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
1242  if (value == "train" || value == "subway" || value == "light_rail" || value == "monorail" || value == "tram" || value == "bus"
1243  || value == "trolleybus" || value == "arialway" || value == "ferry") {
1244  myPTRouteType = value;
1245  }
1246 
1247  } else if (key == "name") {
1248  myName = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
1249  } else if (key == "ref") {
1250  myRef = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
1251  } else if (key == "interval" || key == "headway") {
1252  myInterval = attrs.get<int>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
1253  } else if (key == "by_night") {
1254  myNightService = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
1255  }
1256  }
1257 }
1258 
1259 bool
1261  if (myOSMEdges.find(ref) != myOSMEdges.end()) {
1262  return true;
1263  }
1264 
1265  WRITE_WARNING(
1266  "No way found for reference '" + toString(ref) + "' in relation '" + toString(myCurrentRelation) + "'");
1267  return false;
1268 
1269 }
1270 
1271 void
1273  myParentElements.pop_back();
1274  if (element == SUMO_TAG_RELATION) {
1275  if (myIsRestriction) {
1276  assert(myCurrentRelation != INVALID_ID);
1277  bool ok = true;
1279  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "' with unknown type.");
1280  ok = false;
1281  }
1282  if (myFromWay == INVALID_ID) {
1283  WRITE_WARNING(
1284  "Ignoring restriction relation '" + toString(myCurrentRelation) + "' with unknown from-way.");
1285  ok = false;
1286  }
1287  if (myToWay == INVALID_ID) {
1288  WRITE_WARNING(
1289  "Ignoring restriction relation '" + toString(myCurrentRelation) + "' with unknown to-way.");
1290  ok = false;
1291  }
1292  if (myViaNode == INVALID_ID && myViaWay == INVALID_ID) {
1293  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "' with unknown via.");
1294  ok = false;
1295  }
1296  if (ok && !applyRestriction()) {
1297  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "'.");
1298  }
1299  } else if (myIsStopArea && OptionsCont::getOptions().isSet("ptstop-output")) {
1300  for (long long ref : myStops) {
1301  if (myOSMNodes.find(ref) == myOSMNodes.end()) {
1302  //WRITE_WARNING(
1303  // "Referenced node: '" + toString(ref) + "' in relation: '" + toString(myCurrentRelation)
1304  // + "' does not exist. Probably OSM file is incomplete.");
1305  continue;
1306  }
1307 
1308  NIOSMNode* n = myOSMNodes.find(ref)->second;
1309  NBPTStop* ptStop = myNBPTStopCont->get(toString(n->id));
1310  if (ptStop == nullptr) {
1311  //WRITE_WARNING(
1312  // "Relation '" + toString(myCurrentRelation) + "' refers to a non existing pt stop at node: '"
1313  // + toString(n->id) + "'. Probably OSM file is incomplete.");
1314  continue;
1315  }
1316  for (NIIPTPlatform& myPlatform : myPlatforms) {
1317  if (myPlatform.isWay) {
1318  assert(myPlatformShapes.find(myPlatform.ref) != myPlatformShapes.end()); //already tested earlier
1319  Edge* edge = (*myPlatformShapes.find(myPlatform.ref)).second;
1320  if (edge->myCurrentNodes[0] == *(edge->myCurrentNodes.end() - 1)) {
1321  WRITE_WARNING("Platform '" + toString(myPlatform.ref) + "' in relation: '" + toString(myCurrentRelation)
1322  + "' is given as polygon, which currently is not supported.");
1323  continue;
1324 
1325  }
1326  PositionVector p;
1327  for (auto nodeRef : edge->myCurrentNodes) {
1328  if (myOSMNodes.find(nodeRef) == myOSMNodes.end()) {
1329  //WRITE_WARNING(
1330  // "Referenced node: '" + toString(ref) + "' in relation: '" + toString(myCurrentRelation)
1331  // + "' does not exist. Probably OSM file is incomplete.");
1332  continue;
1333  }
1334  NIOSMNode* pNode = myOSMNodes.find(nodeRef)->second;
1335  Position pNodePos(pNode->lon, pNode->lat, pNode->ele);
1336  if (!NBNetBuilder::transformCoordinate(pNodePos)) {
1337  WRITE_ERROR("Unable to project coordinates for node '" + toString(pNode->id) + "'.");
1338  continue;
1339  }
1340  p.push_back(pNodePos);
1341  }
1342  if (p.size() == 0) {
1343  WRITE_WARNING(
1344  "Referenced platform: '" + toString(myPlatform.ref) + "' in relation: '" + toString(myCurrentRelation)
1345  + "' is corrupt. Probably OSM file is incomplete.");
1346  continue;
1347  }
1348  NBPTPlatform platform(p[(int)p.size() / 2], p.length());
1349  ptStop->addPlatformCand(platform);
1350  } else {
1351  if (myOSMNodes.find(myPlatform.ref) == myOSMNodes.end()) {
1352  //WRITE_WARNING(
1353  // "Referenced node: '" + toString(ref) + "' in relation: '" + toString(myCurrentRelation)
1354  // + "' does not exist. Probably OSM file is incomplete.");
1355  continue;
1356  }
1357  NIOSMNode* pNode = myOSMNodes.find(myPlatform.ref)->second;
1358  Position platformPos(pNode->lon, pNode->lat, pNode->ele);
1359  if (!NBNetBuilder::transformCoordinate(platformPos)) {
1360  WRITE_ERROR("Unable to project coordinates for node '" + toString(pNode->id) + "'.");
1361  }
1362  NBPTPlatform platform(platformPos, myOptionsCont.getFloat(
1363  "osm.stop-output.length"));
1364  ptStop->addPlatformCand(platform);
1365 
1366  }
1367  }
1368  ptStop->setIsMultipleStopPositions(myStops.size() > 1);;
1369  }
1370  } else if (myPTRouteType != "" && myIsRoute && OptionsCont::getOptions().isSet("ptline-output") && myStops.size() > 1) {
1372  ptLine->setMyNumOfStops((int)myStops.size());
1373  for (long long ref : myStops) {
1374  if (myOSMNodes.find(ref) == myOSMNodes.end()) {
1375  //WRITE_WARNING(
1376  // "Referenced node: '" + toString(ref) + "' in relation: '" + toString(myCurrentRelation)
1377  // + "' does not exist. Probably OSM file is incomplete.");
1378 // resetValues();
1379 // return;
1380  if (!ptLine->getStops().empty()) {
1381  WRITE_WARNING("Done reading first coherent chunk of pt stops. Further stops in relation " + toString(myCurrentRelation) + " are ignored");
1382  break;
1383  }
1384  continue;
1385  }
1386 
1387  NIOSMNode* n = myOSMNodes.find(ref)->second;
1388  NBPTStop* ptStop = myNBPTStopCont->get(toString(n->id));
1389  if (ptStop == nullptr) {
1390  //WRITE_WARNING("Relation '" + toString(myCurrentRelation)
1391  // + "' refers to a non existing pt stop at node: '" + toString(n->id)
1392  // + "'. Probably OSM file is incomplete.");
1393 // resetValues();
1394 // return;
1395  if (!ptLine->getStops().empty()) {
1396  WRITE_WARNING("Done reading first coherent chunk of pt stops. Further stops in relation " + toString(myCurrentRelation) + " are ignored");
1397  break;
1398  }
1399  continue;
1400  }
1401  ptLine->addPTStop(ptStop);
1402  }
1403  for (long long& myWay : myWays) {
1404  auto entr = myOSMEdges.find(myWay);
1405  if (entr != myOSMEdges.end()) {
1406  Edge* edge = entr->second;
1407  for (long long& myCurrentNode : edge->myCurrentNodes) {
1408  ptLine->addWayNode(myWay, myCurrentNode);
1409  }
1410  }
1411  }
1412  if (ptLine->getStops().empty()) {
1413  WRITE_WARNING("PT line in relation " + toString(myCurrentRelation) + " with no stops ignored. Probably OSM file is incomplete.");
1414  resetValues();
1415  return;
1416  }
1417  myNBPTLineCont->insert(ptLine);
1418  }
1419  // other relations might use similar subelements so reset in any case
1420  resetValues();
1421  }
1422 }
1423 
1424 bool
1426  // since OSM ways are bidirectional we need the via to figure out which direction was meant
1427  if (myViaNode != INVALID_ID) {
1428  NBNode* viaNode = myOSMNodes.find(myViaNode)->second->node;
1429  if (viaNode == nullptr) {
1430  WRITE_WARNING("Via-node '" + toString(myViaNode) + "' was not instantiated");
1431  return false;
1432  }
1433  NBEdge* from = findEdgeRef(myFromWay, viaNode->getIncomingEdges());
1434  NBEdge* to = findEdgeRef(myToWay, viaNode->getOutgoingEdges());
1435  if (from == nullptr) {
1436  WRITE_WARNING("from-edge of restriction relation could not be determined");
1437  return false;
1438  }
1439  if (to == nullptr) {
1440  WRITE_WARNING("to-edge of restriction relation could not be determined");
1441  return false;
1442  }
1444  from->addEdge2EdgeConnection(to);
1445  } else {
1446  from->removeFromConnections(to, -1, -1, true);
1447  }
1448  } else {
1449  // XXX interpreting via-ways or via-node lists not yet implemented
1450  WRITE_WARNING("direction of restriction relation could not be determined");
1451  return false;
1452  }
1453  return true;
1454 }
1455 
1456 NBEdge*
1458  const std::vector<NBEdge*>& candidates) const {
1459  const std::string prefix = toString(wayRef);
1460  const std::string backPrefix = "-" + prefix;
1461  NBEdge* result = nullptr;
1462  int found = 0;
1463  for (auto candidate : candidates) {
1464  if ((candidate->getID().substr(0, prefix.size()) == prefix) ||
1465  (candidate->getID().substr(0, backPrefix.size()) == backPrefix)) {
1466  result = candidate;
1467  found++;
1468  }
1469  }
1470  if (found > 1) {
1471  WRITE_WARNING("Ambigous way reference '" + prefix + "' in restriction relation");
1472  result = nullptr;
1473  }
1474  return result;
1475 }
1476 
1477 void
1479  NBNodeCont& nc = nb.getNodeCont();
1480  NBEdgeCont& ec = nb.getEdgeCont();
1481  // reconstruct elevation from layer info
1482  // build a map of raising and lowering forces (attractor and distance)
1483  // for all nodes unknownElevation
1484  std::map<NBNode*, std::vector<std::pair<double, double> > > layerForces;
1485 
1486  // collect all nodes that belong to a way with layer information
1487  std::set<NBNode*> knownElevation;
1488  for (auto& myEdge : myEdges) {
1489  Edge* e = myEdge.second;
1490  if (e->myLayer != 0) {
1491  for (auto j = e->myCurrentNodes.begin(); j != e->myCurrentNodes.end(); ++j) {
1492  NBNode* node = nc.retrieve(toString(*j));
1493  if (node != nullptr) {
1494  knownElevation.insert(node);
1495  layerForces[node].emplace_back(e->myLayer * layerElevation, POSITION_EPS);
1496  }
1497  }
1498  }
1499  }
1500 #ifdef DEBUG_LAYER_ELEVATION
1501  std::cout << "known elevations:\n";
1502  for (std::set<NBNode*>::iterator it = knownElevation.begin(); it != knownElevation.end(); ++it) {
1503  const std::vector<std::pair<double, double> >& primaryLayers = layerForces[*it];
1504  std::cout << " node=" << (*it)->getID() << " ele=";
1505  for (std::vector<std::pair<double, double> >::const_iterator it_ele = primaryLayers.begin(); it_ele != primaryLayers.end(); ++it_ele) {
1506  std::cout << it_ele->first << " ";
1507  }
1508  std::cout << "\n";
1509  }
1510 #endif
1511  // layer data only provides a lower bound on elevation since it is used to
1512  // resolve the relation among overlapping ways.
1513  // Perform a sanity check for steep inclines and raise the knownElevation if necessary
1514  std::map<NBNode*, double> knownEleMax;
1515  for (auto it : knownElevation) {
1516  double eleMax = -std::numeric_limits<double>::max();
1517  const std::vector<std::pair<double, double> >& primaryLayers = layerForces[it];
1518  for (const auto& primaryLayer : primaryLayers) {
1519  eleMax = MAX2(eleMax, primaryLayer.first);
1520  }
1521  knownEleMax[it] = eleMax;
1522  }
1523  const double gradeThreshold = OptionsCont::getOptions().getFloat("osm.layer-elevation.max-grade") / 100;
1524  bool changed = true;
1525  while (changed) {
1526  changed = false;
1527  for (auto it = knownElevation.begin(); it != knownElevation.end(); ++it) {
1528  std::map<NBNode*, std::pair<double, double> > neighbors = getNeighboringNodes(*it,
1529  knownEleMax[*it]
1530  / gradeThreshold * 3,
1531  knownElevation);
1532  for (auto& neighbor : neighbors) {
1533  if (knownElevation.count(neighbor.first) != 0) {
1534  const double grade = fabs(knownEleMax[*it] - knownEleMax[neighbor.first])
1535  / MAX2(POSITION_EPS, neighbor.second.first);
1536 #ifdef DEBUG_LAYER_ELEVATION
1537  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";
1538 #endif
1539  if (grade > gradeThreshold * 50 / 3.6 / neighbor.second.second) {
1540  // raise the lower node to the higher level
1541  const double eleMax = MAX2(knownEleMax[*it], knownEleMax[neighbor.first]);
1542  if (knownEleMax[*it] < eleMax) {
1543  knownEleMax[*it] = eleMax;
1544  } else {
1545  knownEleMax[neighbor.first] = eleMax;
1546  }
1547  changed = true;
1548  }
1549  }
1550  }
1551  }
1552  }
1553 
1554  // collect all nodes within a grade-dependent range around knownElevation-nodes and apply knowElevation forces
1555  std::set<NBNode*> unknownElevation;
1556  for (auto it = knownElevation.begin(); it != knownElevation.end(); ++it) {
1557  const double eleMax = knownEleMax[*it];
1558  const double maxDist = fabs(eleMax) * 100 / layerElevation;
1559  std::map<NBNode*, std::pair<double, double> > neighbors = getNeighboringNodes(*it, maxDist, knownElevation);
1560  for (auto& neighbor : neighbors) {
1561  if (knownElevation.count(neighbor.first) == 0) {
1562  unknownElevation.insert(neighbor.first);
1563  layerForces[neighbor.first].emplace_back(eleMax, neighbor.second.first);
1564  }
1565  }
1566  }
1567 
1568  // apply forces to ground-level nodes (neither in knownElevation nor unknownElevation)
1569  for (auto it = unknownElevation.begin(); it != unknownElevation.end(); ++it) {
1570  double eleMax = -std::numeric_limits<double>::max();
1571  const std::vector<std::pair<double, double> >& primaryLayers = layerForces[*it];
1572  for (const auto& primaryLayer : primaryLayers) {
1573  eleMax = MAX2(eleMax, primaryLayer.first);
1574  }
1575  const double maxDist = fabs(eleMax) * 100 / layerElevation;
1576  std::map<NBNode*, std::pair<double, double> > neighbors = getNeighboringNodes(*it, maxDist, knownElevation);
1577  for (auto& neighbor : neighbors) {
1578  if (knownElevation.count(neighbor.first) == 0 && unknownElevation.count(neighbor.first) == 0) {
1579  layerForces[*it].emplace_back(0, neighbor.second.first);
1580  }
1581  }
1582  }
1583  // compute the elevation for each node as the weighted average of all forces
1584 #ifdef DEBUG_LAYER_ELEVATION
1585  std::cout << "summation of forces\n";
1586 #endif
1587  std::map<NBNode*, double> nodeElevation;
1588  for (auto& layerForce : layerForces) {
1589  const std::vector<std::pair<double, double> >& forces = layerForce.second;
1590  if (knownElevation.count(layerForce.first) != 0) {
1591  // use the maximum value
1592  /*
1593  double eleMax = -std::numeric_limits<double>::max();
1594  for (std::vector<std::pair<double, double> >::const_iterator it_force = forces.begin(); it_force != forces.end(); ++it_force) {
1595  eleMax = MAX2(eleMax, it_force->first);
1596  }
1597  */
1598 #ifdef DEBUG_LAYER_ELEVATION
1599  std::cout << " node=" << it->first->getID() << " knownElevation=" << knownEleMax[it->first] << "\n";
1600 #endif
1601  nodeElevation[layerForce.first] = knownEleMax[layerForce.first];
1602  } else if (forces.size() == 1) {
1603  nodeElevation[layerForce.first] = forces.front().first;
1604  } else {
1605  // use the weighted sum
1606  double distSum = 0;
1607  for (const auto& force : forces) {
1608  distSum += force.second;
1609  }
1610  double weightSum = 0;
1611  double elevation = 0;
1612 #ifdef DEBUG_LAYER_ELEVATION
1613  std::cout << " node=" << it->first->getID() << " distSum=" << distSum << "\n";
1614 #endif
1615  for (const auto& force : forces) {
1616  const double weight = (distSum - force.second) / distSum;
1617  weightSum += weight;
1618  elevation += force.first * weight;
1619 
1620 #ifdef DEBUG_LAYER_ELEVATION
1621  std::cout << " force=" << it_force->first << " dist=" << it_force->second << " weight=" << weight << " ele=" << elevation << "\n";
1622 #endif
1623  }
1624  nodeElevation[layerForce.first] = elevation / weightSum;
1625  }
1626  }
1627 #ifdef DEBUG_LAYER_ELEVATION
1628  std::cout << "final elevations:\n";
1629  for (std::map<NBNode*, double>::iterator it = nodeElevation.begin(); it != nodeElevation.end(); ++it) {
1630  std::cout << " node=" << (it->first)->getID() << " ele=" << it->second << "\n";;
1631  }
1632 #endif
1633  // apply node elevations
1634  for (auto& it : nodeElevation) {
1635  NBNode* n = it.first;
1636  Position pos = n->getPosition();
1637  n->reinit(n->getPosition() + Position(0, 0, it.second), n->getType());
1638  }
1639 
1640  // apply way elevation to all edges that had layer information
1641  for (const auto& it : ec) {
1642  NBEdge* edge = it.second;
1643  const PositionVector& geom = edge->getGeometry();
1644  const double length = geom.length2D();
1645  const double zFrom = nodeElevation[edge->getFromNode()];
1646  const double zTo = nodeElevation[edge->getToNode()];
1647  // XXX if the from- or to-node was part of multiple ways with
1648  // different layers, reconstruct the layer value from origID
1649  double dist = 0;
1650  PositionVector newGeom;
1651  for (auto it_pos = geom.begin(); it_pos != geom.end(); ++it_pos) {
1652  if (it_pos != geom.begin()) {
1653  dist += (*it_pos).distanceTo2D(*(it_pos - 1));
1654  }
1655  newGeom.push_back((*it_pos) + Position(0, 0, zFrom + (zTo - zFrom) * dist / length));
1656  }
1657  edge->setGeometry(newGeom);
1658  }
1659 }
1660 
1661 std::map<NBNode*, std::pair<double, double> >
1662 NIImporter_OpenStreetMap::getNeighboringNodes(NBNode* node, double maxDist, const std::set<NBNode*>& knownElevation) {
1663  std::map<NBNode*, std::pair<double, double> > result;
1664  std::set<NBNode*> visited;
1665  std::vector<NBNode*> open;
1666  open.push_back(node);
1667  result[node] = std::make_pair(0, 0);
1668  while (!open.empty()) {
1669  NBNode* n = open.back();
1670  open.pop_back();
1671  if (visited.count(n) != 0) {
1672  continue;
1673  }
1674  visited.insert(n);
1675  const EdgeVector& edges = n->getEdges();
1676  for (auto e : edges) {
1677  NBNode* s = nullptr;
1678  if (n->hasIncoming(e)) {
1679  s = e->getFromNode();
1680  } else {
1681  s = e->getToNode();
1682  }
1683  const double dist = result[n].first + e->getGeometry().length2D();
1684  const double speed = MAX2(e->getSpeed(), result[n].second);
1685  if (result.count(s) == 0) {
1686  result[s] = std::make_pair(dist, speed);
1687  } else {
1688  result[s] = std::make_pair(MIN2(dist, result[s].first), MAX2(speed, result[s].second));
1689  }
1690  if (dist < maxDist && knownElevation.count(s) == 0) {
1691  open.push_back(s);
1692  }
1693  }
1694  }
1695  result.erase(node);
1696  return result;
1697 }
1698 
1699 
1700 /****************************************************************************/
1701 
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
An internal definition of a loaded edge.
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:108
void insert(const std::string &id, int numLanes, double maxSpeed, int prio, SVCPermissions permissions, double width, bool oneWayIsDefault, double sidewalkWidth, double bikeLaneWidth)
Adds a type into the list.
Definition: NBTypeCont.cpp:54
const bool myImportElevation
whether elevation data should be imported
const std::map< long long int, Edge * > & myOSMEdges
The previously parsed edges.
std::map< long long int, Edge * > & myPlatformShapesMap
A map of built edges.
void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
An internal representation of an OSM-node.
const long long int id
The edge&#39;s id.
double length2D() const
Returns the length.
double getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
Definition: NBTypeCont.cpp:174
~EdgesHandler() override
Destructor.
std::string streetName
The edge&#39;s street name.
NBTypeCont & getTypeCont()
Returns a reference to the type container.
Definition: NBNetBuilder.h:160
NBPTLineCont * myNBPTLineCont
PT Line container to be filled.
is a pedestrian
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
std::string next()
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
const long long int id
The node&#39;s id.
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:47
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
WayType myBuswayType
Information about the kind of busway along this road.
long long int myFromWay
the origination way for the current restriction
vehicle is a not electrified rail
A container for traffic light definitions and built programs.
void reinit(const Position &position, SumoXMLNodeType type, bool updateEdgeGeometries=false)
Resets initial values.
Definition: NBNode.cpp:286
std::map< NBNode *, std::pair< double, double > > getNeighboringNodes(NBNode *node, double maxDist, const std::set< NBNode *> &knownElevation)
collect neighboring nodes with their road distance and maximum between-speed. Search does not continu...
vehicle is a bicycle
const double SUMO_const_laneWidth
Definition: StdDefs.h:51
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
The representation of a single edge during network building.
Definition: NBEdge.h:65
int getPriority(const std::string &type) const
Returns the priority for the given type.
Definition: NBTypeCont.cpp:180
vehicle is a light rail
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:261
void removeFromConnections(NBEdge *toEdge, int fromLane=-1, int toLane=-1, bool tryLater=false, const bool adaptToLaneRemoval=false)
Removes the specified connection(s)
Definition: NBEdge.cpp:1281
long long int myCurrentRelation
The currently parsed relation.
bool checkEdgeRef(long long int ref) const
check whether a referenced way has a corresponding edge
void addPTStop(NBPTStop *pStop)
Definition: NBPTLine.cpp:36
T MAX2(T a, T b)
Definition: StdDefs.h:76
NBPTStopCont & getPTStopCont()
Returns a reference to the pt stop container.
Definition: NBNetBuilder.h:176
void setPermissions(SVCPermissions permissions, int lane=-1)
set allowed/disallowed classes for the given lane or for all lanes if -1 is given ...
Definition: NBEdge.cpp:3303
std::vector< NIIPTPlatform > myPlatforms
bus stop platforms
NBPTLineCont & getPTLineCont()
Returns a reference to the pt line container.
Definition: NBNetBuilder.h:181
PositionVector reverse() const
reverse position vector
static bool transformCoordinates(PositionVector &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
int getNumLanes(const std::string &type) const
Returns the number of lanes for the given type.
Definition: NBTypeCont.cpp:168
bool getShallBeDiscarded(const std::string &type) const
Returns the information whether edges of this type shall be discarded.
Definition: NBTypeCont.cpp:192
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getID() const
Returns the id.
Definition: Named.h:78
RelationHandler(const std::map< long long int, NIOSMNode *> &osmNodes, const std::map< long long int, Edge *> &osmEdges, NBPTStopCont *nbptStopCont, const std::map< long long int, Edge *> &platfromShapes, NBPTLineCont *nbptLineCont, const OptionsCont &oc)
Constructor.
The representation of a single pt stop.
Definition: NBPTStop.h:45
std::vector< long long int > myStops
bus stop references
void registerAdditionalEdge(std::string wayId, std::string edgeId)
Definition: NBPTStop.cpp:174
NBParkingCont & getParkingCont()
Definition: NBNetBuilder.h:186
SAX-handler base for SUMO-files.
void myEndElement(int element) override
Called when a closing tag occurs.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:113
void addSidewalk(double width)
add a pedestrian sidewalk of the given width and shift existing connctions
Definition: NBEdge.cpp:3458
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
void setGeometry(const PositionVector &g, bool inner=false)
(Re)sets the edge&#39;s geometry
Definition: NBEdge.cpp:559
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:258
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
bool railwaySignal
Whether this is a railway (main) signal.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
double getWidth(const std::string &type) const
Returns the lane width for the given type [m].
Definition: NBTypeCont.cpp:210
std::set< NIOSMNode *, CompareNodes > & myUniqueNodes
the set of unique nodes (used for duplicate detection/substitution)
NBNode * node
the NBNode that was instantiated
vehicle is a city rail
const EdgeVector & getOutgoingEdges() const
Returns this node&#39;s outgoing edges (The edges which start at this node)
Definition: NBNode.h:255
std::vector< long long int > myWays
ways in pt line references
const OptionsCont & myOptionsCont
the options cont
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given OSM file.
Functor which compares two Edges.
WayType myCyclewayType
Information about the kind of cycleway along this road.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
The representation of a single pt stop.
Definition: NBParking.h:44
int myNoLanesForward
number of lanes in forward direction or 0 if unknown, negative if backwards lanes are meant ...
bool addEdge2EdgeConnection(NBEdge *dest)
Adds a connection to another edge.
Definition: NBEdge.cpp:974
const std::map< long long int, Edge * > & myPlatformShapes
The previously parsed platform shapes.
NBEdge * findEdgeRef(long long int wayRef, const std::vector< NBEdge *> &candidates) const
try to find the way segment among candidates
bool knows(const std::string &type) const
Returns whether the named type is in the container.
Definition: NBTypeCont.cpp:68
double getBikeLaneWidth(const std::string &type) const
Returns the lane width for a bike lane to be added [m].
Definition: NBTypeCont.cpp:222
void load(const OptionsCont &oc, NBNetBuilder &nb)
bool myAllAttributes
whether additional way attributes shall be added to the edge
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
void setFileName(const std::string &name)
Sets the current file name.
void addWayNode(long long int way, long long int node)
Definition: NBPTLine.cpp:100
void setMyNumOfStops(int numStops)
Definition: NBPTLine.cpp:123
A class which extracts OSM-edges from a parsed OSM-file.
int insertEdge(Edge *e, int index, NBNode *from, NBNode *to, const std::vector< long long int > &passed, NBNetBuilder &nb)
Builds an NBEdge.
void insert(NBPTLine *pLine)
insert new line
double ele
The elevation of this node.
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:152
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
std::vector< int > myParentElements
The element stack.
double getSidewalkWidth(const std::string &type) const
Returns the lane width for a sidewalk to be added [m].
Definition: NBTypeCont.cpp:216
void updateParameter(const std::map< std::string, std::string > &mapArg)
Adds or updates all given parameters from the map.
bool ptStopPosition
Whether this is a public transport stop position.
Encapsulated SAX-Attributes.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
classes which drive on tracks
void myEndElement(int element) override
Called when a closing tag occurs.
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:150
A list of positions.
T get(const std::string &str) const
const EdgeVector & getEdges() const
Returns all edges which participate in this node (Edges that start or end at this node) ...
Definition: NBNode.h:260
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
T MIN2(T a, T b)
Definition: StdDefs.h:70
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:243
void cleanupDeleted(NBEdgeCont &cont)
remove stops on non existing (removed) edges
#define POSITION_EPS
Definition: config.h:172
bool operator()(const Edge *e1, const Edge *e2) const
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
int myParkingType
Information about road-side parking.
long long int myLastNodeID
ID of the currently parsed node, for reporting mainly.
std::map< long long int, NIOSMNode * > & myToFill
The nodes container to fill.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
bool myIsRestriction
whether the currently parsed relation is a restriction
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
void setIsMultipleStopPositions(bool multipleStopPositions)
Definition: NBPTStop.cpp:155
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool railwayCrossing
Whether this is a railway crossing.
~NodesHandler() override
Destructor.
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:3331
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
bool hasIncoming(const NBEdge *const e) const
Returns whether the given edge ends at this node.
Definition: NBNode.cpp:1387
void myEndElement(int element) override
Called when a closing tag occurs.
bool myIsInValidNodeTag
Hierarchy helper for parsing a node&#39;s tags.
std::map< long long int, Edge * > myEdges
the map from OSM way ids to edge objects
std::vector< std::string > getVector()
const double lat
The latitude the node is located at.
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:622
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:247
int myNoLanes
number of lanes, or -1 if unknown
bool railwayBufferStop
Whether this is a railway buffer stop.
vehicle is a bus
static std::string to_lower_case(std::string str)
Transfers the content to lower case.
Definition: StringUtils.cpp:58
bool tlsControlled
Whether this is a tls controlled junction.
EdgesHandler(const std::map< long long int, NIOSMNode *> &osmNodes, std::map< long long int, Edge *> &toFill, std::map< long long int, Edge *> &platformShapes)
Constructor.
void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
WayType mySidewalkType
Information about the kind of sidwalk along this road.
std::map< std::string, std::string > myKnownCompoundTypes
The compound types that have already been mapped to other known types.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
Definition: StringUtils.cpp:47
double length() const
Returns the length.
std::map< long long int, Edge * > & myEdgeMap
A map of built edges.
bool myCurrentIsPlatform
Information whether this is a pt platform.
const EdgeVector & getIncomingEdges() const
Returns this node&#39;s incoming edges (The edges which yield in this node)
Definition: NBNode.h:250
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:155
long long int myToWay
the destination way for the current restriction
bool myIsRoute
indicates whether current relation is a route
int myLayer
Information about the relative z-ordering of ways.
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
std::string myPTRouteType
indicates whether current relation is a pt route
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:34
static const std::string compoundTypeSeparator
The separator within newly created compound type names.
virtual std::string getStringSecure(int id, const std::string &def) const =0
Returns the string-value of the named (by its enum-value) attribute.
alternative definition for junction
A storage for options typed value containers)
Definition: OptionsCont.h:92
long long int myViaNode
the via node/way for the current restriction
std::string joinToStringSorting(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:253
NBPTStop * get(std::string id)
Retrieve a previously inserted pt stop.
bool copyRestrictionsAndAttrs(const std::string &fromId, const std::string &toId)
Copy restrictions to a type.
Definition: NBTypeCont.cpp:107
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:267
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
void addBikeLane(double width)
add a bicycle lane of the given width and shift existing connctions
Definition: NBEdge.cpp:3470
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:79
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:165
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge&#39;s lateral offset shal...
void reconstructLayerElevation(double layerElevation, NBNetBuilder &nb)
reconstruct elevation from layer info
std::string name
The name of the node.
A class which extracts OSM-nodes from a parsed OSM-file.
const Position & getPosition() const
Definition: NBNode.h:242
int myInterval
service interval of the pt line in seconds
Represents a single node (junction) during network building.
Definition: NBNode.h:68
void resetValues()
reset members to their defaults for parsing a new relation
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
NBNode * insertNodeChecking(long long int id, NBNodeCont &nc, NBTrafficLightLogicCont &tlsc)
Builds an NBNode.
int myHierarchyLevel
The current hierarchy level.
std::string myHighWayType
The type, stored in "highway" key.
NodesHandler(std::map< long long int, NIOSMNode *> &toFill, std::set< NIOSMNode *, CompareNodes > &uniqueNodes, const OptionsCont &cont)
Contructor.
const double lon
The longitude the node is located at.
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
std::string myNightService
night service information of the pt line
Importer for networks stored in OpenStreetMap format.
bool myIsStopArea
indicates whether current relation is a pt stop area
static const long long int INVALID_ID
bool myCurrentIsRoad
Information whether this is a road.
Edge * myCurrentEdge
The currently built edge.
std::map< long long int, Edge * > myPlatformShapes
the map from OSM way ids to platform shapes
std::set< std::string > myUnusableTypes
The compounds types that do not contain known types.
std::vector< NBPTStop * > getStops()
Definition: NBPTLine.cpp:49
SVCPermissions permissions
type of pt stop
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:434
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:60
void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
bool insert(NBPTStop *ptStop)
Inserts a node into the map.
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:244
double ptStopLength
The length of the pt stop.
std::map< long long int, NIOSMNode * > myOSMNodes
the map from OSM node ids to actual nodes
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:47
std::vector< int > myParentElements
The element stack.
bool getIsOneWay(const std::string &type) const
Returns whether edges are one-way per default for the given type.
Definition: NBTypeCont.cpp:186
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:242
std::set< NIOSMNode *, CompareNodes > myUniqueNodes
the set of unique nodes used in NodesHandler, used when freeing memory
void addPlatformCand(NBPTPlatform platform)
Definition: NBPTStop.cpp:137
static const double MAXSPEED_UNGIVEN
const OptionsCont & myOptionsCont
the options
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:441
bool applyRestriction() const
try to apply the parsed restriction and return whether successful
A class which extracts relevant relation information from a parsed OSM-file.
std::string myIsOneWay
Information whether this is an one-way road.
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:237
std::map< std::string, double > mySpeedMap
A map of non-numeric speed descriptions to their numeric values.
TrafficLightType
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Definition: NBTypeCont.cpp:204
A storage for available types of edges.
Definition: NBTypeCont.h:55
NBPTStopCont * myNBPTStopCont
The previously filled pt stop container.