SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NWWriter_DlrNavteq.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Exporter writing networks using DlrNavteq (Elmar) format
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2012-2014 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
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 #include <algorithm>
32 #include <ctime>
33 #include <cmath>
35 #include <netbuild/NBEdge.h>
36 #include <netbuild/NBEdgeCont.h>
37 #include <netbuild/NBNode.h>
38 #include <netbuild/NBNodeCont.h>
39 #include <netbuild/NBNetBuilder.h>
40 #include <utils/common/ToString.h>
45 #include "NWFrame.h"
46 #include "NWWriter_DlrNavteq.h"
47 
48 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 
53 // ---------------------------------------------------------------------------
54 // static members
55 // ---------------------------------------------------------------------------
56 const std::string NWWriter_DlrNavteq::UNDEFINED("-1");
57 
58 // ---------------------------------------------------------------------------
59 // static methods
60 // ---------------------------------------------------------------------------
61 void
63  // check whether a matsim-file shall be generated
64  if (!oc.isSet("dlr-navteq-output")) {
65  return;
66  }
70 }
71 
72 
74  time_t rawtime;
75  time(&rawtime);
76  char buffer [80];
77  strftime(buffer, 80, "on %c", localtime(&rawtime));
78  device << "# Generated " << buffer << " by " << oc.getFullName() << "\n";
79  device << "# Format matches Extraction version: V6.0 \n";
80  std::stringstream tmp;
81  oc.writeConfiguration(tmp, true, false, false);
82  tmp.seekg(std::ios_base::beg);
83  std::string line;
84  while (!tmp.eof()) {
85  std::getline(tmp, line);
86  device << "# " << line << "\n";
87  }
88  device << "#\n";
89 }
90 
91 void
93  // For "real" nodes we simply use the node id.
94  // For internal nodes (geometry vectors describing edge geometry in the parlance of this format)
95  // we use the id of the edge and do not bother with
96  // compression (each direction gets its own internal node).
97  // XXX add option for generating numerical ids in case the input network has string ids and the target process needs integers
98  OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_nodes_unsplitted.txt");
99  writeHeader(device, oc);
100  const GeoConvHelper& gch = GeoConvHelper::getFinal();
101  const bool haveGeo = gch.usingGeoProjection();
102  const SUMOReal geoScale = pow(10.0f, haveGeo ? 5 : 2); // see NIImporter_DlrNavteq::GEO_SCALE
103  device.setPrecision(0);
104  if (!haveGeo) {
105  WRITE_WARNING("DlrNavteq node data will be written in (floating point) cartesian coordinates");
106  }
107  // write format specifier
108  device << "# NODE_ID\tIS_BETWEEN_NODE\tamount_of_geocoordinates\tx1\ty1\t[x2 y2 ... xn yn]\n";
109  // write normal nodes
110  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
111  NBNode* n = (*i).second;
112  Position pos = n->getPosition();
113  gch.cartesian2geo(pos);
114  pos.mul(geoScale);
115  device << n->getID() << "\t0\t1\t" << pos.x() << "\t" << pos.y() << "\n";
116  }
117  // write "internal" nodes
118  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
119  NBEdge* e = (*i).second;
120  const PositionVector& geom = e->getGeometry();
121  if (geom.size() > 2) {
122  std::string internalNodeID = e->getID();
123  if (internalNodeID == UNDEFINED ||
124  (nc.retrieve(internalNodeID) != 0)) {
125  // need to invent a new name to avoid clashing with the id of a 'real' node or a reserved name
126  internalNodeID += "_geometry";
127  }
128  device << internalNodeID << "\t1\t" << geom.size() - 2;
129  for (size_t ii = 1; ii < geom.size() - 1; ++ii) {
130  Position pos = geom[(int)ii];
131  gch.cartesian2geo(pos);
132  pos.mul(geoScale);
133  device << "\t" << pos.x() << "\t" << pos.y();
134  }
135  device << "\n";
136  }
137  }
138  device.close();
139 }
140 
141 
142 void
144  OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_links_unsplitted.txt");
145  writeHeader(device, oc);
146  // write format specifier
147  device << "# LINK_ID\tNODE_ID_FROM\tNODE_ID_TO\tBETWEEN_NODE_ID\tLENGTH\tVEHICLE_TYPE\tFORM_OF_WAY\tBRUNNEL_TYPE\tFUNCTIONAL_ROAD_CLASS\tSPEED_CATEGORY\tNUMBER_OF_LANES\tSPEED_LIMIT\tSPEED_RESTRICTION\tNAME_ID1_REGIONAL\tNAME_ID2_LOCAL\tHOUSENUMBERS_RIGHT\tHOUSENUMBERS_LEFT\tZIP_CODE\tAREA_ID\tSUBAREA_ID\tTHROUGH_TRAFFIC\tSPECIAL_RESTRICTIONS\tEXTENDED_NUMBER_OF_LANES\tISRAMP\tCONNECTION\n";
148  // write edges
149  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
150  NBEdge* e = (*i).second;
151  const int kph = speedInKph(e->getSpeed());
152  const std::string& betweenNodeID = (e->getGeometry().size() > 2) ? e->getID() : UNDEFINED;
153  device << e->getID() << "\t"
154  << e->getFromNode()->getID() << "\t"
155  << e->getToNode()->getID() << "\t"
156  << betweenNodeID << "\t"
157  << getGraphLength(e) << "\t"
158  << getAllowedTypes(e->getPermissions()) << "\t"
159  << "3\t" // Speed Category 1-8 XXX refine this
160  << UNDEFINED << "\t" // no special brunnel type (we don't know yet)
161  << getRoadClass(e) << "\t"
162  << getSpeedCategory(kph) << "\t"
163  << getNavteqLaneCode(e->getNumLanes()) << "\t"
164  << getSpeedCategoryUpperBound(kph) << "\t"
165  << kph << "\t"
166  << UNDEFINED << "\t" // NAME_ID1_REGIONAL XXX
167  << UNDEFINED << "\t" // NAME_ID2_LOCAL XXX
168  << UNDEFINED << "\t" // housenumbers_right
169  << UNDEFINED << "\t" // housenumbers_left
170  << UNDEFINED << "\t" // ZIP_CODE
171  << UNDEFINED << "\t" // AREA_ID
172  << UNDEFINED << "\t" // SUBAREA_ID
173  << "1\t" // through_traffic (allowed)
174  << UNDEFINED << "\t" // special_restrictions
175  << UNDEFINED << "\t" // extended_number_of_lanes
176  << UNDEFINED << "\t" // isRamp
177  << "0\t" // connection (between nodes always in order)
178  << "\n";
179  }
180 }
181 
182 
183 std::string
185  if (permissions == SVCAll) {
186  return "100000000000";
187  }
188  std::ostringstream oss;
189  oss << "0";
190  oss << ((permissions & SVC_PASSENGER) > 0 ? 1 : 0);
191  oss << ((permissions & SVC_PASSENGER) > 0 ? 1 : 0); // residential
192  oss << ((permissions & SVC_HOV) > 0 ? 1 : 0);
193  oss << ((permissions & SVC_EMERGENCY) > 0 ? 1 : 0);
194  oss << ((permissions & SVC_TAXI) > 0 ? 1 : 0);
195  oss << ((permissions & (SVC_BUS | SVC_COACH)) > 0 ? 1 : 0);
196  oss << ((permissions & SVC_DELIVERY) > 0 ? 1 : 0);
197  oss << ((permissions & (SVC_TRUCK | SVC_TRAILER)) > 0 ? 1 : 0);
198  oss << ((permissions & SVC_MOTORCYCLE) > 0 ? 1 : 0);
199  oss << ((permissions & SVC_BICYCLE) > 0 ? 1 : 0);
200  oss << ((permissions & SVC_PEDESTRIAN) > 0 ? 1 : 0);
201  return oss.str();
202 }
203 
204 
205 int
207  // quoting the navteq manual:
208  // As a general rule, Functional Road Class assignments have no direct
209  // correlation with other road attributes like speed, controlled access, route type, etc.
210  //
211  // we do a simple speed / lane-count mapping anyway
212  // XXX the resulting functional road class layers probably won't be connected as required
213  const int kph = speedInKph(edge->getSpeed());
214  if ((kph) > 100) {
215  return 0;
216  }
217  if ((kph) > 70) {
218  return 1;
219  }
220  if ((kph) > 50) {
221  return (edge->getNumLanes() > 1 ? 2 : 3);
222  }
223  if ((kph) > 30) {
224  return 3;
225  }
226  return 4;
227 }
228 
229 
230 int
232  if ((kph) > 130) {
233  return 1;
234  }
235  if ((kph) > 100) {
236  return 2;
237  }
238  if ((kph) > 90) {
239  return 3;
240  }
241  if ((kph) > 70) {
242  return 4;
243  }
244  if ((kph) > 50) {
245  return 5;
246  }
247  if ((kph) > 30) {
248  return 6;
249  }
250  if ((kph) > 10) {
251  return 7;
252  }
253  return 8;
254 }
255 
256 
257 int
259  if ((kph) > 130) {
260  return 131;
261  }
262  if ((kph) > 100) {
263  return 130;
264  }
265  if ((kph) > 90) {
266  return 100;
267  }
268  if ((kph) > 70) {
269  return 90;
270  }
271  if ((kph) > 50) {
272  return 70;
273  }
274  if ((kph) > 30) {
275  return 50;
276  }
277  if ((kph) > 10) {
278  return 30;
279  }
280  return 10;
281 }
282 
283 
284 unsigned int
285 NWWriter_DlrNavteq::getNavteqLaneCode(const unsigned int numLanes) {
286  const unsigned int code = (numLanes == 1 ? 1 :
287  (numLanes < 4 ? 2 : 3));
288  return numLanes * 10 + code;
289 }
290 
291 
292 SUMOReal
294  PositionVector geom = edge->getGeometry();
297  return geom.length();
298 }
299 
300 
301 void
303  OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_traffic_signals.txt");
304  writeHeader(device, oc);
305  const GeoConvHelper& gch = GeoConvHelper::getFinal();
306  const bool haveGeo = gch.usingGeoProjection();
307  const SUMOReal geoScale = pow(10.0f, haveGeo ? 5 : 2); // see NIImporter_DlrNavteq::GEO_SCALE
308  device.setPrecision(0);
309  // write format specifier
310  device << "#Traffic signal related to LINK_ID and NODE_ID with location relative to driving direction.\n#column format like pointcollection.\n#DESCRIPTION->LOCATION: 1-rechts von LINK; 2-links von LINK; 3-oberhalb LINK -1-keineAngabe\n#RELATREC_ID\tPOICOL_TYPE\tDESCRIPTION\tLONGITUDE\tLATITUDE\tLINK_ID\n";
311  // write record for every edge incoming to a tls controlled node
312  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
313  NBNode* n = (*i).second;
314  if (n->isTLControlled()) {
315  Position pos = n->getPosition();
316  gch.cartesian2geo(pos);
317  pos.mul(geoScale);
318  const EdgeVector& incoming = n->getIncomingEdges();
319  for (EdgeVector::const_iterator it = incoming.begin(); it != incoming.end(); ++it) {
320  NBEdge* e = *it;
321  device << e->getID() << "\t"
322  << "12\t" // POICOL_TYPE
323  << "LSA;NODEIDS#" << n->getID() << "#;LOCATION#-1#;\t"
324  << pos.x() << "\t"
325  << pos.y() << "\t"
326  << e->getID() << "\n";
327  }
328  }
329  }
330 }
331 
332 
333 /****************************************************************************/
334