SUMO - Simulation of Urban MObility
NIImporter_OpenStreetMap.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Importer for networks stored in OpenStreetMap format
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 #include <algorithm>
34 #include <set>
35 #include <functional>
36 #include <sstream>
37 #include <limits>
41 #include <utils/common/ToString.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>
56 #include <utils/xml/XMLSubSys.h>
57 #include "NILoader.h"
59 
60 #ifdef CHECK_MEMORY_LEAKS
61 #include <foreign/nvwa/debug_new.h>
62 #endif // CHECK_MEMORY_LEAKS
63 
64 // ---------------------------------------------------------------------------
65 // static members
66 // ---------------------------------------------------------------------------
68 
70 
71 // ===========================================================================
72 // Private classes
73 // ===========================================================================
74 
78 public:
79  bool operator()(const Edge* e1, const Edge* e2) const {
80  if (e1->myHighWayType != e2->myHighWayType) {
81  return e1->myHighWayType > e2->myHighWayType;
82  }
83  if (e1->myNoLanes != e2->myNoLanes) {
84  return e1->myNoLanes > e2->myNoLanes;
85  }
86  if (e1->myNoLanesForward != e2->myNoLanesForward) {
87  return e1->myNoLanesForward > e2->myNoLanesForward;
88  }
89  if (e1->myMaxSpeed != e2->myMaxSpeed) {
90  return e1->myMaxSpeed > e2->myMaxSpeed;
91  }
92  if (e1->myIsOneWay != e2->myIsOneWay) {
93  return e1->myIsOneWay > e2->myIsOneWay;
94  }
95  return e1->myCurrentNodes > e2->myCurrentNodes;
96  }
97 };
98 
99 // ===========================================================================
100 // method definitions
101 // ===========================================================================
102 // ---------------------------------------------------------------------------
103 // static methods
104 // ---------------------------------------------------------------------------
106 
107 
108 void
110  NIImporter_OpenStreetMap importer;
111  importer.load(oc, nb);
112 }
113 
114 
116 
117 
119  // delete nodes
120  for (std::set<NIOSMNode*, CompareNodes>::iterator i = myUniqueNodes.begin(); i != myUniqueNodes.end(); i++) {
121  delete *i;
122  }
123  // delete edges
124  for (std::map<long long int, Edge*>::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
125  delete(*i).second;
126  }
127 }
128 
129 
130 void
132  // check whether the option is set (properly)
133  if (!oc.isSet("osm-files")) {
134  return;
135  }
136  /* Parse file(s)
137  * Each file is parsed twice: first for nodes, second for edges. */
138  std::vector<std::string> files = oc.getStringVector("osm-files");
139  // load nodes, first
140  NodesHandler nodesHandler(myOSMNodes, myUniqueNodes, oc.getBool("osm.elevation"));
141  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
142  // nodes
143  if (!FileHelpers::isReadable(*file)) {
144  WRITE_ERROR("Could not open osm-file '" + *file + "'.");
145  return;
146  }
147  nodesHandler.setFileName(*file);
148  PROGRESS_BEGIN_MESSAGE("Parsing nodes from osm-file '" + *file + "'");
149  if (!XMLSubSys::runParser(nodesHandler, *file)) {
150  return;
151  }
153  }
154  // load edges, then
155  EdgesHandler edgesHandler(myOSMNodes, myEdges);
156  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
157  // edges
158  edgesHandler.setFileName(*file);
159  PROGRESS_BEGIN_MESSAGE("Parsing edges from osm-file '" + *file + "'");
160  XMLSubSys::runParser(edgesHandler, *file);
162  }
163 
164  /* Remove duplicate edges with the same shape and attributes */
165  if (!oc.getBool("osm.skip-duplicates-check")) {
166  PROGRESS_BEGIN_MESSAGE("Removing duplicate edges");
167  if (myEdges.size() > 1) {
168  std::set<const Edge*, CompareEdges> dupsFinder;
169  for (std::map<long long int, Edge*>::iterator it = myEdges.begin(); it != myEdges.end();) {
170  if (dupsFinder.count(it->second) > 0) {
171  WRITE_MESSAGE("Found duplicate edges. Removing " + toString(it->first));
172  delete it->second;
173  myEdges.erase(it++);
174  } else {
175  dupsFinder.insert(it->second);
176  it++;
177  }
178  }
179  }
181  }
182 
183  /* Mark which nodes are used (by edges or traffic lights).
184  * This is necessary to detect which OpenStreetMap nodes are for
185  * geometry only */
186  std::map<long long int, int> nodeUsage;
187  // Mark which nodes are used by edges (begin and end)
188  for (std::map<long long int, Edge*>::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
189  Edge* e = (*i).second;
190  assert(e->myCurrentIsRoad);
191  for (std::vector<long long int>::const_iterator j = e->myCurrentNodes.begin(); j != e->myCurrentNodes.end(); ++j) {
192  if (nodeUsage.find(*j) == nodeUsage.end()) {
193  nodeUsage[*j] = 0;
194  }
195  nodeUsage[*j] = nodeUsage[*j] + 1;
196  }
197  }
198  // Mark which nodes are used by traffic lights
199  for (std::map<long long int, NIOSMNode*>::const_iterator nodesIt = myOSMNodes.begin(); nodesIt != myOSMNodes.end(); ++nodesIt) {
200  if (nodesIt->second->tlsControlled) {
201  // If the key is not found in the map, the value is automatically
202  // initialized with 0.
203  nodeUsage[nodesIt->first] += 1;
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 (std::map<long long int, Edge*>::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
212  Edge* e = (*i).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 (std::vector<long long int>::iterator 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  }
234  }
235  if (running == 0) {
236  running = -1;
237  }
238  insertEdge(e, running, currentFrom, last, passed, nb);
239  }
240 
241  // load relations (after edges are built since we want to apply
242  // turn-restrictions directly to NBEdges)
243  RelationHandler relationHandler(myOSMNodes, myEdges);
244  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
245  // relations
246  relationHandler.setFileName(*file);
247  PROGRESS_BEGIN_MESSAGE("Parsing relations from osm-file '" + *file + "'");
248  XMLSubSys::runParser(relationHandler, *file);
250  }
251 }
252 
253 
254 NBNode*
256  NBNode* node = nc.retrieve(toString(id));
257  if (node == 0) {
258  NIOSMNode* n = myOSMNodes.find(id)->second;
259  Position pos(n->lon, n->lat, n->ele);
260  if (!NBNetBuilder::transformCoordinates(pos, true)) {
261  WRITE_ERROR("Unable to project coordinates for junction '" + toString(id) + "'.");
262  return 0;
263  }
264  node = new NBNode(toString(id), pos);
265  if (!nc.insert(node)) {
266  WRITE_ERROR("Could not insert junction '" + toString(id) + "'.");
267  delete node;
268  return 0;
269  }
270  n->node = node;
271  if (n->tlsControlled) {
272  // ok, this node is a traffic light node where no other nodes
273  // participate
274  // @note: The OSM-community has not settled on a schema for differentiating between fixed and actuated lights
276  NBOwnTLDef* tlDef = new NBOwnTLDef(toString(id), node, 0, type);
277  if (!tlsc.insert(tlDef)) {
278  // actually, nothing should fail here
279  delete tlDef;
280  throw ProcessError("Could not allocate tls '" + toString(id) + "'.");
281  }
282  }
283  }
284  return node;
285 }
286 
287 
288 int
290  const std::vector<long long int>& passed, NBNetBuilder& nb) {
291  NBNodeCont& nc = nb.getNodeCont();
292  NBEdgeCont& ec = nb.getEdgeCont();
293  NBTypeCont& tc = nb.getTypeCont();
295  // patch the id
296  std::string id = toString(e->id);
297  if (from == 0 || to == 0) {
298  WRITE_ERROR("Discarding edge '" + id + "' because the nodes could not be built.");
299  return index;
300  }
301  if (index >= 0) {
302  id = id + "#" + toString(index);
303  } else {
304  index = 0;
305  }
306  if (from == to) {
307  assert(passed.size() >= 2);
308  if (passed.size() == 2) {
309  WRITE_WARNING("Discarding edge '" + id + "' which connects two identical nodes without geometry.");
310  return index;
311  }
312  // in the special case of a looped way split again using passed
313  size_t intermediateIndex = passed.size() / 2;
314  NBNode* intermediate = insertNodeChecking(passed[intermediateIndex], nc, tlsc);
315  std::vector<long long int> part1(passed.begin(), passed.begin() + intermediateIndex);
316  std::vector<long long int> part2(passed.begin() + intermediateIndex + 1, passed.end());
317  index = insertEdge(e, index, from, intermediate, part1, nb);
318  return insertEdge(e, index, intermediate, to, part2, nb);
319  }
320  const int newIndex = index + 1;
321 
322  // convert the shape
323  PositionVector shape;
324  shape.push_back(from->getPosition());
325  for (std::vector<long long int>::const_iterator i = passed.begin(); i != passed.end(); ++i) {
326  NIOSMNode* n = myOSMNodes.find(*i)->second;
327  Position pos(n->lon, n->lat, n->ele);
328  if (!NBNetBuilder::transformCoordinates(pos, true)) {
329  WRITE_ERROR("Unable to project coordinates for edge '" + id + "'.");
330  }
331  shape.push_back_noDoublePos(pos);
332  }
333  shape.push_back_noDoublePos(to->getPosition());
334 
335  std::string type = e->myHighWayType;
336  if (!tc.knows(type)) {
337  if (myUnusableTypes.count(type) > 0) {
338  return newIndex;
339  } else if (myKnownCompoundTypes.count(type) > 0) {
340  type = myKnownCompoundTypes[type];
341  } else {
342  // this edge has a type which does not yet exist in the TypeContainer
344  std::vector<std::string> types;
345  while (tok.hasNext()) {
346  std::string t = tok.next();
347  if (tc.knows(t)) {
348  if (std::find(types.begin(), types.end(), t) == types.end()) {
349  types.push_back(t);
350  }
351  } else if (tok.size() > 1) {
352  WRITE_WARNING("Discarding unknown compound '" + t + "' in type '" + type + "' (first occurence for edge '" + id + "').");
353  }
354  }
355  if (types.size() == 0) {
356  WRITE_WARNING("Discarding unusable type '" + type + "' (first occurence for edge '" + id + "').");
357  myUnusableTypes.insert(type);
358  return newIndex;
359  } else {
360  const std::string newType = joinToString(types, "|");
361  if (tc.knows(newType)) {
362  myKnownCompoundTypes[type] = newType;
363  type = newType;
364  } else if (myKnownCompoundTypes.count(newType) > 0) {
365  type = myKnownCompoundTypes[newType];
366  } else {
367  // build a new type by merging all values
368  int numLanes = 0;
369  SUMOReal maxSpeed = 0;
370  int prio = 0;
372  SUMOReal sidewalkWidth = NBEdge::UNSPECIFIED_WIDTH;
373  SUMOReal bikelaneWidth = NBEdge::UNSPECIFIED_WIDTH;
374  bool defaultIsOneWay = false;
375  SVCPermissions permissions = 0;
376  bool discard = true;
377  for (std::vector<std::string>::iterator it = types.begin(); it != types.end(); it++) {
378  if (!tc.getShallBeDiscarded(*it)) {
379  numLanes = MAX2(numLanes, tc.getNumLanes(*it));
380  maxSpeed = MAX2(maxSpeed, tc.getSpeed(*it));
381  prio = MAX2(prio, tc.getPriority(*it));
382  defaultIsOneWay &= tc.getIsOneWay(*it);
383  permissions |= tc.getPermissions(*it);
384  width = MAX2(width, tc.getWidth(*it));
385  sidewalkWidth = MAX2(sidewalkWidth, tc.getSidewalkWidth(*it));
386  bikelaneWidth = MAX2(bikelaneWidth, tc.getBikeLaneWidth(*it));
387  discard = false;
388  }
389  }
390  if (width != NBEdge::UNSPECIFIED_WIDTH) {
391  width = MAX2(width, SUMO_const_laneWidth);
392  }
393  if (discard) {
394  WRITE_WARNING("Discarding compound type '" + newType + "' (first occurence for edge '" + id + "').");
395  myUnusableTypes.insert(newType);
396  return newIndex;
397  } else {
398  WRITE_MESSAGE("Adding new type '" + type + "' (first occurence for edge '" + id + "').");
399  tc.insert(newType, numLanes, maxSpeed, prio, permissions, width, defaultIsOneWay, sidewalkWidth, bikelaneWidth);
400  for (std::vector<std::string>::iterator it = types.begin(); it != types.end(); it++) {
401  if (!tc.getShallBeDiscarded(*it)) {
402  tc.copyRestrictionsAndAttrs(*it, newType);
403  }
404  }
405  myKnownCompoundTypes[type] = newType;
406  type = newType;
407  }
408  }
409  }
410  }
411  }
412 
413  // otherwise it is not an edge and will be ignored
414  bool ok = true;
415  int numLanesForward = tc.getNumLanes(type);
416  int numLanesBackward = tc.getNumLanes(type);
417  SUMOReal speed = tc.getSpeed(type);
418  bool defaultsToOneWay = tc.getIsOneWay(type);
419  SVCPermissions forwardPermissions = tc.getPermissions(type);
420  SVCPermissions backwardPermissions = tc.getPermissions(type);
421  SUMOReal forwardWidth = tc.getWidth(type);
422  SUMOReal backwardWidth = tc.getWidth(type);
423  const bool addSidewalk = (tc.getSidewalkWidth(type) != NBEdge::UNSPECIFIED_WIDTH);
424  const bool addBikeLane = (tc.getBikeLaneWidth(type) != NBEdge::UNSPECIFIED_WIDTH);
425  // check directions
426  bool addForward = true;
427  bool addBackward = true;
428  if (e->myIsOneWay == "true" || e->myIsOneWay == "yes" || e->myIsOneWay == "1" || (defaultsToOneWay && e->myIsOneWay != "no" && e->myIsOneWay != "false" && e->myIsOneWay != "0")) {
429  addBackward = false;
430  }
431  if (e->myIsOneWay == "-1" || e->myIsOneWay == "reverse") {
432  // one-way in reversed direction of way
433  addForward = false;
434  addBackward = true;
435  }
436  if (e->myIsOneWay != "" && e->myIsOneWay != "false" && e->myIsOneWay != "no" && e->myIsOneWay != "true" && e->myIsOneWay != "yes" && e->myIsOneWay != "-1" && e->myIsOneWay != "1" && e->myIsOneWay != "reverse") {
437  WRITE_WARNING("New value for oneway found: " + e->myIsOneWay);
438  }
439  // if we had been able to extract the number of lanes, override the highway type default
440  if (e->myNoLanes > 0) {
441  if (addForward && !addBackward) {
442  numLanesForward = e->myNoLanes;
443  } else if (!addForward && addBackward) {
444  numLanesBackward = e->myNoLanes;
445  } else {
446  if (e->myNoLanesForward > 0) {
447  numLanesForward = e->myNoLanesForward;
448  } else if (e->myNoLanesForward < 0) {
449  numLanesForward = e->myNoLanes + e->myNoLanesForward;
450  } else {
451  numLanesForward = (int)std::ceil(e->myNoLanes / 2.0);
452  }
453  numLanesBackward = e->myNoLanes - numLanesForward;
454  // sometimes ways are tagged according to their physical width of a single
455  // lane but they are intended for traffic in both directions
456  numLanesForward = MAX2(1, numLanesForward);
457  numLanesBackward = MAX2(1, numLanesBackward);
458  }
459  } else if (e->myNoLanes == 0) {
460  WRITE_WARNING("Skipping edge '" + id + "' because it has zero lanes.");
461  ok = false;
462  }
463  // if we had been able to extract the maximum speed, override the type's default
464  if (e->myMaxSpeed != MAXSPEED_UNGIVEN) {
465  speed = (SUMOReal)(e->myMaxSpeed / 3.6);
466  }
467  if (speed <= 0) {
468  WRITE_WARNING("Skipping edge '" + id + "' because it has speed " + toString(speed));
469  ok = false;
470  }
471  // deal with cycleways that run in the opposite direction of a one-way street
472  if (addBikeLane) {
473  if (!addForward && (e->myCyclewayType & WAY_FORWARD) != 0) {
474  addForward = true;
475  forwardPermissions = SVC_BICYCLE;
476  forwardWidth = tc.getBikeLaneWidth(type);
477  numLanesForward = 1;
478  // do not add an additional cycle lane
480  }
481  if (!addBackward && (e->myCyclewayType & WAY_BACKWARD) != 0) {
482  addBackward = true;
483  backwardPermissions = SVC_BICYCLE;
484  backwardWidth = tc.getBikeLaneWidth(type);
485  numLanesBackward = 1;
486  // do not add an additional cycle lane
488  }
489  }
490  // deal with busways that run in the opposite direction of a one-way street
491  if (!addForward && (e->myBuswayType & WAY_FORWARD) != 0) {
492  addForward = true;
493  forwardPermissions = SVC_BUS;
494  numLanesForward = 1;
495  }
496  if (!addBackward && (e->myBuswayType & WAY_BACKWARD) != 0) {
497  addBackward = true;
498  backwardPermissions = SVC_BUS;
499  numLanesBackward = 1;
500  }
501 
502  if (ok) {
504  id = StringUtils::escapeXML(id);
505  if (addForward) {
506  assert(numLanesForward > 0);
507  NBEdge* nbe = new NBEdge(id, from, to, type, speed, numLanesForward, tc.getPriority(type),
508  forwardWidth, NBEdge::UNSPECIFIED_OFFSET, shape,
509  StringUtils::escapeXML(e->streetName), toString(e->id), lsf, true);
510  nbe->setPermissions(forwardPermissions);
511  if ((e->myBuswayType & WAY_FORWARD) != 0) {
512  nbe->setPermissions(SVC_BUS, 0);
513  }
514  if (addBikeLane && (e->myCyclewayType == WAY_UNKNOWN || (e->myCyclewayType & WAY_FORWARD) != 0)) {
515  nbe->addBikeLane(tc.getBikeLaneWidth(type));
516  }
517  if (addSidewalk) {
518  nbe->addSidewalk(tc.getSidewalkWidth(type));
519  }
520  if (!ec.insert(nbe)) {
521  delete nbe;
522  throw ProcessError("Could not add edge '" + id + "'.");
523  }
524  }
525  if (addBackward) {
526  assert(numLanesBackward > 0);
527  NBEdge* nbe = new NBEdge("-" + id, to, from, type, speed, numLanesBackward, tc.getPriority(type),
528  backwardWidth, NBEdge::UNSPECIFIED_OFFSET, shape.reverse(),
529  StringUtils::escapeXML(e->streetName), toString(e->id), lsf, true);
530  nbe->setPermissions(backwardPermissions);
531  if ((e->myBuswayType & WAY_BACKWARD) != 0) {
532  nbe->setPermissions(SVC_BUS, 0);
533  }
534  if (addBikeLane && (e->myCyclewayType == WAY_UNKNOWN || (e->myCyclewayType & WAY_BACKWARD) != 0)) {
535  nbe->addBikeLane(tc.getBikeLaneWidth(type));
536  }
537  if (addSidewalk) {
538  nbe->addSidewalk(tc.getSidewalkWidth(type));
539  }
540  if (!ec.insert(nbe)) {
541  delete nbe;
542  throw ProcessError("Could not add edge '-" + id + "'.");
543  }
544  }
545  }
546  return newIndex;
547 }
548 
549 
550 // ---------------------------------------------------------------------------
551 // definitions of NIImporter_OpenStreetMap::NodesHandler-methods
552 // ---------------------------------------------------------------------------
554  std::map<long long int, NIOSMNode*>& toFill,
555  std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
556  bool importElevation) :
557  SUMOSAXHandler("osm - file"),
558  myToFill(toFill),
559  myLastNodeID(-1),
560  myIsInValidNodeTag(false),
561  myHierarchyLevel(0),
562  myUniqueNodes(uniqueNodes),
563  myImportElevation(importElevation) {
564 }
565 
566 
568 
569 
570 void
573  if (element == SUMO_TAG_NODE) {
574  bool ok = true;
575  if (myHierarchyLevel != 2) {
576  WRITE_ERROR("Node element on wrong XML hierarchy level (id='" + toString(attrs.get<long long int>(SUMO_ATTR_ID, 0, ok)) + "', level='" + toString(myHierarchyLevel) + "').");
577  return;
578  }
579  long long int id = attrs.get<long long int>(SUMO_ATTR_ID, 0, ok);
580  std::string action = attrs.hasAttribute("action") ? attrs.getStringSecure("action", "") : "";
581  if (action == "delete") {
582  return;
583  }
584  if (!ok) {
585  return;
586  }
587  myLastNodeID = -1;
588  if (myToFill.find(id) == myToFill.end()) {
589  myLastNodeID = id;
590  // assume we are loading multiple files...
591  // ... so we won't report duplicate nodes
592  bool ok = true;
593  double tlat, tlon;
594  std::istringstream lon(attrs.get<std::string>(SUMO_ATTR_LON, toString(id).c_str(), ok));
595  if (!ok) {
596  return;
597  }
598  lon >> tlon;
599  if (lon.fail()) {
600  WRITE_ERROR("Node's '" + toString(id) + "' lon information is not numeric.");
601  return;
602  }
603  std::istringstream lat(attrs.get<std::string>(SUMO_ATTR_LAT, toString(id).c_str(), ok));
604  if (!ok) {
605  return;
606  }
607  lat >> tlat;
608  if (lat.fail()) {
609  WRITE_ERROR("Node's '" + toString(id) + "' lat information is not numeric.");
610  return;
611  }
612  NIOSMNode* toAdd = new NIOSMNode(id, tlon, tlat);
613  myIsInValidNodeTag = true;
614 
615  std::set<NIOSMNode*, CompareNodes>::iterator similarNode = myUniqueNodes.find(toAdd);
616  if (similarNode == myUniqueNodes.end()) {
617  myUniqueNodes.insert(toAdd);
618  } else {
619  delete toAdd;
620  toAdd = *similarNode;
621  WRITE_MESSAGE("Found duplicate nodes. Substituting " + toString(id) + " with " + toString(toAdd->id));
622  }
623  myToFill[id] = toAdd;
624  }
625  }
626  if (element == SUMO_TAG_TAG && myIsInValidNodeTag) {
627  if (myHierarchyLevel != 3) {
628  WRITE_ERROR("Tag element on wrong XML hierarchy level.");
629  return;
630  }
631  bool ok = true;
632  std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myLastNodeID).c_str(), ok, false);
633  // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
634  if (key == "highway" || key == "ele" || key == "crossing") {
635  std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myLastNodeID).c_str(), ok, false);
636  if (key == "highway" && value.find("traffic_signal") != std::string::npos) {
637  myToFill[myLastNodeID]->tlsControlled = true;
638  } else if (key == "crossing" && value.find("traffic_signals") != std::string::npos) {
639  myToFill[myLastNodeID]->tlsControlled = true;
640  } else if (myImportElevation && key == "ele") {
641  try {
642  myToFill[myLastNodeID]->ele = TplConvert::_2SUMOReal(value.c_str());
643  } catch (...) {
644  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in node '" +
645  toString(myLastNodeID) + "'.");
646  }
647  }
648  }
649  }
650 }
651 
652 
653 void
655  if (element == SUMO_TAG_NODE && myHierarchyLevel == 2) {
656  myLastNodeID = -1;
657  myIsInValidNodeTag = false;
658  }
660 }
661 
662 
663 // ---------------------------------------------------------------------------
664 // definitions of NIImporter_OpenStreetMap::EdgesHandler-methods
665 // ---------------------------------------------------------------------------
667  const std::map<long long int, NIOSMNode*>& osmNodes,
668  std::map<long long int, Edge*>& toFill) :
669  SUMOSAXHandler("osm - file"),
670  myOSMNodes(osmNodes),
671  myEdgeMap(toFill) {
672  mySpeedMap["signals"] = MAXSPEED_UNGIVEN;
673  mySpeedMap["none"] = 300.;
674  mySpeedMap["no"] = 300.;
675  mySpeedMap["walk"] = 5.;
676  mySpeedMap["DE:rural"] = 100.;
677  mySpeedMap["DE:urban"] = 50.;
678  mySpeedMap["DE:living_street"] = 10.;
679 
680 }
681 
682 
684 }
685 
686 
687 void
689  const SUMOSAXAttributes& attrs) {
690  myParentElements.push_back(element);
691  // parse "way" elements
692  if (element == SUMO_TAG_WAY) {
693  bool ok = true;
694  long long int id = attrs.get<long long int>(SUMO_ATTR_ID, 0, ok);
695  std::string action = attrs.hasAttribute("action") ? attrs.getStringSecure("action", "") : "";
696  if (action == "delete") {
697  myCurrentEdge = 0;
698  return;
699  }
700  if (!ok) {
701  myCurrentEdge = 0;
702  return;
703  }
704  myCurrentEdge = new Edge(id);
705  }
706  // parse "nd" (node) elements
707  if (element == SUMO_TAG_ND) {
708  bool ok = true;
709  long long int ref = attrs.get<long long int>(SUMO_ATTR_REF, 0, ok);
710  if (ok) {
711  std::map<long long int, NIOSMNode*>::const_iterator node = myOSMNodes.find(ref);
712  if (node == myOSMNodes.end()) {
713  WRITE_WARNING("The referenced geometry information (ref='" + toString(ref) + "') is not known");
714  return;
715  } else {
716  ref = node->second->id; // node may have been substituted
717  if (myCurrentEdge->myCurrentNodes.size() == 0 ||
718  myCurrentEdge->myCurrentNodes.back() != ref) { // avoid consecutive duplicates
719  myCurrentEdge->myCurrentNodes.push_back(ref);
720  }
721  }
722  }
723  }
724  // parse values
725  if (element == SUMO_TAG_TAG && myParentElements.size() > 2 && myParentElements[myParentElements.size() - 2] == SUMO_TAG_WAY) {
726  if (myCurrentEdge == 0) {
727  return;
728  }
729  bool ok = true;
730  std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myCurrentEdge->id).c_str(), ok, false);
731  if (key.size() > 8 && StringUtils::startsWith(key, "cycleway:")) {
732  // handle special busway keys
733  const std::string cyclewaySpec = key.substr(9);
734  key = "cycleway";
735  if (cyclewaySpec == "right") {
737  } else if (cyclewaySpec == "left") {
739  } else if (cyclewaySpec == "both") {
741  } else {
742  key = "ignore";
743  }
744  if ((myCurrentEdge->myCyclewayType & WAY_BOTH) != 0) {
745  // now we have some info on directionality
747  }
748  } else if (key.size() > 6 && StringUtils::startsWith(key, "busway:")) {
749  // handle special busway keys
750  const std::string buswaySpec = key.substr(7);
751  key = "busway";
752  if (buswaySpec == "right") {
754  } else if (buswaySpec == "left") {
756  } else if (buswaySpec == "both") {
758  } else {
759  key = "ignore";
760  }
761  }
762 
763  // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
764  if (!StringUtils::endsWith(key, "way") && !StringUtils::startsWith(key, "lanes") && key != "maxspeed" && key != "junction" && key != "name" && key != "tracks") {
765  return;
766  }
767  std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentEdge->id).c_str(), ok, false);
768 
769  if (key == "highway" || key == "railway" || key == "waterway" || key == "cycleway" || key == "busway") {
771  // special cycleway stuff
772  if (key == "cycleway") {
773  if (value == "no") {
774  return;
775  } else if (value == "opposite_track") {
777  } else if (value == "opposite_lane") {
779  }
780  }
781  // special busway stuff
782  if (key == "busway") {
783  if (value == "no") {
784  return;
785  } else if (value == "opposite_track") {
787  } else if (value == "opposite_lane") {
789  }
790  // no need to extend the type id
791  return;
792  }
793  // build type id
794  const std::string singleTypeID = key + "." + value;
795  if (myCurrentEdge->myHighWayType != "") {
796  // osm-ways may be used by more than one mode (eg railway.tram + highway.residential. this is relevant for multimodal traffic)
797  // we create a new type for this kind of situation which must then be resolved in insertEdge()
798  std::vector<std::string> types = StringTokenizer(myCurrentEdge->myHighWayType, compoundTypeSeparator).getVector();
799  types.push_back(singleTypeID);
801  } else {
802  myCurrentEdge->myHighWayType = singleTypeID;
803  }
804  } else if (key == "lanes") {
805  try {
806  myCurrentEdge->myNoLanes = TplConvert::_2int(value.c_str());
807  } catch (NumberFormatException&) {
808  // might be a list of values
809  StringTokenizer st(value, ";", true);
810  std::vector<std::string> list = st.getVector();
811  if (list.size() >= 2) {
812  int minLanes = std::numeric_limits<int>::max();
813  try {
814  for (std::vector<std::string>::iterator i = list.begin(); i != list.end(); ++i) {
815  int numLanes = TplConvert::_2int(StringUtils::prune(*i).c_str());
816  minLanes = MIN2(minLanes, numLanes);
817  }
818  myCurrentEdge->myNoLanes = minLanes;
819  WRITE_WARNING("Using minimum lane number from list (" + value + ") for edge '" + toString(myCurrentEdge->id) + "'.");
820  } catch (NumberFormatException&) {
821  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
822  toString(myCurrentEdge->id) + "'.");
823  }
824  }
825  } catch (EmptyData&) {
826  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
827  toString(myCurrentEdge->id) + "'.");
828  }
829  } else if (key == "lanes:forward") {
830  try {
832  } catch (...) {
833  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
834  toString(myCurrentEdge->id) + "'.");
835  }
836  } else if (key == "lanes:backward") {
837  try {
838  // denote backwards count with a negative sign
840  } catch (...) {
841  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
842  toString(myCurrentEdge->id) + "'.");
843  }
844  } else if (key == "maxspeed") {
845  if (mySpeedMap.find(value) != mySpeedMap.end()) {
847  } else {
848  SUMOReal conversion = 1; // OSM default is km/h
849  if (StringUtils::to_lower_case(value).find("km/h") != std::string::npos) {
850  value = StringUtils::prune(value.substr(0, value.find_first_not_of("0123456789")));
851  } else if (StringUtils::to_lower_case(value).find("mph") != std::string::npos) {
852  value = StringUtils::prune(value.substr(0, value.find_first_not_of("0123456789")));
853  conversion = 1.609344; // kilometers per mile
854  }
855  try {
856  myCurrentEdge->myMaxSpeed = TplConvert::_2SUMOReal(value.c_str()) * conversion;
857  } catch (...) {
858  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
859  toString(myCurrentEdge->id) + "'.");
860  }
861  }
862  } else if (key == "junction") {
863  if ((value == "roundabout") && (myCurrentEdge->myIsOneWay == "")) {
864  myCurrentEdge->myIsOneWay = "yes";
865  }
866  } else if (key == "oneway") {
867  myCurrentEdge->myIsOneWay = value;
868  } else if (key == "name") {
869  myCurrentEdge->streetName = value;
870  } else if (key == "tracks") {
871  try {
872  if (TplConvert::_2int(value.c_str()) > 1) {
873  myCurrentEdge->myIsOneWay = "false";
874  } else {
875  myCurrentEdge->myIsOneWay = "true";
876  }
877  } catch (...) {
878  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
879  toString(myCurrentEdge->id) + "'.");
880  }
881  }
882  }
883 }
884 
885 
886 void
888  myParentElements.pop_back();
889  if (element == SUMO_TAG_WAY) {
892  } else {
893  delete myCurrentEdge;
894  }
895  myCurrentEdge = 0;
896  }
897 }
898 
899 
900 // ---------------------------------------------------------------------------
901 // definitions of NIImporter_OpenStreetMap::RelationHandler-methods
902 // ---------------------------------------------------------------------------
904  const std::map<long long int, NIOSMNode*>& osmNodes,
905  const std::map<long long int, Edge*>& osmEdges) :
906  SUMOSAXHandler("osm - file"),
907  myOSMNodes(osmNodes),
908  myOSMEdges(osmEdges) {
909  resetValues();
910 }
911 
912 
914 }
915 
916 void
919  myIsRestriction = false;
925 }
926 
927 void
929  const SUMOSAXAttributes& attrs) {
930  myParentElements.push_back(element);
931  // parse "way" elements
932  if (element == SUMO_TAG_RELATION) {
933  bool ok = true;
934  myCurrentRelation = attrs.get<long long int>(SUMO_ATTR_ID, 0, ok);
935  std::string action = attrs.hasAttribute("action") ? attrs.getStringSecure("action", "") : "";
936  if (action == "delete" || !ok) {
938  }
939  return;
940  } else if (myCurrentRelation == INVALID_ID) {
941  return;
942  }
943  // parse member elements
944  if (element == SUMO_TAG_MEMBER) {
945  bool ok = true;
946  std::string role = attrs.hasAttribute("role") ? attrs.getStringSecure("role", "") : "";
947  long long int ref = attrs.get<long long int>(SUMO_ATTR_REF, 0, ok);
948  if (role == "via") {
949  // u-turns for divided ways may be given with 2 via-nodes or 1 via-way
950  std::string memberType = attrs.get<std::string>(SUMO_ATTR_TYPE, 0, ok);
951  if (memberType == "way" && checkEdgeRef(ref)) {
952  myViaWay = ref;
953  } else if (memberType == "node") {
954  if (myOSMNodes.find(ref) != myOSMNodes.end()) {
955  myViaNode = ref;
956  } else {
957  WRITE_WARNING("No node found for reference '" + toString(ref) + "' in relation '" + toString(myCurrentRelation) + "'");
958  }
959  }
960  } else if (role == "from" && checkEdgeRef(ref)) {
961  myFromWay = ref;
962  } else if (role == "to" && checkEdgeRef(ref)) {
963  myToWay = ref;
964  }
965  return;
966  }
967  // parse values
968  if (element == SUMO_TAG_TAG) {
969  bool ok = true;
970  std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myCurrentRelation).c_str(), ok, false);
971  // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
972  if (key == "type" || key == "restriction") {
973  std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
974  if (key == "type" && value == "restriction") {
975  myIsRestriction = true;
976  return;
977  }
978  if (key == "restriction") {
979  // @note: the 'right/left/straight' part is ignored since the information is
980  // redundantly encoded in the 'from', 'to' and 'via' members
981  if (value.substr(0, 5) == "only_") {
983  } else if (value.substr(0, 3) == "no_") {
985  } else {
986  WRITE_WARNING("Found unknown restriction type '" + value + "' in relation '" + toString(myCurrentRelation) + "'");
987  }
988  return;
989  }
990  }
991  }
992 }
993 
994 
995 bool
997  if (myOSMEdges.find(ref) != myOSMEdges.end()) {
998  return true;
999  } else {
1000  WRITE_WARNING("No way found for reference '" + toString(ref) + "' in relation '" + toString(myCurrentRelation) + "'");
1001  return false;
1002  }
1003 }
1004 
1005 
1006 void
1008  myParentElements.pop_back();
1009  if (element == SUMO_TAG_RELATION) {
1010  if (myIsRestriction) {
1011  assert(myCurrentRelation != INVALID_ID);
1012  bool ok = true;
1014  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "' with unknown type.");
1015  ok = false;
1016  }
1017  if (myFromWay == INVALID_ID) {
1018  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "' with unknown from-way.");
1019  ok = false;
1020  }
1021  if (myToWay == INVALID_ID) {
1022  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "' with unknown to-way.");
1023  ok = false;
1024  }
1025  if (myViaNode == INVALID_ID && myViaWay == INVALID_ID) {
1026  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "' with unknown via.");
1027  ok = false;
1028  }
1029  if (ok && !applyRestriction()) {
1030  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "'.");
1031  }
1032  }
1033  // other relations might use similar subelements so reset in any case
1034  resetValues();
1035  }
1036 }
1037 
1038 
1039 bool
1041  // since OSM ways are bidirectional we need the via to figure out which direction was meant
1042  if (myViaNode != INVALID_ID) {
1043  NBNode* viaNode = myOSMNodes.find(myViaNode)->second->node;
1044  if (viaNode == 0) {
1045  WRITE_WARNING("Via-node '" + toString(myViaNode) + "' was not instantiated");
1046  return false;
1047  }
1048  NBEdge* from = findEdgeRef(myFromWay, viaNode->getIncomingEdges());
1049  NBEdge* to = findEdgeRef(myToWay, viaNode->getOutgoingEdges());
1050  if (from == 0) {
1051  WRITE_WARNING("from-edge of restriction relation could not be determined");
1052  return false;
1053  }
1054  if (to == 0) {
1055  WRITE_WARNING("to-edge of restriction relation could not be determined");
1056  return false;
1057  }
1059  from->addEdge2EdgeConnection(to);
1060  } else {
1061  from->removeFromConnections(to, -1, -1, true);
1062  }
1063  } else {
1064  // XXX interpreting via-ways or via-node lists not yet implemented
1065  WRITE_WARNING("direction of restriction relation could not be determined");
1066  return false;
1067  }
1068  return true;
1069 }
1070 
1071 
1072 NBEdge*
1073 NIImporter_OpenStreetMap::RelationHandler::findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const {
1074  const std::string prefix = toString(wayRef);
1075  const std::string backPrefix = "-" + prefix;
1076  NBEdge* result = 0;
1077  int found = 0;
1078  for (EdgeVector::const_iterator it = candidates.begin(); it != candidates.end(); ++it) {
1079  if (((*it)->getID().substr(0, prefix.size()) == prefix) ||
1080  ((*it)->getID().substr(0, backPrefix.size()) == backPrefix)) {
1081  result = *it;
1082  found++;
1083  }
1084  }
1085  if (found > 1) {
1086  WRITE_WARNING("Ambigous way reference '" + prefix + "' in restriction relation");
1087  result = 0;
1088  }
1089  return result;
1090 }
1091 
1092 
1093 /****************************************************************************/
1094 
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
const SUMOReal lat
The latitude the node is located at.
An internal definition of a loaded edge.
const bool myImportElevation
whether elevation data should be imported
const std::map< long long int, Edge * > & myOSMEdges
The previously parsed edges.
An internal representation of an OSM-node.
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) ...
const EdgeVector & getIncomingEdges() const
Returns this node&#39;s incoming edges.
Definition: NBNode.h:240
const long long int id
The edge&#39;s id.
static const SUMOReal UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:201
std::string streetName
The edge&#39;s street name.
NBTypeCont & getTypeCont()
Returns the type container.
Definition: NBNetBuilder.h:170
const SUMOReal SUMO_const_laneWidth
Definition: StdDefs.h:49
std::string next()
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
static bool transformCoordinates(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
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:58
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.
static SUMOReal _2SUMOReal(const E *const data)
Definition: TplConvert.h:242
long long int myFromWay
the origination way for the current restriction
A container for traffic light definitions and built programs.
bool applyRestriction() const
try to apply the parsed restriction and return whether successful
void addSidewalk(SUMOReal width)
add a pedestrian sidewalk of the given width and shift existing connctions
Definition: NBEdge.cpp:2478
vehicle is a bicycle
void myEndElement(int element)
Called when a closing tag occurs.
int SVCPermissions
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
The representation of a single edge during network building.
Definition: NBEdge.h:70
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
static std::string escapeXML(const std::string &orig)
Replaces the standard escapes by their XML entities.
bool getIsOneWay(const std::string &type) const
Returns whether edges are one-way per default for the given type.
Definition: NBTypeCont.cpp:193
long long int myCurrentRelation
The currently parsed relation.
T MAX2(T a, T b)
Definition: StdDefs.h:75
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:2365
void myEndElement(int element)
Called when a closing tag occurs.
static const SUMOReal UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:203
SAX-handler base for SUMO-files.
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:114
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
SUMOReal getWidth(const std::string &type) const
Returns the lane width for the given type [m].
Definition: NBTypeCont.cpp:217
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
std::string joinToStringSorting(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:176
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
SUMOReal ele
The elevation of this node.
std::set< NIOSMNode *, CompareNodes > & myUniqueNodes
the set of unique nodes (used for duplicate detection/substitution)
NBNode * node
the NBNode that was instantiated
PositionVector reverse() const
static const SUMOReal MAXSPEED_UNGIVEN
SUMOReal getSidewalkWidth(const std::string &type) const
Returns the lane width for a sidewalk to be added [m].
Definition: NBTypeCont.cpp:223
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.
const EdgeVector & getOutgoingEdges() const
Returns this node&#39;s outgoing edges.
Definition: NBNode.h:248
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:660
const Position & getPosition() const
Returns the position of this node.
Definition: NBNode.h:228
RelationHandler(const std::map< long long int, NIOSMNode * > &osmNodes, const std::map< long long int, Edge * > &osmEdges)
Constructor.
#define max(a, b)
Definition: polyfonts.c:65
void load(const OptionsCont &oc, NBNetBuilder &nb)
SUMOReal getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
Definition: NBTypeCont.cpp:181
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.
SUMOReal getBikeLaneWidth(const std::string &type) const
Returns the lane width for a bike lane to be added [m].
Definition: NBTypeCont.cpp:229
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.
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:161
std::vector< int > myParentElements
The element stack.
Encapsulated SAX-Attributes.
static StringBijection< TrafficLightType > TrafficLightTypes
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
int getNumLanes(const std::string &type) const
Returns the number of lanes for the given type.
Definition: NBTypeCont.cpp:175
NBEdgeCont & getEdgeCont()
Returns the edge container.
Definition: NBNetBuilder.h:154
A list of positions.
int getPriority(const std::string &type) const
Returns the priority for the given type.
Definition: NBTypeCont.cpp:187
void myEndElement(int element)
Called when a closing tag occurs.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
T MIN2(T a, T b)
Definition: StdDefs.h:69
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
size_t size() const
long long int myLastNodeID
ID of the currently parsed node, for reporting mainly.
NodesHandler(std::map< long long int, NIOSMNode * > &toFill, std::set< NIOSMNode *, CompareNodes > &uniqueNodes, bool importElevation)
Contructor.
std::map< long long int, NIOSMNode * > & myToFill
The nodes container to fill.
bool myIsRestriction
whether the currently parsed relation is a restriction
bool knows(const std::string &type) const
Returns whether the named type is in the container.
Definition: NBTypeCont.cpp:75
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
void removeFromConnections(NBEdge *toEdge, int fromLane=-1, int toLane=-1, bool tryLater=false)
Removes the specified connection(s)
Definition: NBEdge.cpp:922
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
void insert(const std::string &id, int numLanes, SUMOReal maxSpeed, int prio, SVCPermissions permissions, SUMOReal width, bool oneWayIsDefault, SUMOReal sidewalkWidth, SUMOReal bikeLaneWidth)
Adds a type into the list.
Definition: NBTypeCont.cpp:61
bool checkEdgeRef(long long int ref) const
check whether a referenced way has a corresponding edge
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()
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
int myNoLanes
number of lanes, or -1 if unknown
vehicle is a bus
void addBikeLane(SUMOReal width)
add a bicycle lane of the given width and shift existing connctions
Definition: NBEdge.cpp:2484
static std::string to_lower_case(std::string str)
Transfers the content to lower case.
Definition: StringUtils.cpp:67
static int _2int(const E *const data)
Definition: TplConvert.h:114
bool tlsControlled
Whether this is a tls controlled junction.
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:56
EdgesHandler(const std::map< long long int, NIOSMNode * > &osmNodes, std::map< long long int, Edge * > &toFill)
Constructor.
std::map< long long int, Edge * > & myEdgeMap
A map of built edges.
const SUMOReal lon
The longitude the node is located at.
NBNodeCont & getNodeCont()
Returns the node container.
Definition: NBNetBuilder.h:162
long long int myToWay
the destination way for the current restriction
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
bool getShallBeDiscarded(const std::string &type) const
Returns the information whether edges of this type shall be discarded.
Definition: NBTypeCont.cpp:199
static const std::string compoundTypeSeparator
The separator within newly created compound type names.
std::map< std::string, SUMOReal > mySpeedMap
A map of non-numeric speed descriptions to their numeric values.
virtual std::string getStringSecure(int id, const std::string &def) const =0
Returns the string-value of the named (by its enum-value) attribute.
A storage for options typed value containers)
Definition: OptionsCont.h:108
long long int myViaNode
the via node/way for the current restriction
bool copyRestrictionsAndAttrs(const std::string &fromId, const std::string &toId)
Copy restrictions to a type.
Definition: NBTypeCont.cpp:114
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:80
NBTrafficLightLogicCont & getTLLogicCont()
Returns the traffic light logics container.
Definition: NBNetBuilder.h:178
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge&#39;s lateral offset shal...
NBEdge * findEdgeRef(long long int wayRef, const std::vector< NBEdge * > &candidates) const
try to find the way segment among candidates
A class which extracts OSM-nodes from a parsed OSM-file.
Represents a single node (junction) during network building.
Definition: NBNode.h:74
void resetValues()
reset members to their defaults for parsing a new relation
NBNode * insertNodeChecking(long long int id, NBNodeCont &nc, NBTrafficLightLogicCont &tlsc)
Builds an NBNode.
T get(const std::string &str) const
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:160
int myHierarchyLevel
The current hierarchy level.
std::string myHighWayType
The type, stored in "highway" key.
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
Importer for networks stored in OpenStreetMap format.
static const long long int INVALID_ID
#define SUMOReal
Definition: config.h:213
bool myCurrentIsRoad
Information whether this is a road.
bool operator()(const Edge *e1, const Edge *e2) const
Edge * myCurrentEdge
The currently built edge.
std::set< std::string > myUnusableTypes
The compounds types that do not contain known types.
void push_back_noDoublePos(const Position &p)
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:109
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Definition: NBTypeCont.cpp:211
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:64
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:203
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:54
std::vector< int > myParentElements
The element stack.
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
std::set< NIOSMNode *, CompareNodes > myUniqueNodes
the set of unique nodes used in NodesHandler, used when freeing memory
A class which extracts relevant relation information from a parsed OSM-file.
std::string myIsOneWay
Information whether this is an one-way road.
TrafficLightType
A storage for available types of edges.
Definition: NBTypeCont.h:62
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.