SUMO - Simulation of Urban MObility
NIImporter_DlrNavteq.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Importer for networks stored in Elmar's format
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <sstream>
34 #include <limits>
40 #include <utils/common/ToString.h>
45 #include <netbuild/NBNetBuilder.h>
46 #include <netbuild/NBNode.h>
47 #include <netbuild/NBNodeCont.h>
48 #include <netbuild/NBEdge.h>
49 #include <netbuild/NBEdgeCont.h>
50 #include <netbuild/NBTypeCont.h>
51 #include <netbuild/NBOwnTLDef.h>
53 #include "NILoader.h"
54 #include "NIImporter_DlrNavteq.h"
55 
56 
57 // ---------------------------------------------------------------------------
58 // static members
59 // ---------------------------------------------------------------------------
60 const std::string NIImporter_DlrNavteq::GEO_SCALE("1e-5");
61 const int NIImporter_DlrNavteq::EdgesHandler::MISSING_COLUMN = std::numeric_limits<int>::max();
62 const std::string NIImporter_DlrNavteq::UNDEFINED("-1");
63 
64 // ===========================================================================
65 // method definitions
66 // ===========================================================================
67 // ---------------------------------------------------------------------------
68 // static methods
69 // ---------------------------------------------------------------------------
70 void
72  // check whether the option is set (properly)
73  if (!oc.isSet("dlr-navteq-prefix")) {
74  return;
75  }
76  time_t csTime;
77  time(&csTime);
78  // parse file(s)
79  LineReader lr;
80  // load nodes
81  std::map<std::string, PositionVector> myGeoms;
82  PROGRESS_BEGIN_MESSAGE("Loading nodes");
83  std::string file = oc.getString("dlr-navteq-prefix") + "_nodes_unsplitted.txt";
84  NodesHandler handler1(nb.getNodeCont(), file, myGeoms);
85  if (!lr.setFile(file)) {
86  throw ProcessError("The file '" + file + "' could not be opened.");
87  }
88  lr.readAll(handler1);
90 
91  // load street names if given and wished
92  std::map<std::string, std::string> streetNames; // nameID : name
93  if (oc.getBool("output.street-names")) {
94  file = oc.getString("dlr-navteq-prefix") + "_names.txt";
95  if (lr.setFile(file)) {
96  PROGRESS_BEGIN_MESSAGE("Loading Street Names");
97  NamesHandler handler4(file, streetNames);
98  lr.readAll(handler4);
100  } else {
101  WRITE_WARNING("Output will not contain street names because the file '" + file + "' was not found");
102  }
103  }
104 
105  // load edges
106  PROGRESS_BEGIN_MESSAGE("Loading edges");
107  file = oc.getString("dlr-navteq-prefix") + "_links_unsplitted.txt";
108  // parse the file
109  EdgesHandler handler2(nb.getNodeCont(), nb.getEdgeCont(), nb.getTypeCont(), file, myGeoms, streetNames);
110  if (!lr.setFile(file)) {
111  throw ProcessError("The file '" + file + "' could not be opened.");
112  }
113  lr.readAll(handler2);
116 
117  // load traffic lights if given
118  file = oc.getString("dlr-navteq-prefix") + "_traffic_signals.txt";
119  if (lr.setFile(file)) {
120  PROGRESS_BEGIN_MESSAGE("Loading traffic lights");
121  TrafficlightsHandler handler3(nb.getNodeCont(), nb.getTLLogicCont(), nb.getEdgeCont(), file);
122  lr.readAll(handler3);
124  }
125 
126  // load prohibited manoeuvres if given
127  file = oc.getString("dlr-navteq-prefix") + "_prohibited_manoeuvres.txt";
128  if (lr.setFile(file)) {
129  PROGRESS_BEGIN_MESSAGE("Loading prohibited manoeuvres");
130  ProhibitionHandler handler6(nb.getEdgeCont(), file, csTime);
131  lr.readAll(handler6);
133  }
134 
135  // load connected lanes if given
136  file = oc.getString("dlr-navteq-prefix") + "_connected_lanes.txt";
137  if (lr.setFile(file)) {
138  PROGRESS_BEGIN_MESSAGE("Loading connected lanes");
139  ConnectedLanesHandler handler7(nb.getEdgeCont());
140  lr.readAll(handler7);
142  }
143 
144  // load time restrictions if given
145  file = oc.getString("dlr-navteq-prefix") + "_links_timerestrictions.txt";
146  if (lr.setFile(file)) {
147  PROGRESS_BEGIN_MESSAGE("Loading time restrictions");
148  if (!oc.isDefault("construction-date")) {
149  csTime = readDate(oc.getString("construction-date"));
150  }
151  TimeRestrictionsHandler handler5(nb.getEdgeCont(), nb.getDistrictCont(), csTime);
152  lr.readAll(handler5);
153  handler5.printSummary();
155  }
156 }
157 
158 double
159 NIImporter_DlrNavteq::readVersion(const std::string& line, const std::string& file) {
160  assert(line[0] == '#');
161  const std::string marker = "extraction version: v";
162  const std::string lowerCase = StringUtils::to_lower_case(line);
163  if (lowerCase.find(marker) == std::string::npos) {
164  return -1;
165  }
166  const int vStart = (int)(lowerCase.find(marker) + marker.size());
167  const int vEnd = (int)line.find(" ", vStart);
168  try {
169  const double version = TplConvert::_2double(line.substr(vStart, vEnd - vStart).c_str());
170  if (version < 0) {
171  throw ProcessError("Invalid version number '" + toString(version) + "' in file '" + file + "'.");
172  }
173  return version;
174  } catch (NumberFormatException&) {
175  throw ProcessError("Non-numerical value '" + line.substr(vStart, vEnd - vStart) + "' for version string in file '" + file + "'.");
176  }
177 }
178 
179 
180 // ---------------------------------------------------------------------------
181 // definitions of NIImporter_DlrNavteq::NodesHandler-methods
182 // ---------------------------------------------------------------------------
184  const std::string& file,
185  std::map<std::string, PositionVector>& geoms)
186  : myNodeCont(nc), myGeoms(geoms) {
187  UNUSED_PARAMETER(file);
188 }
189 
190 
192 
193 
194 bool
195 NIImporter_DlrNavteq::NodesHandler::report(const std::string& result) {
196  if (result[0] == '#') {
197  return true;
198  }
199  std::string id;
200  double x, y;
201  int no_geoms, intermediate;
202  // parse
203  std::istringstream stream(result);
204  // id
205  stream >> id;
206  if (stream.fail()) {
207  throw ProcessError("Something is wrong with the following data line\n" + result);
208  }
209  // intermediate?
210  stream >> intermediate;
211  if (stream.fail()) {
212  if (myNodeCont.size() == 0) { // be generous with extra data at beginning of file
213  return true;
214  }
215  throw ProcessError("Non-numerical value for intermediate status in node " + id + ".");
216  }
217  // number of geometrical information
218  stream >> no_geoms;
219  if (stream.fail()) {
220  throw ProcessError("Non-numerical value for number of geometries in node " + id + ".");
221  }
222  // geometrical information
223  PositionVector geoms;
224  for (int i = 0; i < no_geoms; i++) {
225  stream >> x;
226  if (stream.fail()) {
227  throw ProcessError("Non-numerical value for x-position in node " + id + ".");
228  }
229  stream >> y;
230  if (stream.fail()) {
231  throw ProcessError("Non-numerical value for y-position in node " + id + ".");
232  }
233  Position pos(x, y);
234  if (!NBNetBuilder::transformCoordinate(pos, true)) {
235  throw ProcessError("Unable to project coordinates for node " + id + ".");
236  }
237  geoms.push_back(pos);
238  }
239 
240  if (intermediate == 0) {
241  NBNode* n = new NBNode(id, geoms[0]);
242  if (!myNodeCont.insert(n)) {
243  delete n;
244  throw ProcessError("Could not add node '" + id + "'.");
245  }
246  } else {
247  myGeoms[id] = geoms;
248  }
249  return true;
250 }
251 
252 
253 // ---------------------------------------------------------------------------
254 // definitions of NIImporter_DlrNavteq::EdgesHandler-methods
255 // ---------------------------------------------------------------------------
257  NBTypeCont& tc, const std::string& file,
258  std::map<std::string, PositionVector>& geoms,
259  std::map<std::string, std::string>& streetNames):
260  myNodeCont(nc),
261  myEdgeCont(ec),
262  myTypeCont(tc),
263  myGeoms(geoms),
264  myStreetNames(streetNames),
265  myVersion(0),
266  myFile(file) {
267 }
268 
269 
271 
272 
273 bool
274 NIImporter_DlrNavteq::EdgesHandler::report(const std::string& result) {
275  // parse version number from first comment line and initialize column definitions
276  if (result[0] == '#') {
277  if (!myColumns.empty()) {
278  return true;
279  }
280  const double version = readVersion(result, myFile);
281  if (version > 0) {
282  myVersion = version;
283  // init columns
284  const int NUM_COLUMNS = 25; // @note arrays must match this size!
285  const int MC = MISSING_COLUMN;
286  if (myVersion < 3) {
287  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};
288  myColumns = std::vector<int>(columns, columns + NUM_COLUMNS);
289  } else if (myVersion < 6) {
290  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};
291  myColumns = std::vector<int>(columns, columns + NUM_COLUMNS);
292  } else {
293  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};
294  myColumns = std::vector<int>(columns, columns + NUM_COLUMNS);
295  }
296  }
297  return true;
298  }
299  if (myColumns.empty()) {
300  throw ProcessError("Missing version string in file '" + myFile + "'.");
301  }
302  // interpret link attributes
304  const std::string id = getColumn(st, LINK_ID);
305  // form of way (for priority and permissions)
306  int form_of_way;
307  try {
308  form_of_way = TplConvert::_2int(getColumn(st, FORM_OF_WAY).c_str());
309  } catch (NumberFormatException&) {
310  throw ProcessError("Non-numerical value for form_of_way of link '" + id + "'.");
311  }
312  // brunnel type (bridge/tunnel/ferry (for permissions)
313  int brunnel_type;
314  try {
315  brunnel_type = TplConvert::_2int(getColumn(st, BRUNNEL_TYPE).c_str());
316  } catch (NumberFormatException&) {
317  throw ProcessError("Non-numerical value for brunnel_type of link '" + id + "'.");
318  }
319  // priority based on street_type / frc
320  int priority;
321  try {
322  priority = -TplConvert::_2int(getColumn(st, FUNCTIONAL_ROAD_CLASS).c_str());
323  // lower priority using form_of_way
324  if (form_of_way == 11) {
325  priority -= 1; // frontage road, very often with lowered curb
326  } else if (form_of_way > 11) {
327  priority -= 2; // parking/service access assume lowered curb
328  }
329  } catch (NumberFormatException&) {
330  throw ProcessError("Non-numerical value for street_type of link '" + id + "').");
331  }
332  // street name
333  std::string streetName = getStreetNameFromIDs(
336  // try to get the nodes
337  const std::string fromID = getColumn(st, NODE_ID_FROM);
338  const std::string toID = getColumn(st, NODE_ID_TO);
339  NBNode* from = myNodeCont.retrieve(fromID);
340  NBNode* to = myNodeCont.retrieve(toID);
341  if (from == 0) {
342  throw ProcessError("The from-node '" + fromID + "' of link '" + id + "' could not be found");
343  }
344  if (to == 0) {
345  throw ProcessError("The to-node '" + toID + "' of link '" + id + "' could not be found");
346  }
347  // speed
348  double speed;
349  try {
350  speed = TplConvert::_2int(getColumn(st, SPEED_RESTRICTION, "-1").c_str()) / 3.6;
351  } catch (NumberFormatException) {
352  throw ProcessError("Non-numerical value for the SPEED_RESTRICTION of link '" + id + "'.");
353  }
354  if (speed < 0) {
355  // speed category as fallback
357  }
358  // number of lanes
359  int numLanes;
360  try {
361  // EXTENDED_NUMBER_OF_LANES is prefered but may not be defined
362  numLanes = TplConvert::_2int(getColumn(st, EXTENDED_NUMBER_OF_LANES, "-1").c_str());
363  if (numLanes == -1) {
364  numLanes = NINavTeqHelper::getLaneNumber(id, getColumn(st, NUMBER_OF_LANES), speed);
365  }
366  } catch (NumberFormatException&) {
367  throw ProcessError("Non-numerical value for the number of lanes of link '" + id + "'.");
368  }
369  // build the edge
370  NBEdge* e = 0;
371  const std::string interID = getColumn(st, BETWEEN_NODE_ID);
372  if (interID == "-1") {
373  e = new NBEdge(id, from, to, "", speed, numLanes, priority,
375  } else {
376  PositionVector geoms = myGeoms[interID];
377  if (getColumn(st, CONNECTION, "0") == "1") {
378  geoms = geoms.reverse();
379  }
380  geoms.insert(geoms.begin(), from->getPosition());
381  geoms.push_back(to->getPosition());
382  const std::string origID = OptionsCont::getOptions().getBool("output.original-names") ? id : "";
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,
824  }
825  // ensure that connections for other lanes are guessed if not specified
827  from->getLaneStruct(fromLane).connectionsDone = true;
828  return true;
829 }
830 
831 /****************************************************************************/
bool report(const std::string &result)
Parsing method.
static const PositionVector EMPTY
empty Vector
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:108
NBNodeCont & myNodeCont
The node container to get the referenced nodes from.
NBTypeCont & getTypeCont()
Returns a reference to the type container.
Definition: NBNetBuilder.h:166
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()
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:266
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:57
void reinit(const Position &position, SumoXMLNodeType type, bool updateEdgeGeometries=false)
Resets initial values.
Definition: NBNode.cpp:273
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:70
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:257
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:1201
T MAX2(T a, T b)
Definition: StdDefs.h:73
bool setFile(const std::string &file)
Reinitialises the reader for reading from the given file.
Definition: LineReader.cpp:184
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:2997
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:151
const std::string & getID() const
Returns the id.
Definition: Named.h:65
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:1177
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:39
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:254
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
The edge has been loaded, nothing is computed yet.
Definition: NBEdge.h:91
static const double UNSPECIFIED_SPEED
unspecified lane speed
Definition: NBEdge.h:260
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:65
bool knows(const std::string &type) const
Returns whether the named type is in the container.
Definition: NBTypeCont.cpp:74
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:157
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
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:243
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
std::string getLaneID(int lane) const
get Lane ID (Secure)
Definition: NBEdge.cpp:2783
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:391
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:412
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
TimeRestrictionsHandler(NBEdgeCont &ec, NBDistrictCont &dc, time_t constructionTime)
Constructor.
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:156
A list of positions.
static const double UNSPECIFIED_CONTPOS
unspecified internal junction position
Definition: NBEdge.h:263
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:167
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:67
const std::string myFile
the file being parsed
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:201
static int readPrefixedInt(const std::string &s, const std::string &prefix, int fallBack=0)
The connection was given by the user.
Definition: NBEdge.h:112
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:3025
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:205
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:62
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:155
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, double speed=UNSPECIFIED_SPEED, const PositionVector &customShape=PositionVector::EMPTY)
Adds a connection between the specified this edge&#39;s lane and an approached one.
Definition: NBEdge.cpp:921
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:161
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
std::string getStreetNameFromIDs(const std::string &regionalID, const std::string &localID) const
build the street name for the given ids
void addPostProcessConnection(const std::string &from, int fromLane, const std::string &to, int toLane, bool mayDefinitelyPass, bool keepClear, double contPos, double visibility, double speed, const PositionVector &customShape, bool warnOnly=false)
Adds a connection which could not be set during loading.
Definition: NBEdgeCont.cpp:857
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:250
A storage for options typed value containers)
Definition: OptionsCont.h:98
static double _2double(const E *const data)
converts a char-type array into the double value described by it
Definition: TplConvert.h:311
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:266
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:79
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:171
std::map< std::string, std::string > & myStreetNames
The container for storing read names.
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:1191
const Position & getPosition() const
Definition: NBNode.h:241
Represents a single node (junction) during network building.
Definition: NBNode.h:74
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:829
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:66
TrafficlightsHandler(NBNodeCont &nc, NBTrafficLightLogicCont &tlc, NBEdgeCont &ne, const std::string &file)
Constructor.
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:202
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:53
static const std::string GEO_SCALE
scaling factor for geo coordinates (DLRNavteq format uses this to increase floating point precisions)...
static time_t readDate(const std::string &yyyymmdd)
Imports prohibitions regarding connectivity.
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:200
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:176
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:433
void disallowVehicleClass(int lane, SUMOVehicleClass vclass)
set disallowed class for the given lane or for all lanes if -1 is given
Definition: NBEdge.cpp:2885
TrafficLightType
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Definition: NBTypeCont.cpp:210
A storage for available types of edges.
Definition: NBTypeCont.h:61
std::string getColumn(const StringTokenizer &st, ColumnName name, const std::string fallback="")
bool report(const std::string &result)
Parsing method.