SUMO - Simulation of Urban MObility
NIImporter_DlrNavteq.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Importer for networks stored in Elmar's format
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <sstream>
35 #include <limits>
41 #include <utils/common/ToString.h>
46 #include <netbuild/NBNetBuilder.h>
47 #include <netbuild/NBNode.h>
48 #include <netbuild/NBNodeCont.h>
49 #include <netbuild/NBEdge.h>
50 #include <netbuild/NBEdgeCont.h>
51 #include <netbuild/NBTypeCont.h>
52 #include <netbuild/NBOwnTLDef.h>
54 #include "NILoader.h"
55 #include "NIImporter_DlrNavteq.h"
56 
57 
58 // ---------------------------------------------------------------------------
59 // static members
60 // ---------------------------------------------------------------------------
63 const std::string NIImporter_DlrNavteq::UNDEFINED("-1");
64 
65 // ===========================================================================
66 // method definitions
67 // ===========================================================================
68 // ---------------------------------------------------------------------------
69 // static methods
70 // ---------------------------------------------------------------------------
71 void
73  // check whether the option is set (properly)
74  if (!oc.isSet("dlr-navteq-prefix")) {
75  return;
76  }
77  time_t csTime;
78  time(&csTime);
79  // parse file(s)
80  LineReader lr;
81  // load nodes
82  std::map<std::string, PositionVector> myGeoms;
83  PROGRESS_BEGIN_MESSAGE("Loading nodes");
84  std::string file = oc.getString("dlr-navteq-prefix") + "_nodes_unsplitted.txt";
85  NodesHandler handler1(nb.getNodeCont(), file, myGeoms);
86  if (!lr.setFile(file)) {
87  throw ProcessError("The file '" + file + "' could not be opened.");
88  }
89  lr.readAll(handler1);
91 
92  // load street names if given and wished
93  std::map<std::string, std::string> streetNames; // nameID : name
94  if (oc.getBool("output.street-names")) {
95  file = oc.getString("dlr-navteq-prefix") + "_names.txt";
96  if (lr.setFile(file)) {
97  PROGRESS_BEGIN_MESSAGE("Loading Street Names");
98  NamesHandler handler4(file, streetNames);
99  lr.readAll(handler4);
101  } else {
102  WRITE_WARNING("Output will not contain street names because the file '" + file + "' was not found");
103  }
104  }
105 
106  // load edges
107  PROGRESS_BEGIN_MESSAGE("Loading edges");
108  file = oc.getString("dlr-navteq-prefix") + "_links_unsplitted.txt";
109  // parse the file
110  EdgesHandler handler2(nb.getNodeCont(), nb.getEdgeCont(), nb.getTypeCont(), file, myGeoms, streetNames);
111  if (!lr.setFile(file)) {
112  throw ProcessError("The file '" + file + "' could not be opened.");
113  }
114  lr.readAll(handler2);
117 
118  // load traffic lights if given
119  file = oc.getString("dlr-navteq-prefix") + "_traffic_signals.txt";
120  if (lr.setFile(file)) {
121  PROGRESS_BEGIN_MESSAGE("Loading traffic lights");
122  TrafficlightsHandler handler3(nb.getNodeCont(), nb.getTLLogicCont(), nb.getEdgeCont(), file);
123  lr.readAll(handler3);
125  }
126 
127  // load prohibited manoeuvres if given
128  file = oc.getString("dlr-navteq-prefix") + "_prohibited_manoeuvres.txt";
129  if (lr.setFile(file)) {
130  PROGRESS_BEGIN_MESSAGE("Loading prohibited manoeuvres");
131  ProhibitionHandler handler6(nb.getEdgeCont(), file, csTime);
132  lr.readAll(handler6);
134  }
135 
136  // load connected lanes if given
137  file = oc.getString("dlr-navteq-prefix") + "_connected_lanes.txt";
138  if (lr.setFile(file)) {
139  PROGRESS_BEGIN_MESSAGE("Loading connected lanes");
140  ConnectedLanesHandler handler7(nb.getEdgeCont());
141  lr.readAll(handler7);
143  }
144 
145  // load time restrictions if given
146  file = oc.getString("dlr-navteq-prefix") + "_links_timerestrictions.txt";
147  if (lr.setFile(file)) {
148  PROGRESS_BEGIN_MESSAGE("Loading time restrictions");
149  if (!oc.isDefault("construction-date")) {
150  csTime = readDate(oc.getString("construction-date"));
151  }
152  TimeRestrictionsHandler handler5(nb.getEdgeCont(), nb.getDistrictCont(), csTime);
153  lr.readAll(handler5);
154  handler5.printSummary();
156  }
157 }
158 
159 double
160 NIImporter_DlrNavteq::readVersion(const std::string& line, const std::string& file) {
161  assert(line[0] == '#');
162  const std::string marker = "extraction version: v";
163  const std::string lowerCase = StringUtils::to_lower_case(line);
164  if (lowerCase.find(marker) == std::string::npos) {
165  return -1;
166  }
167  const int vStart = (int)(lowerCase.find(marker) + marker.size());
168  const int vEnd = (int)line.find(" ", vStart);
169  try {
170  const double version = TplConvert::_2double(line.substr(vStart, vEnd - vStart).c_str());
171  if (version < 0) {
172  throw ProcessError("Invalid version number '" + toString(version) + "' in file '" + file + "'.");
173  }
174  return version;
175  } catch (NumberFormatException&) {
176  throw ProcessError("Non-numerical value '" + line.substr(vStart, vEnd - vStart) + "' for version string in file '" + file + "'.");
177  }
178 }
179 
180 
181 // ---------------------------------------------------------------------------
182 // definitions of NIImporter_DlrNavteq::NodesHandler-methods
183 // ---------------------------------------------------------------------------
185  const std::string& file,
186  std::map<std::string, PositionVector>& geoms)
187  : myNodeCont(nc), myGeoms(geoms) {
188  UNUSED_PARAMETER(file);
189 }
190 
191 
193 
194 
195 bool
196 NIImporter_DlrNavteq::NodesHandler::report(const std::string& result) {
197  if (result[0] == '#') {
198  return true;
199  }
200  std::string id;
201  double x, y;
202  int no_geoms, intermediate;
203  // parse
204  std::istringstream stream(result);
205  // id
206  stream >> id;
207  if (stream.fail()) {
208  throw ProcessError("Something is wrong with the following data line\n" + result);
209  }
210  // intermediate?
211  stream >> intermediate;
212  if (stream.fail()) {
213  if (myNodeCont.size() == 0) { // be generous with extra data at beginning of file
214  return true;
215  }
216  throw ProcessError("Non-numerical value for intermediate status in node " + id + ".");
217  }
218  // number of geometrical information
219  stream >> no_geoms;
220  if (stream.fail()) {
221  throw ProcessError("Non-numerical value for number of geometries in node " + id + ".");
222  }
223  // geometrical information
224  PositionVector geoms;
225  for (int i = 0; i < no_geoms; i++) {
226  stream >> x;
227  if (stream.fail()) {
228  throw ProcessError("Non-numerical value for x-position in node " + id + ".");
229  }
230  stream >> y;
231  if (stream.fail()) {
232  throw ProcessError("Non-numerical value for y-position in node " + id + ".");
233  }
234  Position pos(x, y);
235  if (!NBNetBuilder::transformCoordinate(pos, true)) {
236  throw ProcessError("Unable to project coordinates for node " + id + ".");
237  }
238  geoms.push_back(pos);
239  }
240 
241  if (intermediate == 0) {
242  NBNode* n = new NBNode(id, geoms[0]);
243  if (!myNodeCont.insert(n)) {
244  delete n;
245  throw ProcessError("Could not add node '" + id + "'.");
246  }
247  } else {
248  myGeoms[id] = geoms;
249  }
250  return true;
251 }
252 
253 
254 // ---------------------------------------------------------------------------
255 // definitions of NIImporter_DlrNavteq::EdgesHandler-methods
256 // ---------------------------------------------------------------------------
258  NBTypeCont& tc, const std::string& file,
259  std::map<std::string, PositionVector>& geoms,
260  std::map<std::string, std::string>& streetNames):
261  myNodeCont(nc),
262  myEdgeCont(ec),
263  myTypeCont(tc),
264  myGeoms(geoms),
265  myStreetNames(streetNames),
266  myVersion(0),
267  myFile(file) {
268 }
269 
270 
272 
273 
274 bool
275 NIImporter_DlrNavteq::EdgesHandler::report(const std::string& result) {
276  // parse version number from first comment line and initialize column definitions
277  if (result[0] == '#') {
278  if (!myColumns.empty()) {
279  return true;
280  }
281  const double version = readVersion(result, myFile);
282  if (version > 0) {
283  myVersion = version;
284  // init columns
285  const int NUM_COLUMNS = 25; // @note arrays must match this size!
286  const int MC = MISSING_COLUMN;
287  if (myVersion < 3) {
288  const int columns[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, MC, 12, 13, 14, 15, 16, 17, 18, 19, 20, MC, MC, -21};
289  myColumns = std::vector<int>(columns, columns + NUM_COLUMNS);
290  } else if (myVersion < 6) {
291  const int columns[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, MC, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, -23};
292  myColumns = std::vector<int>(columns, columns + NUM_COLUMNS);
293  } else {
294  const int columns[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
295  myColumns = std::vector<int>(columns, columns + NUM_COLUMNS);
296  }
297  }
298  return true;
299  }
300  if (myColumns.empty()) {
301  throw ProcessError("Missing version string in file '" + myFile + "'.");
302  }
303  // interpret link attributes
305  const std::string id = getColumn(st, LINK_ID);
306  // form of way (for priority and permissions)
307  int form_of_way;
308  try {
309  form_of_way = TplConvert::_2int(getColumn(st, FORM_OF_WAY).c_str());
310  } catch (NumberFormatException&) {
311  throw ProcessError("Non-numerical value for form_of_way of link '" + id + "'.");
312  }
313  // brunnel type (bridge/tunnel/ferry (for permissions)
314  int brunnel_type;
315  try {
316  brunnel_type = TplConvert::_2int(getColumn(st, BRUNNEL_TYPE).c_str());
317  } catch (NumberFormatException&) {
318  throw ProcessError("Non-numerical value for brunnel_type of link '" + id + "'.");
319  }
320  // priority based on street_type / frc
321  int priority;
322  try {
323  priority = -TplConvert::_2int(getColumn(st, FUNCTIONAL_ROAD_CLASS).c_str());
324  // lower priority using form_of_way
325  if (form_of_way == 11) {
326  priority -= 1; // frontage road, very often with lowered curb
327  } else if (form_of_way > 11) {
328  priority -= 2; // parking/service access assume lowered curb
329  }
330  } catch (NumberFormatException&) {
331  throw ProcessError("Non-numerical value for street_type of link '" + id + "').");
332  }
333  // street name
334  std::string streetName = getStreetNameFromIDs(
337  // try to get the nodes
338  const std::string fromID = getColumn(st, NODE_ID_FROM);
339  const std::string toID = getColumn(st, NODE_ID_TO);
340  NBNode* from = myNodeCont.retrieve(fromID);
341  NBNode* to = myNodeCont.retrieve(toID);
342  if (from == 0) {
343  throw ProcessError("The from-node '" + fromID + "' of link '" + id + "' could not be found");
344  }
345  if (to == 0) {
346  throw ProcessError("The to-node '" + toID + "' of link '" + id + "' could not be found");
347  }
348  // speed
349  double speed;
350  try {
351  speed = TplConvert::_2int(getColumn(st, SPEED_RESTRICTION, "-1").c_str()) / 3.6;
352  } catch (NumberFormatException) {
353  throw ProcessError("Non-numerical value for the SPEED_RESTRICTION of link '" + id + "'.");
354  }
355  if (speed < 0) {
356  // speed category as fallback
358  }
359  // number of lanes
360  int numLanes;
361  try {
362  // EXTENDED_NUMBER_OF_LANES is prefered but may not be defined
363  numLanes = TplConvert::_2int(getColumn(st, EXTENDED_NUMBER_OF_LANES, "-1").c_str());
364  if (numLanes == -1) {
365  numLanes = NINavTeqHelper::getLaneNumber(id, getColumn(st, NUMBER_OF_LANES), speed);
366  }
367  } catch (NumberFormatException&) {
368  throw ProcessError("Non-numerical value for the number of lanes of link '" + id + "'.");
369  }
370  // build the edge
371  NBEdge* e = 0;
372  const std::string interID = getColumn(st, BETWEEN_NODE_ID);
373  if (interID == "-1") {
374  e = new NBEdge(id, from, to, "", speed, numLanes, priority,
376  } else {
377  PositionVector geoms = myGeoms[interID];
378  if (getColumn(st, CONNECTION, "0") == "1") {
379  geoms = geoms.reverse();
380  }
381  geoms.insert(geoms.begin(), from->getPosition());
382  geoms.push_back(to->getPosition());
383  e = new NBEdge(id, from, to, "", speed, numLanes, priority,
385  }
386 
387  // NavTeq imports can be done with a typemap (if supplied), if not, the old defaults are used
388  const std::string navTeqTypeId = getColumn(st, VEHICLE_TYPE) + "_" + getColumn(st, FORM_OF_WAY);
389 
390  if (myTypeCont.knows(navTeqTypeId)) {
391  e->setPermissions(myTypeCont.getPermissions(navTeqTypeId));
392  } else {
393  // add vehicle type information to the edge
394  if (myVersion < 6.0) {
396  } else {
398  }
399  if (e->getPermissions() == SVCAll) {
401  }
402  // permission modifications based on form_of_way
403  if (form_of_way == 14) { // pedestrian area (fussgaengerzone)
404  // unfortunately, the veh_type string is misleading in this case
406  }
407  // permission modifications based on brunnel_type
408  if (brunnel_type == 10) { // ferry
409  e->setPermissions(SVC_SHIP, -1);
410  }
411  }
412 
413  // insert the edge to the network
414  if (!myEdgeCont.insert(e)) {
415  delete e;
416  throw ProcessError("Could not add edge '" + id + "'.");
417  }
418  return true;
419 }
420 
421 
422 std::string
423 NIImporter_DlrNavteq::EdgesHandler::getColumn(const StringTokenizer& st, ColumnName name, const std::string fallback) {
424  assert(!myColumns.empty());
425  if (myColumns[name] == MISSING_COLUMN) {
426  if (fallback == "") {
427  throw ProcessError("Missing column " + toString(name) + ".");
428  } else {
429  return fallback;
430  }
431  } else if (myColumns[name] >= 0) {
432  return st.get((int)(myColumns[name]));
433  } else {
434  // negative column number implies an optional column
435  if ((int) st.size() <= -myColumns[name]) {
436  // the column is not present
437  if (fallback == "") {
438  throw ProcessError("Missing optional column " + toString(name) + " without default value.");
439  } else {
440  return fallback;
441  }
442  } else {
443  return st.get((int)(-myColumns[name]));
444  }
445  }
446 }
447 
448 
449 std::string
451  const std::string& regionalID, const std::string& localID) const {
452  std::string result = "";
453  bool hadRegional = false;
454  if (myStreetNames.count(regionalID) > 0) {
455  hadRegional = true;
456  result += myStreetNames[regionalID];
457  }
458  if (myStreetNames.count(localID) > 0) {
459  if (hadRegional) {
460  result += " / ";
461  }
462  result += myStreetNames[localID];
463  }
464  return result;
465 }
466 
467 // ---------------------------------------------------------------------------
468 // definitions of NIImporter_DlrNavteq::TrafficlightsHandler-methods
469 // ---------------------------------------------------------------------------
472  NBEdgeCont& ne,
473  const std::string& file) :
474  myNodeCont(nc),
475  myTLLogicCont(tlc),
476  myEdgeCont(ne) {
477  UNUSED_PARAMETER(file);
478 }
479 
480 
482 
483 
484 bool
486 // #ID POICOL-TYPE DESCRIPTION LONGITUDE LATITUDE NAVTEQ_LINK_ID NODEID
487 
488  if (result[0] == '#') {
489  return true;
490  }
492  const std::string edgeID = st.get(5);
493  NBEdge* edge = myEdgeCont.retrieve(edgeID);
494  if (edge == 0) {
495  WRITE_WARNING("The traffic light edge '" + edgeID + "' could not be found");
496  } else {
497  NBNode* node = edge->getToNode();
498  if (node->getType() != NODETYPE_TRAFFIC_LIGHT) {
499  node->reinit(node->getPosition(), NODETYPE_TRAFFIC_LIGHT);
500  // @note. There may be additional information somewhere in the GDF files about traffic light type ...
502  // @note actually we could use the navteq node ID here
503  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(node->getID(), node, 0, type);
504  if (!myTLLogicCont.insert(tlDef)) {
505  // actually, nothing should fail here
506  delete tlDef;
507  throw ProcessError("Could not allocate tls for '" + node->getID() + "'.");
508  }
509  }
510  }
511  return true;
512 }
513 
514 
515 // ---------------------------------------------------------------------------
516 // definitions of NIImporter_DlrNavteq::NamesHandler-methods
517 // ---------------------------------------------------------------------------
519  const std::string& file, std::map<std::string, std::string>& streetNames) :
520  myStreetNames(streetNames) {
521  UNUSED_PARAMETER(file);
522 }
523 
524 
526 
527 
528 bool
529 NIImporter_DlrNavteq::NamesHandler::report(const std::string& result) {
530 // # NAME_ID Name
531  if (result[0] == '#') {
532  return true;
533  }
535  if (st.size() == 1) {
536  return true; // one line with the number of data containing lines in it (also starts with a comment # since ersion 6.5)
537  }
538  assert(st.size() >= 2);
539  const std::string id = st.next();
540  if (st.size() > 2) {
541  const std::string permanent_id_info = st.next();
542  }
543  myStreetNames[id] = st.next();
544  return true;
545 }
546 
547 
548 // ---------------------------------------------------------------------------
549 // definitions of NIImporter_DlrNavteq::TimeRestrictionsHandler-methods
550 // ---------------------------------------------------------------------------
552  myEdgeCont(ec),
553  myDistrictCont(dc),
554  myConstructionTime(constructionTime),
555  myCS_min(std::numeric_limits<time_t>::max()),
556  myCS_max(std::numeric_limits<time_t>::min()),
557  myConstructionEntries(0),
558  myNotStarted(0),
559  myUnderConstruction(0),
560  myFinished(0),
561  myRemovedEdges(0) {
562 }
563 
564 
566 
567 
568 bool
570 // # NAME_ID Name
571  if (result[0] == '#') {
572  return true;
573  }
575  const std::string id = st.next();
576  const std::string type = st.next();
577  const std::string directionOfFlow = st.next(); // can be ignored since unidirectional edge ids are referenced in the file
578  const std::string throughTraffic = st.next();
579  const std::string vehicleType = st.next();
580  const std::string validityPeriod = st.next();
581  const std::string warning = "Unrecognized TIME_REC '" + validityPeriod + "'";
582  if (type == "CS") {
584  if (validityPeriod.size() > 1024) {
585  WRITE_WARNING(warning);
586  }
587  // construction
588  char start[1024];
589  char duration[1024];
590 
591  int matched;
592 
593  matched = sscanf(validityPeriod.c_str(), "[(%[^)]){%[^}]}]", start, duration);
594  if (matched == 2) {
595  time_t tStart = readTimeRec(start, "");
596  time_t tEnd = readTimeRec(start, duration);
597  myCS_min = MIN2(myCS_min, tStart);
598  myCS_max = MAX2(myCS_max, tEnd);
599  //std::cout << " start=" << start << " tStart=" << tStart<< " translation=" << asctime(localtime(&tStart)) << "";
600  //std::cout << " duration=" << duration << " tEnd=" << tEnd << " translation=" << asctime(localtime(&tEnd)) << "\n";
601  if (myConstructionTime < tEnd) {
602  NBEdge* edge = myEdgeCont.retrieve(id);
603  if (edge != 0) {
604  myRemovedEdges++;
605  myEdgeCont.extract(myDistrictCont, edge, true);
606  }
607  if (myConstructionTime < tStart) {
608  myNotStarted++;
609  } else {
611  }
612  } else {
613  myFinished++;
614  }
615  } else {
616  WRITE_WARNING(warning);
617  };
618  }
619  return true;
620 }
621 
622 
623 void
625  if (myConstructionEntries > 0) {
626  char buff[1024];
627  std::ostringstream msg;
628  strftime(buff, 1024, "%Y-%m-%d", localtime(&myCS_min));
629  msg << "Parsed " << myConstructionEntries << " construction entries between " << buff;
630  strftime(buff, 1024, "%Y-%m-%d", localtime(&myCS_max));
631  msg << " and " << buff << ".\n";
632  strftime(buff, 1024, "%Y-%m-%d", localtime(&myConstructionTime));
633  msg << "Removed " << myRemovedEdges << " edges not yet constructed at " << buff << ".\n";
634  msg << " not yet started: " << myNotStarted << "\n";
635  msg << " under construction: " << myUnderConstruction << "\n";
636  msg << " finished: " << myFinished << "\n";
637  WRITE_MESSAGE(msg.str());
638  }
639 }
640 
641 
642 int
643 NIImporter_DlrNavteq::readPrefixedInt(const std::string& s, const std::string& prefix, int fallBack) {
644  int result = fallBack;
645  size_t pos = s.find(prefix);
646  if (pos != std::string::npos) {
647  sscanf(s.substr(pos).c_str(), (prefix + "%i").c_str(), &result);
648  }
649  return result;
650 }
651 
652 time_t
653 NIImporter_DlrNavteq::readTimeRec(const std::string& start, const std::string& duration) {
654  // http://www.cplusplus.com/reference/ctime/mktime/
655  struct tm timeinfo;
656  timeinfo.tm_hour = 0;
657  timeinfo.tm_min = 0;
658  timeinfo.tm_sec = 0;
659  timeinfo.tm_year = 0;
660  timeinfo.tm_mon = 0;
661  timeinfo.tm_mday = 1;
662  timeinfo.tm_wday = 0;
663  timeinfo.tm_yday = 0;
664  timeinfo.tm_isdst = 0;
665 
666  timeinfo.tm_year = readPrefixedInt(start, "y") + readPrefixedInt(duration, "y") - 1900;
667  timeinfo.tm_mon = readPrefixedInt(start, "M") + readPrefixedInt(duration, "M") - 1;
668  timeinfo.tm_mday = 7 * (readPrefixedInt(start, "w") + readPrefixedInt(duration, "w"));
669  timeinfo.tm_mday += readPrefixedInt(start, "d") + readPrefixedInt(duration, "d");
670 
671  time_t result = mktime(&timeinfo);
672  return result;
673 }
674 
675 
676 time_t
677 NIImporter_DlrNavteq::readDate(const std::string& yyyymmdd) {
678  struct tm timeinfo;
679  timeinfo.tm_hour = 0;
680  timeinfo.tm_min = 0;
681  timeinfo.tm_sec = 0;
682  timeinfo.tm_wday = 0;
683  timeinfo.tm_yday = 0;
684  timeinfo.tm_isdst = 0;
685 
686  if (yyyymmdd.size() == 10
687  && yyyymmdd[4] == '-'
688  && yyyymmdd[7] == '-') {
689  try {
690  timeinfo.tm_year = TplConvert::_str2int(yyyymmdd.substr(0, 4)) - 1900;
691  timeinfo.tm_mon = TplConvert::_str2int(yyyymmdd.substr(5, 2)) - 1;
692  timeinfo.tm_mday = TplConvert::_str2int(yyyymmdd.substr(8, 2));
693  return mktime(&timeinfo);
694  } catch (...) {
695  }
696  }
697  WRITE_ERROR("Could not parse YYYY-MM-DD date '" + yyyymmdd + "'");
698  time_t now;
699  time(&now);
700  return now;
701 }
702 
703 // ---------------------------------------------------------------------------
704 // definitions of NIImporter_DlrNavteq::ProhibitionHandler-methods
705 // ---------------------------------------------------------------------------
707  NBEdgeCont& ec, const std::string& file, time_t constructionTime) :
708  myEdgeCont(ec),
709  myFile(file),
710  myVersion(0),
711  myConstructionTime(constructionTime) {
712 }
713 
714 
716 
717 
718 bool
720 // # NAME_ID Name
721  if (result[0] == '#') {
722  if (myVersion == 0) {
723  const double version = readVersion(result, myFile);
724  if (version > 0) {
725  myVersion = version;
726  }
727  }
728  return true;
729  }
731  if (st.size() == 1) {
732  return true; // one line with the number of data containing lines in it (also starts with a comment # since ersion 6.5)
733  }
734  if (myVersion >= 6) {
735  assert(st.size() >= 7);
736  const std::string id = st.next();
737  const std::string permanent = st.next();
738  const std::string validityPeriod = st.next();
739  const std::string throughTraffic = st.next();
740  const std::string vehicleType = st.next();
741  if (validityPeriod != UNDEFINED) {
742  WRITE_WARNING("Ignoring temporary prohibited manoeuvre (" + validityPeriod + ")");
743  return true;
744  }
745  }
746  const std::string startEdge = st.next();
747  const std::string endEdge = st.get(st.size() - 1);
748 
749  NBEdge* from = myEdgeCont.retrieve(startEdge);
750  if (from == 0) {
751  WRITE_WARNING("Ignoring prohibition from unknown start edge '" + startEdge + "'");
752  return true;
753  }
754  NBEdge* to = myEdgeCont.retrieve(endEdge);
755  if (to == 0) {
756  WRITE_WARNING("Ignoring prohibition from unknown end edge '" + endEdge + "'");
757  return true;
758  }
759  from->removeFromConnections(to, -1, -1, true);
760  return true;
761 }
762 
763 
764 // ---------------------------------------------------------------------------
765 // definitions of NIImporter_DlrNavteq::ConnectedLanesHandler-methods
766 // ---------------------------------------------------------------------------
768  NBEdgeCont& ec) :
769  myEdgeCont(ec) {
770 }
771 
772 
774 
775 
776 bool
778  if (result[0] == '#') {
779  return true;
780  }
782  if (st.size() == 1) {
783  return true; // one line with the number of data containing lines in it (also starts with a comment # since ersion 6.5)
784  }
785  assert(st.size() >= 7);
786  const std::string nodeID = st.next();
787  const std::string vehicleType = st.next();
788  const std::string fromLaneS = st.next();
789  const std::string toLaneS = st.next();
790  const std::string throughTraffic = st.next();
791  const std::string startEdge = st.next();
792  const std::string endEdge = st.get(st.size() - 1);
793 
794  NBEdge* from = myEdgeCont.retrieve(startEdge);
795  if (from == 0) {
796  WRITE_WARNING("Ignoring prohibition from unknown start edge '" + startEdge + "'");
797  return true;
798  }
799  NBEdge* to = myEdgeCont.retrieve(endEdge);
800  if (to == 0) {
801  WRITE_WARNING("Ignoring prohibition from unknown end edge '" + endEdge + "'");
802  return true;
803  }
804  int fromLane = TplConvert::_2int(fromLaneS.c_str()) - 1; // one based
805  if (fromLane < 0 || fromLane >= from->getNumLanes()) {
806  WRITE_WARNING("Ignoring invalid lane index '" + fromLaneS + "' in connection from edge '" + startEdge + "' with " + toString(from->getNumLanes()) + " lanes");
807  return true;
808  }
809  int toLane = TplConvert::_2int(toLaneS.c_str()) - 1; // one based
810  if (toLane < 0 || toLane >= to->getNumLanes()) {
811  WRITE_WARNING("Ignoring invalid lane index '" + toLaneS + "' in connection to edge '" + endEdge + "' with " + toString(to->getNumLanes()) + " lanes");
812  return true;
813  }
814  if (!from->addLane2LaneConnection(fromLane, to, toLane, NBEdge::L2L_USER, true)) {
815  if (OptionsCont::getOptions().getBool("show-errors.connections-first-try")) {
816  WRITE_WARNING("Could not set loaded connection from '" + from->getLaneID(fromLane) + "' to '" + to->getLaneID(toLane) + "'.");
817  }
818  // set as to be re-applied after network processing
819  // if this connection runs across a node cluster it may not be possible to set this
820  const bool warnOnly = st.size() > 7;
821  myEdgeCont.addPostProcessConnection(from->getID(), fromLane, to->getID(), toLane, false, true,
823  }
824  // ensure that connections for other lanes are guessed if not specified
826  from->getLaneStruct(fromLane).connectionsDone = true;
827  return true;
828 }
829 
830 /****************************************************************************/
bool report(const std::string &result)
Parsing method.
void addPostProcessConnection(const std::string &from, int fromLane, const std::string &to, int toLane, bool mayDefinitelyPass, bool keepClear, double contPos, double visibility, bool warnOnly=false)
Adds a connection which could not be set during loading.
Definition: NBEdgeCont.cpp:837
NBEdgeCont & myEdgeCont
The edge container to store loaded edges into.
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:106
NBNodeCont & myNodeCont
The node container to get the referenced nodes from.
NBTypeCont & getTypeCont()
Returns a reference to the type container.
Definition: NBNetBuilder.h:165
bool report(const std::string &result)
Parsing method.
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
std::string next()
#define min(a, b)
Definition: polyfonts.c:66
std::map< std::string, std::string > & myStreetNames
Previously read streat names (non-const because operate[] is more convenient)
static const double UNSPECIFIED_VISIBILITY_DISTANCE
unspecified foe visibility for connections
Definition: NBEdge.h:267
static double getSpeed(const std::string &id, const std::string &speedClassS)
Returns the speed evaluating the given Navteq-description.
static const int WHITECHARS
Importer of street names in DLRNavteq&#39;s (aka elmar) format.
Importer of nodes stored in unsplit elmar format.
A container for traffic light definitions and built programs.
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:58
void reinit(const Position &position, SumoXMLNodeType type, bool updateEdgeGeometries=false)
Resets initial values.
Definition: NBNode.cpp:262
bool report(const std::string &result)
Parsing method.
NodesHandler(NBNodeCont &nc, const std::string &file, std::map< std::string, PositionVector > &geoms)
Constructor.
The representation of a single edge during network building.
Definition: NBEdge.h:71
static const std::string UNDEFINED
magic value for undefined stuff
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given dlr-navteq (aka Elmar-fomat) folder.
A container for districts.
The base class for traffic light logic definitions.
static void addVehicleClasses(NBEdge &e, const std::string &classS)
Adds vehicle classes parsing the given list of allowed vehicles.
bool report(const std::string &result)
Parsing method.
std::string get(int pos) const
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:258
void removeFromConnections(NBEdge *toEdge, int fromLane=-1, int toLane=-1, bool tryLater=false, const bool adaptToLaneRemoval=false)
Removes the specified connection(s)
Definition: NBEdge.cpp:1174
T MAX2(T a, T b)
Definition: StdDefs.h:70
bool setFile(const std::string &file)
Reinitialises the reader for reading from the given file.
Definition: LineReader.cpp:185
bool report(const std::string &result)
Parsing method.
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:2885
ProhibitionHandler(NBEdgeCont &ne, const std::string &file, time_t constructionTime)
Constructor.
NBEdgeCont & myEdgeCont
The edge container to store loaded edges into.
std::map< std::string, PositionVector > & myGeoms
Previously read edge geometries (manipulated during use)
PositionVector reverse() const
reverse position vector
Imports prohibitions regarding connectivity.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
bool connectionsDone
Whether connection information for this lane is already completed.
Definition: NBEdge.h:157
const std::string & getID() const
Returns the id.
Definition: Named.h:66
Importer of street names in DLRNavteq&#39;s (aka elmar) format.
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
const SVCPermissions SVCAll
all VClasses are allowed
NBTypeCont & myTypeCont
The type container to retrieve type info from.
Lane & getLaneStruct(int lane)
Definition: NBEdge.h:1154
Importer of traffic lights stored in DLRNavteq&#39;s (aka elmar) format.
bool report(const std::string &result)
Parsing method.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:38
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:255
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
The edge has been loaded, nothing is computed yet.
Definition: NBEdge.h:94
time_t myConstructionTime
The date for which to build the network (in case some edges are still under construction) ...
Importer of edges stored in unsplit elmar format.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static double readVersion(const std::string &line, const std::string &file)
void readAll(LineHandler &lh)
Reads the whole file linewise, reporting every line to the given LineHandler.
Definition: LineReader.cpp:66
bool knows(const std::string &type) const
Returns whether the named type is in the container.
Definition: NBTypeCont.cpp:75
#define max(a, b)
Definition: polyfonts.c:65
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:158
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
NBEdgeCont & myEdgeCont
The edge container to store loaded edges into.
NamesHandler(const std::string &file, std::map< std::string, std::string > &streetNames)
Constructor.
int size() const
Returns the number of nodes stored in this container.
Definition: NBNodeCont.h:229
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
std::string getLaneID(int lane) const
get Lane ID (Secure)
Definition: NBEdge.cpp:2679
void extract(NBDistrictCont &dc, NBEdge *edge, bool remember=false)
Removes the given edge from the container like erase but does not delete it.
Definition: NBEdgeCont.cpp:392
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:413
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
TimeRestrictionsHandler(NBEdgeCont &ec, NBDistrictCont &dc, time_t constructionTime)
Constructor.
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:155
A list of positions.
static const double UNSPECIFIED_CONTPOS
unspecified internal junction position
Definition: NBEdge.h:264
T get(const std::string &str) const
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static int _str2int(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
Definition: TplConvert.h:160
static time_t readTimeRec(const std::string &start, const std::string &duration)
std::map< std::string, PositionVector > & myGeoms
A container for parsed geometries.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
T MIN2(T a, T b)
Definition: StdDefs.h:64
const std::string myFile
the file being parsed
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
static int readPrefixedInt(const std::string &s, const std::string &prefix, int fallBack=0)
The connection was given by the user.
Definition: NBEdge.h:115
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:2913
vehicle is a passenger car (a "normal" car)
static const int TAB
double myVersion
version number of current file
is an arbitrary ship
NBEdgeCont & myEdgeCont
The edge container to get the referenced edges from.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
static void addVehicleClassesV6(NBEdge &e, const std::string &classS)
same as addVehicleClasses but for version 6+
static std::string to_lower_case(std::string str)
Transfers the content to lower case.
Definition: StringUtils.cpp:63
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:149
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:160
Instance responsible for building networks.
Definition: NBNetBuilder.h:114
std::string getStreetNameFromIDs(const std::string &regionalID, const std::string &localID) const
build the street name for the given ids
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:251
A storage for options typed value containers)
Definition: OptionsCont.h:99
static double _2double(const E *const data)
converts a char-type array into the double value described by it
Definition: TplConvert.h:297
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:257
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:77
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:170
std::map< std::string, std::string > & myStreetNames
The container for storing read names.
bool addLane2LaneConnection(int fromLane, NBEdge *dest, int toLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false, bool keepClear=true, double contPos=UNSPECIFIED_CONTPOS, double visibility=UNSPECIFIED_VISIBILITY_DISTANCE)
Adds a connection between the specified this edge&#39;s lane and an approached one.
Definition: NBEdge.cpp:900
NBTrafficLightLogicCont & myTLLogicCont
The traffic lights container to add built tls to.
EdgesHandler(NBNodeCont &nc, NBEdgeCont &ec, NBTypeCont &tc, const std::string &file, std::map< std::string, PositionVector > &geoms, std::map< std::string, std::string > &streetNames)
Constructor.
void declareConnectionsAsLoaded(EdgeBuildingStep step=LANES2LANES_USER)
declares connections as fully loaded. This is needed to avoid recomputing connections if an edge has ...
Definition: NBEdge.h:1168
const Position & getPosition() const
Definition: NBNode.h:232
Represents a single node (junction) during network building.
Definition: NBNode.h:75
static const int GEO_SCALE
scaling factor for geo coordinates (DLRNavteq format uses this to increase floating point precisions)...
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
void recheckLaneSpread()
Rechecks whether the lane spread is proper.
Definition: NBEdgeCont.cpp:809
static int getLaneNumber(const std::string &id, const std::string &laneNoS, double speed)
Returns the lane number evaluating the given Navteq-description.
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63
TrafficlightsHandler(NBNodeCont &nc, NBTrafficLightLogicCont &tlc, NBEdgeCont &ne, const std::string &file)
Constructor.
#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
static time_t readDate(const std::string &yyyymmdd)
Imports prohibitions regarding connectivity.
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:175
std::vector< int > myColumns
the version number of the edge file being parsed
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:434
void disallowVehicleClass(int lane, SUMOVehicleClass vclass)
set disallowed class for the given lane or for all lanes if -1 is given
Definition: NBEdge.cpp:2781
TrafficLightType
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Definition: NBTypeCont.cpp:211
A storage for available types of edges.
Definition: NBTypeCont.h:62
std::string getColumn(const StringTokenizer &st, ColumnName name, const std::string fallback="")
bool report(const std::string &result)
Parsing method.