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