SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2015 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<SUMOLong, 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  // preset types
137  // for highways
138  NBTypeCont& tc = nb.getTypeCont();
139  SUMOReal const WIDTH = NBEdge::UNSPECIFIED_WIDTH;
140  tc.insert("highway.motorway", 2, (SUMOReal)(160. / 3.6), 13, WIDTH, SVC_IGNORING, true);
141  tc.insert("highway.motorway_link", 1, (SUMOReal)(80. / 3.6), 12, WIDTH, SVC_IGNORING, true);
142  tc.insert("highway.trunk", 2, (SUMOReal)(100. / 3.6), 11, WIDTH); // !!! 130km/h?
143  tc.insert("highway.trunk_link", 1, (SUMOReal)(80. / 3.6), 10, WIDTH);
144  tc.insert("highway.primary", 2, (SUMOReal)(100. / 3.6), 9, WIDTH);
145  tc.insert("highway.primary_link", 1, (SUMOReal)(80. / 3.6), 8, WIDTH);
146  tc.insert("highway.secondary", 2, (SUMOReal)(100. / 3.6), 7, WIDTH);
147  tc.insert("highway.secondary_link", 1, (SUMOReal)(80. / 3.6), 6, WIDTH);
148  tc.insert("highway.tertiary", 1, (SUMOReal)(80. / 3.6), 6, WIDTH);
149  tc.insert("highway.tertiary_link", 1, (SUMOReal)(80. / 3.6), 5, WIDTH);
150  tc.insert("highway.unclassified", 1, (SUMOReal)(80. / 3.6), 5, WIDTH);
151  tc.insert("highway.residential", 1, (SUMOReal)(50. / 3.6), 4, WIDTH); // actually, maybe one lane for parking would be nice...
152  tc.insert("highway.living_street", 1, (SUMOReal)(10. / 3.6), 3, WIDTH);
153  tc.insert("highway.service", 1, (SUMOReal)(20. / 3.6), 2, WIDTH, SVC_DELIVERY);
154  tc.insert("highway.track", 1, (SUMOReal)(20. / 3.6), 1, WIDTH);
155  tc.insert("highway.services", 1, (SUMOReal)(30. / 3.6), 1, WIDTH); // service area i.e. on a motorway
156  tc.insert("highway.unsurfaced", 1, (SUMOReal)(30. / 3.6), 1, WIDTH); // unofficial value, used outside germany
157 
158  tc.insert("highway.pedestrian", 1, (SUMOReal)(30. / 3.6), 1, WIDTH, SVC_PEDESTRIAN, true);
159  tc.insert("highway.path", 1, (SUMOReal)(10. / 3.6), 1, WIDTH, SVC_PEDESTRIAN, true);
160  tc.insert("highway.bridleway", 1, (SUMOReal)(10. / 3.6), 1, WIDTH, SVC_BICYCLE); // no horse stuff
161  tc.insert("highway.cycleway", 1, (SUMOReal)(20. / 3.6), 1, WIDTH, SVC_BICYCLE);
162  tc.insert("highway.footway", 1, (SUMOReal)(10. / 3.6), 1, WIDTH, SVC_PEDESTRIAN, true);
163  tc.insert("highway.step", 1, (SUMOReal)(5. / 3.6), 1, WIDTH, SVC_PEDESTRIAN, true); // additional
164  tc.insert("highway.steps", 1, (SUMOReal)(5. / 3.6), 1, WIDTH, SVC_PEDESTRIAN, true); // :-) do not run too fast
165  tc.insert("highway.stairs", 1, (SUMOReal)(5. / 3.6), 1, WIDTH, SVC_PEDESTRIAN, true); // additional
166  tc.insert("highway.bus_guideway", 1, (SUMOReal)(30. / 3.6), 1, WIDTH, SVC_BUS);
167  tc.insert("highway.raceway", 2, (SUMOReal)(300. / 3.6), 14, WIDTH, SVC_VIP);
168  tc.insert("highway.ford", 1, (SUMOReal)(10. / 3.6), 1, WIDTH, SVC_ARMY);
169 
170  // for railways
171  const bool oneWay = oc.getBool("osm.railway.oneway-default");
172  tc.insert("railway.rail", 1, (SUMOReal)(300. / 3.6), 15, WIDTH, SVC_RAIL, oneWay);
173  tc.insert("railway.tram", 1, (SUMOReal)(100. / 3.6), 15, WIDTH, SVC_TRAM, oneWay);
174  tc.insert("railway.light_rail", 1, (SUMOReal)(100. / 3.6), 15, WIDTH, SVC_RAIL_URBAN, oneWay); // might also correspond to higher standard trams
175  tc.insert("railway.subway", 1, (SUMOReal)(100. / 3.6), 15, WIDTH, SVC_RAIL_URBAN, oneWay);
176  tc.insert("railway.preserved", 1, (SUMOReal)(100. / 3.6), 15, WIDTH, SVC_RAIL, oneWay);
177 
178 
179  /* Parse file(s)
180  * Each file is parsed twice: first for nodes, second for edges. */
181  std::vector<std::string> files = oc.getStringVector("osm-files");
182  // load nodes, first
183  NodesHandler nodesHandler(myOSMNodes, myUniqueNodes, oc.getBool("osm.elevation"));
184  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
185  // nodes
186  if (!FileHelpers::isReadable(*file)) {
187  WRITE_ERROR("Could not open osm-file '" + *file + "'.");
188  return;
189  }
190  nodesHandler.setFileName(*file);
191  PROGRESS_BEGIN_MESSAGE("Parsing nodes from osm-file '" + *file + "'");
192  if (!XMLSubSys::runParser(nodesHandler, *file)) {
193  return;
194  }
196  }
197  // load edges, then
198  EdgesHandler edgesHandler(myOSMNodes, myEdges);
199  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
200  // edges
201  edgesHandler.setFileName(*file);
202  PROGRESS_BEGIN_MESSAGE("Parsing edges from osm-file '" + *file + "'");
203  XMLSubSys::runParser(edgesHandler, *file);
205  }
206 
207  /* Remove duplicate edges with the same shape and attributes */
208  if (!oc.getBool("osm.skip-duplicates-check")) {
209  PROGRESS_BEGIN_MESSAGE("Removing duplicate edges");
210  if (myEdges.size() > 1) {
211  std::set<const Edge*, CompareEdges> dupsFinder;
212  for (std::map<SUMOLong, Edge*>::iterator it = myEdges.begin(); it != myEdges.end();) {
213  if (dupsFinder.count(it->second) > 0) {
214  WRITE_MESSAGE("Found duplicate edges. Removing " + toString(it->first));
215  delete it->second;
216  myEdges.erase(it++);
217  } else {
218  dupsFinder.insert(it->second);
219  it++;
220  }
221  }
222  }
224  }
225 
226  /* Mark which nodes are used (by edges or traffic lights).
227  * This is necessary to detect which OpenStreetMap nodes are for
228  * geometry only */
229  std::map<SUMOLong, int> nodeUsage;
230  // Mark which nodes are used by edges (begin and end)
231  for (std::map<SUMOLong, Edge*>::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
232  Edge* e = (*i).second;
233  assert(e->myCurrentIsRoad);
234  for (std::vector<SUMOLong>::const_iterator j = e->myCurrentNodes.begin(); j != e->myCurrentNodes.end(); ++j) {
235  if (nodeUsage.find(*j) == nodeUsage.end()) {
236  nodeUsage[*j] = 0;
237  }
238  nodeUsage[*j] = nodeUsage[*j] + 1;
239  }
240  }
241  // Mark which nodes are used by traffic lights
242  for (std::map<SUMOLong, NIOSMNode*>::const_iterator nodesIt = myOSMNodes.begin(); nodesIt != myOSMNodes.end(); ++nodesIt) {
243  if (nodesIt->second->tlsControlled) {
244  // If the key is not found in the map, the value is automatically
245  // initialized with 0.
246  nodeUsage[nodesIt->first] += 1;
247  }
248  }
249  /* Instantiate edges
250  * Only those nodes in the middle of an edge which are used by more than
251  * one edge are instantiated. Other nodes are considered as geometry nodes. */
252  NBNodeCont& nc = nb.getNodeCont();
254  for (std::map<SUMOLong, Edge*>::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
255  Edge* e = (*i).second;
256  assert(e->myCurrentIsRoad);
257  if (e->myCurrentNodes.size() < 2) {
258  WRITE_WARNING("Discarding way '" + toString(e->id) + "' because it has only " +
259  toString(e->myCurrentNodes.size()) + " node(s)");
260  continue;
261  }
262  // build nodes;
263  // - the from- and to-nodes must be built in any case
264  // - the in-between nodes are only built if more than one edge references them
265  NBNode* currentFrom = insertNodeChecking(*e->myCurrentNodes.begin(), nc, tlsc);
266  NBNode* last = insertNodeChecking(*(e->myCurrentNodes.end() - 1), nc, tlsc);
267  int running = 0;
268  std::vector<SUMOLong> passed;
269  for (std::vector<SUMOLong>::iterator j = e->myCurrentNodes.begin(); j != e->myCurrentNodes.end(); ++j) {
270  passed.push_back(*j);
271  if (nodeUsage[*j] > 1 && j != e->myCurrentNodes.end() - 1 && j != e->myCurrentNodes.begin()) {
272  NBNode* currentTo = insertNodeChecking(*j, nc, tlsc);
273  running = insertEdge(e, running, currentFrom, currentTo, passed, nb);
274  currentFrom = currentTo;
275  passed.clear();
276  }
277  }
278  if (running == 0) {
279  running = -1;
280  }
281  insertEdge(e, running, currentFrom, last, passed, nb);
282  }
283 
284  // load relations (after edges are built since we want to apply
285  // turn-restrictions directly to NBEdges)
286  RelationHandler relationHandler(myOSMNodes, myEdges);
287  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
288  // relations
289  relationHandler.setFileName(*file);
290  PROGRESS_BEGIN_MESSAGE("Parsing relations from osm-file '" + *file + "'");
291  XMLSubSys::runParser(relationHandler, *file);
293  }
294 }
295 
296 
297 NBNode*
299  NBNode* node = nc.retrieve(toString(id));
300  if (node == 0) {
301  NIOSMNode* n = myOSMNodes.find(id)->second;
302  Position pos(n->lon, n->lat, n->ele);
303  if (!NBNetBuilder::transformCoordinates(pos, true)) {
304  WRITE_ERROR("Unable to project coordinates for node " + toString(id) + ".");
305  return 0;
306  }
307  node = new NBNode(toString(id), pos);
308  if (!nc.insert(node)) {
309  WRITE_ERROR("Could not insert node '" + toString(id) + "').");
310  delete node;
311  return 0;
312  }
313  n->node = node;
314  if (n->tlsControlled) {
315  // ok, this node is a traffic light node where no other nodes
316  // participate
317  // @note: The OSM-community has not settled on a schema for differentiating between fixed and actuated lights
319  NBOwnTLDef* tlDef = new NBOwnTLDef(toString(id), node, 0, type);
320  if (!tlsc.insert(tlDef)) {
321  // actually, nothing should fail here
322  delete tlDef;
323  throw ProcessError("Could not allocate tls '" + toString(id) + "'.");
324  }
325  }
326  }
327  return node;
328 }
329 
330 
331 int
333  const std::vector<SUMOLong>& passed, NBNetBuilder& nb) {
334  NBNodeCont& nc = nb.getNodeCont();
335  NBEdgeCont& ec = nb.getEdgeCont();
336  NBTypeCont& tc = nb.getTypeCont();
338  // patch the id
339  std::string id = toString(e->id);
340  if (from == 0 || to == 0) {
341  WRITE_ERROR("Discarding edge " + id + " because the nodes could not be built.");
342  return index;
343  }
344  if (index >= 0) {
345  id = id + "#" + toString(index);
346  } else {
347  index = 0;
348  }
349  if (from == to) {
350  // in the special case of a looped way split again using passed
351  assert(passed.size() >= 2);
352  std::vector<SUMOLong> geom(passed);
353  geom.pop_back(); // remove to-node
354  NBNode* intermediate = insertNodeChecking(geom.back(), nc, tlsc);
355  index = insertEdge(e, index, from, intermediate, geom, nb);
356  geom.clear();
357  return insertEdge(e, index, intermediate, to, geom, nb);
358  }
359  const int newIndex = index + 1;
360 
361  // convert the shape
362  PositionVector shape;
363  shape.push_back(from->getPosition());
364  for (std::vector<SUMOLong>::const_iterator i = passed.begin(); i != passed.end(); ++i) {
365  NIOSMNode* n = myOSMNodes.find(*i)->second;
366  Position pos(n->lon, n->lat, n->ele);
367  if (!NBNetBuilder::transformCoordinates(pos, true)) {
368  WRITE_ERROR("Unable to project coordinates for edge " + id + ".");
369  }
370  shape.push_back_noDoublePos(pos);
371  }
372  shape.push_back_noDoublePos(to->getPosition());
373 
374  std::string type = e->myHighWayType;
375  if (!tc.knows(type)) {
376  if (myUnusableTypes.count(type) > 0) {
377  return newIndex;
378  } else if (myKnownCompoundTypes.count(type) > 0) {
379  type = myKnownCompoundTypes[type];
380  } else {
381  // this edge has a type which does not yet exist in the TypeContainer
383  std::vector<std::string> types;
384  while (tok.hasNext()) {
385  std::string t = tok.next();
386  if (tc.knows(t)) {
387  if (std::find(types.begin(), types.end(), t) == types.end()) {
388  types.push_back(t);
389  }
390  } else if (tok.size() > 1) {
391  WRITE_WARNING("Discarding unknown compound \"" + t + "\" in type \"" + type + "\" (first occurence for edge \"" + id + "\").");
392  }
393  }
394  if (types.size() == 0) {
395  WRITE_WARNING("Discarding unusable type \"" + type + "\" (first occurence for edge \"" + id + "\").");
396  myUnusableTypes.insert(type);
397  return newIndex;
398  } else {
399  const std::string newType = joinToString(types, "|");
400  if (tc.knows(newType)) {
401  myKnownCompoundTypes[type] = newType;
402  type = newType;
403  } else if (myKnownCompoundTypes.count(newType) > 0) {
404  type = myKnownCompoundTypes[newType];
405  } else {
406  // build a new type by merging all values
407  int numLanes = 0;
408  SUMOReal maxSpeed = 0;
409  int prio = 0;
411  SUMOReal sidewalkWidth = NBEdge::UNSPECIFIED_WIDTH;
412  bool defaultIsOneWay = false;
413  SVCPermissions permissions = 0;
414  bool discard = true;
415  for (std::vector<std::string>::iterator it = types.begin(); it != types.end(); it++) {
416  if (!tc.getShallBeDiscarded(*it)) {
417  numLanes = MAX2(numLanes, tc.getNumLanes(*it));
418  maxSpeed = MAX2(maxSpeed, tc.getSpeed(*it));
419  prio = MAX2(prio, tc.getPriority(*it));
420  defaultIsOneWay &= tc.getIsOneWay(*it);
421  permissions |= tc.getPermissions(*it);
422  width = MAX2(width, tc.getWidth(*it));
423  sidewalkWidth = MAX2(sidewalkWidth, tc.getSidewalkWidth(*it));
424  discard = false;
425  }
426  }
427  if (width != NBEdge::UNSPECIFIED_WIDTH) {
428  width = MAX2(width, SUMO_const_laneWidth);
429  }
430  if (discard) {
431  WRITE_WARNING("Discarding compound type \"" + newType + "\" (first occurence for edge \"" + id + "\").");
432  myUnusableTypes.insert(newType);
433  return newIndex;
434  } else {
435  WRITE_MESSAGE("Adding new type \"" + type + "\" (first occurence for edge \"" + id + "\").");
436  tc.insert(newType, numLanes, maxSpeed, prio, permissions, width, defaultIsOneWay, sidewalkWidth);
437  myKnownCompoundTypes[type] = newType;
438  type = newType;
439  }
440  }
441  }
442  }
443  }
444 
445  // otherwise it is not an edge and will be ignored
446  bool ok = true;
447  int numLanesForward = tc.getNumLanes(type);
448  int numLanesBackward = tc.getNumLanes(type);
449  SUMOReal speed = tc.getSpeed(type);
450  bool defaultsToOneWay = tc.getIsOneWay(type);
451  SVCPermissions permissions = tc.getPermissions(type);
452  const bool addSidewalk = (tc.getSidewalkWidth(type) != NBEdge::UNSPECIFIED_WIDTH);
453  // check directions
454  bool addForward = true;
455  bool addBackward = true;
456  if (e->myIsOneWay == "true" || e->myIsOneWay == "yes" || e->myIsOneWay == "1" || (defaultsToOneWay && e->myIsOneWay != "no" && e->myIsOneWay != "false" && e->myIsOneWay != "0")) {
457  addBackward = false;
458  }
459  if (e->myIsOneWay == "-1" || e->myIsOneWay == "reverse") {
460  // one-way in reversed direction of way
461  addForward = false;
462  addBackward = true;
463  }
464  if (e->myIsOneWay != "" && e->myIsOneWay != "false" && e->myIsOneWay != "no" && e->myIsOneWay != "true" && e->myIsOneWay != "yes" && e->myIsOneWay != "-1" && e->myIsOneWay != "1" && e->myIsOneWay != "reverse") {
465  WRITE_WARNING("New value for oneway found: " + e->myIsOneWay);
466  }
467  // if we had been able to extract the number of lanes, override the highway type default
468  if (e->myNoLanes > 0) {
469  if (addForward && !addBackward) {
470  numLanesForward = e->myNoLanes;
471  } else if (!addForward && addBackward) {
472  numLanesBackward = e->myNoLanes;
473  } else {
474  if (e->myNoLanesForward > 0) {
475  numLanesForward = e->myNoLanesForward;
476  } else if (e->myNoLanesForward < 0) {
477  numLanesForward = e->myNoLanes + e->myNoLanesForward;
478  } else {
479  numLanesForward = (int)std::ceil(e->myNoLanes / 2.0);
480  }
481  numLanesBackward = e->myNoLanes - numLanesForward;
482  // sometimes ways are tagged according to their physical width of a single
483  // lane but they are intended for traffic in both directions
484  numLanesForward = MAX2(1, numLanesForward);
485  numLanesBackward = MAX2(1, numLanesBackward);
486  }
487  } else if (e->myNoLanes == 0) {
488  WRITE_WARNING("Skipping edge '" + id + "' because it has zero lanes.");
489  ok = false;
490  }
491  // if we had been able to extract the maximum speed, override the type's default
492  if (e->myMaxSpeed != MAXSPEED_UNGIVEN) {
493  speed = (SUMOReal)(e->myMaxSpeed / 3.6);
494  }
495  if (speed <= 0) {
496  WRITE_WARNING("Skipping edge '" + id + "' because it has speed " + toString(speed));
497  ok = false;
498  }
499  if (ok) {
501  if (addForward) {
502  assert(numLanesForward > 0);
503  NBEdge* nbe = new NBEdge(StringUtils::escapeXML(id), from, to, type, speed, numLanesForward, tc.getPriority(type),
504  tc.getWidth(type), NBEdge::UNSPECIFIED_OFFSET, shape, StringUtils::escapeXML(e->streetName), lsf, true);
505  nbe->setPermissions(permissions);
506  if (addSidewalk) {
507  nbe->addSidewalk(tc.getSidewalkWidth(type));
508  }
509  if (!ec.insert(nbe)) {
510  delete nbe;
511  throw ProcessError("Could not add edge '" + id + "'.");
512  }
513  id = "-" + id;
514  }
515  if (addBackward) {
516  assert(numLanesBackward > 0);
517  NBEdge* nbe = new NBEdge(StringUtils::escapeXML(id), to, from, type, speed, numLanesBackward, tc.getPriority(type),
519  nbe->setPermissions(permissions);
520  if (addSidewalk) {
521  nbe->addSidewalk(tc.getSidewalkWidth(type));
522  }
523  if (!ec.insert(nbe)) {
524  delete nbe;
525  throw ProcessError("Could not add edge " + id + "'.");
526  }
527  }
528  }
529  return newIndex;
530 }
531 
532 
533 // ---------------------------------------------------------------------------
534 // definitions of NIImporter_OpenStreetMap::NodesHandler-methods
535 // ---------------------------------------------------------------------------
537  std::map<SUMOLong, NIOSMNode*>& toFill,
538  std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
539  bool importElevation) :
540  SUMOSAXHandler("osm - file"),
541  myToFill(toFill),
542  myLastNodeID(-1),
543  myIsInValidNodeTag(false),
544  myHierarchyLevel(0),
545  myUniqueNodes(uniqueNodes),
546  myImportElevation(importElevation)
547 { }
548 
549 
551 
552 
553 void
555  ++myHierarchyLevel;
556  if (element == SUMO_TAG_NODE) {
557  bool ok = true;
558  if (myHierarchyLevel != 2) {
559  WRITE_ERROR("Node element on wrong XML hierarchy level (id='" + toString(attrs.get<SUMOLong>(SUMO_ATTR_ID, 0, ok)) + "', level='" + toString(myHierarchyLevel) + "').");
560  return;
561  }
562  SUMOLong id = attrs.get<SUMOLong>(SUMO_ATTR_ID, 0, ok);
563  std::string action = attrs.hasAttribute("action") ? attrs.getStringSecure("action", "") : "";
564  if (action == "delete") {
565  return;
566  }
567  if (!ok) {
568  return;
569  }
570  myLastNodeID = -1;
571  if (myToFill.find(id) == myToFill.end()) {
572  myLastNodeID = id;
573  // assume we are loading multiple files...
574  // ... so we won't report duplicate nodes
575  bool ok = true;
576  double tlat, tlon;
577  std::istringstream lon(attrs.get<std::string>(SUMO_ATTR_LON, toString(id).c_str(), ok));
578  if (!ok) {
579  return;
580  }
581  lon >> tlon;
582  if (lon.fail()) {
583  WRITE_ERROR("Node's '" + toString(id) + "' lon information is not numeric.");
584  return;
585  }
586  std::istringstream lat(attrs.get<std::string>(SUMO_ATTR_LAT, toString(id).c_str(), ok));
587  if (!ok) {
588  return;
589  }
590  lat >> tlat;
591  if (lat.fail()) {
592  WRITE_ERROR("Node's '" + toString(id) + "' lat information is not numeric.");
593  return;
594  }
595  NIOSMNode* toAdd = new NIOSMNode(id, tlon, tlat);
596  myIsInValidNodeTag = true;
597 
598  std::set<NIOSMNode*, CompareNodes>::iterator similarNode = myUniqueNodes.find(toAdd);
599  if (similarNode == myUniqueNodes.end()) {
600  myUniqueNodes.insert(toAdd);
601  } else {
602  delete toAdd;
603  toAdd = *similarNode;
604  WRITE_MESSAGE("Found duplicate nodes. Substituting " + toString(id) + " with " + toString(toAdd->id));
605  }
606  myToFill[id] = toAdd;
607  }
608  }
609  if (element == SUMO_TAG_TAG && myIsInValidNodeTag) {
610  if (myHierarchyLevel != 3) {
611  WRITE_ERROR("Tag element on wrong XML hierarchy level.");
612  return;
613  }
614  bool ok = true;
615  std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myLastNodeID).c_str(), ok, false);
616  // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
617  if (key == "highway" || key == "ele") {
618  std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myLastNodeID).c_str(), ok, false);
619  if (key == "highway" && value.find("traffic_signal") != std::string::npos) {
620  myToFill[myLastNodeID]->tlsControlled = true;
621  } else if (myImportElevation && key == "ele") {
622  try {
623  myToFill[myLastNodeID]->ele = TplConvert::_2SUMOReal(value.c_str());
624  } catch (...) {
625  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in node '" +
626  toString(myLastNodeID) + "'.");
627  }
628  }
629  }
630  }
631 }
632 
633 
634 void
636  if (element == SUMO_TAG_NODE && myHierarchyLevel == 2) {
637  myLastNodeID = -1;
638  myIsInValidNodeTag = false;
639  }
640  --myHierarchyLevel;
641 }
642 
643 
644 // ---------------------------------------------------------------------------
645 // definitions of NIImporter_OpenStreetMap::EdgesHandler-methods
646 // ---------------------------------------------------------------------------
648  const std::map<SUMOLong, NIOSMNode*>& osmNodes,
649  std::map<SUMOLong, Edge*>& toFill) :
650  SUMOSAXHandler("osm - file"),
651  myOSMNodes(osmNodes),
652  myEdgeMap(toFill) {
653  mySpeedMap["signals"] = MAXSPEED_UNGIVEN;
654  mySpeedMap["none"] = 300.;
655  mySpeedMap["no"] = 300.;
656  mySpeedMap["walk"] = 5.;
657  mySpeedMap["DE:rural"] = 100.;
658  mySpeedMap["DE:urban"] = 50.;
659  mySpeedMap["DE:living_street"] = 10.;
660 
661 }
662 
663 
665 }
666 
667 
668 void
670  const SUMOSAXAttributes& attrs) {
671  myParentElements.push_back(element);
672  // parse "way" elements
673  if (element == SUMO_TAG_WAY) {
674  bool ok = true;
675  SUMOLong id = attrs.get<SUMOLong>(SUMO_ATTR_ID, 0, ok);
676  std::string action = attrs.hasAttribute("action") ? attrs.getStringSecure("action", "") : "";
677  if (action == "delete") {
678  myCurrentEdge = 0;
679  return;
680  }
681  if (!ok) {
682  myCurrentEdge = 0;
683  return;
684  }
685  myCurrentEdge = new Edge(id);
686  }
687  // parse "nd" (node) elements
688  if (element == SUMO_TAG_ND) {
689  bool ok = true;
690  SUMOLong ref = attrs.get<SUMOLong>(SUMO_ATTR_REF, 0, ok);
691  if (ok) {
692  std::map<SUMOLong, NIOSMNode*>::const_iterator node = myOSMNodes.find(ref);
693  if (node == myOSMNodes.end()) {
694  WRITE_WARNING("The referenced geometry information (ref='" + toString(ref) + "') is not known");
695  return;
696  } else {
697  ref = node->second->id; // node may have been substituted
698  if (myCurrentEdge->myCurrentNodes.size() == 0 ||
699  myCurrentEdge->myCurrentNodes.back() != ref) { // avoid consecutive duplicates
700  myCurrentEdge->myCurrentNodes.push_back(ref);
701  }
702  }
703  }
704  }
705  // parse values
706  if (element == SUMO_TAG_TAG && myParentElements.size() > 2 && myParentElements[myParentElements.size() - 2] == SUMO_TAG_WAY) {
707  if (myCurrentEdge == 0) {
708  return;
709  }
710  bool ok = true;
711  std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myCurrentEdge->id).c_str(), ok, false);
712  // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
713  if (!StringUtils::endsWith(key, "way") && !StringUtils::startsWith(key, "lanes") && key != "maxspeed" && key != "junction" && key != "name" && key != "tracks") {
714  return;
715  }
716  std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentEdge->id).c_str(), ok, false);
717 
718  if (key == "highway" || key == "railway" || key == "waterway") {
719  const std::string singleTypeID = key + "." + value;
720  if (myCurrentEdge->myHighWayType != "") {
721  // osm-ways may be used by more than one mode (eg railway.tram + highway.residential. this is relevant for multimodal traffic)
722  // we create a new type for this kind of situation which must then be resolved in insertEdge()
723  myCurrentEdge->myHighWayType = myCurrentEdge->myHighWayType + compoundTypeSeparator + singleTypeID;
724  } else {
725  myCurrentEdge->myHighWayType = singleTypeID;
726  }
727  myCurrentEdge->myCurrentIsRoad = true;
728  } else if (key == "lanes") {
729  try {
730  myCurrentEdge->myNoLanes = TplConvert::_2int(value.c_str());
731  } catch (NumberFormatException&) {
732  // might be a list of values
733  StringTokenizer st(value, ";", true);
734  std::vector<std::string> list = st.getVector();
735  if (list.size() >= 2) {
736  int minLanes = std::numeric_limits<int>::max();
737  try {
738  for (std::vector<std::string>::iterator i = list.begin(); i != list.end(); ++i) {
739  int numLanes = TplConvert::_2int(StringUtils::prune(*i).c_str());
740  minLanes = MIN2(minLanes, numLanes);
741  }
742  myCurrentEdge->myNoLanes = minLanes;
743  WRITE_WARNING("Using minimum lane number from list (" + value + ") for edge '" + toString(myCurrentEdge->id) + "'.");
744  } catch (NumberFormatException&) {
745  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
746  toString(myCurrentEdge->id) + "'.");
747  }
748  }
749  } catch (EmptyData&) {
750  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
751  toString(myCurrentEdge->id) + "'.");
752  }
753  } else if (key == "lanes:forward") {
754  try {
755  myCurrentEdge->myNoLanesForward = TplConvert::_2int(value.c_str());
756  } catch (...) {
757  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
758  toString(myCurrentEdge->id) + "'.");
759  }
760  } else if (key == "lanes:backward") {
761  try {
762  // denote backwards count with a negative sign
763  myCurrentEdge->myNoLanesForward = -TplConvert::_2int(value.c_str());
764  } catch (...) {
765  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
766  toString(myCurrentEdge->id) + "'.");
767  }
768  } else if (key == "maxspeed") {
769  if (mySpeedMap.find(value) != mySpeedMap.end()) {
770  myCurrentEdge->myMaxSpeed = mySpeedMap[value];
771  } else {
772  SUMOReal conversion = 1; // OSM default is km/h
773  if (StringUtils::to_lower_case(value).find("km/h") != std::string::npos) {
774  value = StringUtils::prune(value.substr(0, value.find_first_not_of("0123456789")));
775  } else if (StringUtils::to_lower_case(value).find("mph") != std::string::npos) {
776  value = StringUtils::prune(value.substr(0, value.find_first_not_of("0123456789")));
777  conversion = 1.609344; // kilometers per mile
778  }
779  try {
780  myCurrentEdge->myMaxSpeed = TplConvert::_2SUMOReal(value.c_str()) * conversion;
781  } catch (...) {
782  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
783  toString(myCurrentEdge->id) + "'.");
784  }
785  }
786  } else if (key == "junction") {
787  if ((value == "roundabout") && (myCurrentEdge->myIsOneWay == "")) {
788  myCurrentEdge->myIsOneWay = "yes";
789  }
790  } else if (key == "oneway") {
791  myCurrentEdge->myIsOneWay = value;
792  } else if (key == "name") {
793  myCurrentEdge->streetName = value;
794  } else if (key == "tracks") {
795  try {
796  if (TplConvert::_2int(value.c_str()) > 1) {
797  myCurrentEdge->myIsOneWay = "false";
798  } else {
799  myCurrentEdge->myIsOneWay = "true";
800  }
801  } catch (...) {
802  WRITE_WARNING("Value of key '" + key + "' is not numeric ('" + value + "') in edge '" +
803  toString(myCurrentEdge->id) + "'.");
804  }
805  }
806  }
807 }
808 
809 
810 void
812  myParentElements.pop_back();
813  if (element == SUMO_TAG_WAY) {
814  if (myCurrentEdge != 0 && myCurrentEdge->myCurrentIsRoad) {
815  myEdgeMap[myCurrentEdge->id] = myCurrentEdge;
816  } else {
817  delete myCurrentEdge;
818  }
819  myCurrentEdge = 0;
820  }
821 }
822 
823 
824 // ---------------------------------------------------------------------------
825 // definitions of NIImporter_OpenStreetMap::RelationHandler-methods
826 // ---------------------------------------------------------------------------
828  const std::map<SUMOLong, NIOSMNode*>& osmNodes,
829  const std::map<SUMOLong, Edge*>& osmEdges) :
830  SUMOSAXHandler("osm - file"),
831  myOSMNodes(osmNodes),
832  myOSMEdges(osmEdges) {
833  resetValues();
834 }
835 
836 
838 }
839 
840 void
842  myCurrentRelation = INVALID_ID;
843  myIsRestriction = false;
844  myFromWay = INVALID_ID;
845  myToWay = INVALID_ID;
846  myViaNode = INVALID_ID;
847  myViaWay = INVALID_ID;
848  myRestrictionType = RESTRICTION_UNKNOWN;
849 }
850 
851 void
853  const SUMOSAXAttributes& attrs) {
854  myParentElements.push_back(element);
855  // parse "way" elements
856  if (element == SUMO_TAG_RELATION) {
857  bool ok = true;
858  myCurrentRelation = attrs.get<SUMOLong>(SUMO_ATTR_ID, 0, ok);
859  std::string action = attrs.hasAttribute("action") ? attrs.getStringSecure("action", "") : "";
860  if (action == "delete" || !ok) {
861  myCurrentRelation = INVALID_ID;
862  }
863  return;
864  } else if (myCurrentRelation == INVALID_ID) {
865  return;
866  }
867  // parse member elements
868  if (element == SUMO_TAG_MEMBER) {
869  bool ok = true;
870  std::string role = attrs.hasAttribute("role") ? attrs.getStringSecure("role", "") : "";
871  SUMOLong ref = attrs.get<SUMOLong>(SUMO_ATTR_REF, 0, ok);
872  if (role == "via") {
873  // u-turns for divided ways may be given with 2 via-nodes or 1 via-way
874  std::string memberType = attrs.get<std::string>(SUMO_ATTR_TYPE, 0, ok);
875  if (memberType == "way" && checkEdgeRef(ref)) {
876  myViaWay = ref;
877  } else if (memberType == "node") {
878  if (myOSMNodes.find(ref) != myOSMNodes.end()) {
879  myViaNode = ref;
880  } else {
881  WRITE_WARNING("No node found for reference '" + toString(ref) + "' in relation '" + toString(myCurrentRelation) + "'");
882  }
883  }
884  } else if (role == "from" && checkEdgeRef(ref)) {
885  myFromWay = ref;
886  } else if (role == "to" && checkEdgeRef(ref)) {
887  myToWay = ref;
888  }
889  return;
890  }
891  // parse values
892  if (element == SUMO_TAG_TAG) {
893  bool ok = true;
894  std::string key = attrs.get<std::string>(SUMO_ATTR_K, toString(myCurrentRelation).c_str(), ok, false);
895  // we check whether the key is relevant (and we really need to transcode the value) to avoid hitting #1636
896  if (key == "type" || key == "restriction") {
897  std::string value = attrs.get<std::string>(SUMO_ATTR_V, toString(myCurrentRelation).c_str(), ok, false);
898  if (key == "type" && value == "restriction") {
899  myIsRestriction = true;
900  return;
901  }
902  if (key == "restriction") {
903  // @note: the 'right/left/straight' part is ignored since the information is
904  // redundantly encoded in the 'from', 'to' and 'via' members
905  if (value.substr(0, 5) == "only_") {
906  myRestrictionType = RESTRICTION_ONLY;
907  } else if (value.substr(0, 3) == "no_") {
908  myRestrictionType = RESTRICTION_NO;
909  } else {
910  WRITE_WARNING("Found unknown restriction type '" + value + "' in relation '" + toString(myCurrentRelation) + "'");
911  }
912  return;
913  }
914  }
915  }
916 }
917 
918 
919 bool
921  if (myOSMEdges.find(ref) != myOSMEdges.end()) {
922  return true;
923  } else {
924  WRITE_WARNING("No way found for reference '" + toString(ref) + "' in relation '" + toString(myCurrentRelation) + "'");
925  return false;
926  }
927 }
928 
929 
930 void
932  myParentElements.pop_back();
933  if (element == SUMO_TAG_RELATION) {
934  if (myIsRestriction) {
935  assert(myCurrentRelation != INVALID_ID);
936  bool ok = true;
937  if (myRestrictionType == RESTRICTION_UNKNOWN) {
938  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "' with unknown type.");
939  ok = false;
940  }
941  if (myFromWay == INVALID_ID) {
942  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "' with unknown from-way.");
943  ok = false;
944  }
945  if (myToWay == INVALID_ID) {
946  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "' with unknown to-way.");
947  ok = false;
948  }
949  if (myViaNode == INVALID_ID && myViaWay == INVALID_ID) {
950  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "' with unknown via.");
951  ok = false;
952  }
953  if (ok && !applyRestriction()) {
954  WRITE_WARNING("Ignoring restriction relation '" + toString(myCurrentRelation) + "'.");
955  }
956  }
957  // other relations might use similar subelements so reset in any case
958  resetValues();
959  }
960 }
961 
962 
963 bool
965  // since OSM ways are bidirectional we need the via to figure out which direction was meant
966  if (myViaNode != INVALID_ID) {
967  NBNode* viaNode = myOSMNodes.find(myViaNode)->second->node;
968  if (viaNode == 0) {
969  WRITE_WARNING("Via-node '" + toString(myViaNode) + "' was not instantiated");
970  return false;
971  }
972  NBEdge* from = findEdgeRef(myFromWay, viaNode->getIncomingEdges());
973  NBEdge* to = findEdgeRef(myToWay, viaNode->getOutgoingEdges());
974  if (from == 0) {
975  WRITE_WARNING("from-edge of restriction relation could not be determined");
976  return false;
977  }
978  if (to == 0) {
979  WRITE_WARNING("to-edge of restriction relation could not be determined");
980  return false;
981  }
982  if (myRestrictionType == RESTRICTION_ONLY) {
983  from->addEdge2EdgeConnection(to);
984  } else {
985  from->removeFromConnections(to, -1, -1, true);
986  }
987  } else {
988  // XXX interpreting via-ways or via-node lists not yet implemented
989  WRITE_WARNING("direction of restriction relation could not be determined");
990  return false;
991  }
992  return true;
993 }
994 
995 
996 NBEdge*
997 NIImporter_OpenStreetMap::RelationHandler::findEdgeRef(SUMOLong wayRef, const std::vector<NBEdge*>& candidates) const {
998  const std::string prefix = toString(wayRef);
999  const std::string backPrefix = "-" + prefix;
1000  NBEdge* result = 0;
1001  int found = 0;
1002  for (EdgeVector::const_iterator it = candidates.begin(); it != candidates.end(); ++it) {
1003  if (((*it)->getID().substr(0, prefix.size()) == prefix) ||
1004  ((*it)->getID().substr(0, backPrefix.size()) == backPrefix)) {
1005  result = *it;
1006  found++;
1007  }
1008  }
1009  if (found > 1) {
1010  WRITE_WARNING("Ambigous way reference '" + prefix + "' in restriction relation");
1011  result = 0;
1012  }
1013  return result;
1014 }
1015 
1016 
1017 /****************************************************************************/
1018 
NodesHandler(std::map< SUMOLong, NIOSMNode * > &toFill, std::set< NIOSMNode *, CompareNodes > &uniqueNodes, bool importElevation)
Contructor.
const SUMOReal lat
The latitude the node is located at.
An internal definition of a loaded edge.
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's incoming edges.
Definition: NBNode.h:251
static const SUMOReal UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:201
std::string streetName
The edge's street name.
NBTypeCont & getTypeCont()
Returns the type container.
Definition: NBNetBuilder.h:170
const SUMOReal SUMO_const_laneWidth
Definition: StdDefs.h:46
std::map< SUMOLong, Edge * > myEdges
the map from OSM way ids to edge objects
is a pedestrian
std::string next()
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...
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.
static SUMOReal _2SUMOReal(const E *const data)
Definition: TplConvert.h:223
vehicle is a not electrified rail
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:2339
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:71
vehicle is a small delivery vehicle
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.
const SUMOLong id
The edge's id.
vehicle is a light rail
bool getIsOneWay(const std::string &type) const
Returns whether edges are one-way per default for the given type.
Definition: NBTypeCont.cpp:116
T MAX2(T a, T b)
Definition: StdDefs.h:74
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:2227
void myEndElement(int element)
Called when a closing tag occurs.
NBNode * insertNodeChecking(SUMOLong id, NBNodeCont &nc, NBTrafficLightLogicCont &tlsc)
Builds an NBNode.
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's ok.
Definition: XMLSubSys.cpp:114
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:134
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
SUMOReal ele
The elevation of this node.
NBNode * node
the NBNode that was instantiated
vehicle is a city rail
PositionVector reverse() const
static const SUMOReal MAXSPEED_UNGIVEN
std::vector< SUMOLong > myCurrentNodes
The list of nodes this edge is made of.
SUMOReal getSidewalkWidth(const std::string &type) const
Returns the lane width for a sidewalk to be added [m].
Definition: NBTypeCont.cpp:140
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given OSM file.
Functor which compares two Edges.
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges.
Definition: NBNode.h:259
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:625
const Position & getPosition() const
Returns the position of this node.
Definition: NBNode.h:239
#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:104
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.
A class which extracts OSM-edges from a parsed OSM-file.
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:170
Encapsulated SAX-Attributes.
static StringBijection< TrafficLightType > TrafficLightTypes
army vehicles
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:98
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:110
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:68
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
#define SUMOLong
Definition: config.h:215
size_t size() const
bool knows(const std::string &type) const
Returns whether the named type is in the container.
Definition: NBTypeCont.cpp:80
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
void removeFromConnections(NBEdge *toEdge, int fromLane=-1, int toLane=-1, bool tryLater=false)
Removes the specified connection(s)
Definition: NBEdge.cpp:869
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
bool insert(const std::string &id, int noLanes, SUMOReal maxSpeed, int prio, SUMOReal width, SUMOVehicleClass vClasses=SVC_IGNORING, bool oneWayIsDefault=false, SUMOReal sidewalkWidth=NBEdge::UNSPECIFIED_WIDTH)
Adds a type into the list. This is a simplified convenience form of insert, if only one allowed vehic...
Definition: NBTypeCont.cpp:60
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
NBEdge * findEdgeRef(SUMOLong wayRef, const std::vector< NBEdge * > &candidates) const
try to find the way segment among candidates
std::vector< std::string > getVector()
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
int myNoLanes
number of lanes, or -1 if unknown
vehicle is a bus
void push_back(const PositionVector &p)
Appends all positions from the given vector.
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
const SUMOReal lon
The longitude the node is located at.
EdgesHandler(const std::map< SUMOLong, NIOSMNode * > &osmNodes, std::map< SUMOLong, Edge * > &toFill)
Constructor.
NBNodeCont & getNodeCont()
Returns the node container.
Definition: NBNetBuilder.h:162
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
vip vehicles
bool getShallBeDiscarded(const std::string &type) const
Returns the information whether edges of this type shall be discarded.
Definition: NBTypeCont.cpp:122
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.
RelationHandler(const std::map< SUMOLong, NIOSMNode * > &osmNodes, const std::map< SUMOLong, Edge * > &osmEdges)
Constructor.
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
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 the traffic light logics container.
Definition: NBNetBuilder.h:178
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
A class which extracts OSM-nodes from a parsed OSM-file.
Represents a single node (junction) during network building.
Definition: NBNode.h:75
void resetValues()
reset members to their defaults for parsing a new relation
T get(const std::string &str) const
bool checkEdgeRef(SUMOLong ref) const
check whether a referenced way has a corresponding edge
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:159
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.
#define SUMOReal
Definition: config.h:218
int insertEdge(Edge *e, int index, NBNode *from, NBNode *to, const std::vector< SUMOLong > &passed, NBNetBuilder &nb)
Builds an NBEdge.
bool myCurrentIsRoad
Information whether this is a road.
bool operator()(const Edge *e1, const Edge *e2) const
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:108
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Definition: NBTypeCont.cpp:128
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
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:54
std::map< SUMOLong, NIOSMNode * > myOSMNodes
the map from OSM node ids to actual nodes
#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
static const SUMOLong INVALID_ID
A class which extracts relevant relation information from a parsed OSM-file.
std::string myIsOneWay
Information whether this is an one-way road.
vehicles ignoring classes
TrafficLightType
A storage for available types of edges.
Definition: NBTypeCont.h:56
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.