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-2014 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  std::string internalNodeID = e->getID();
122  if (internalNodeID == UNDEFINED ||
123  (nc.retrieve(internalNodeID) != 0)) {
124  // need to invent a new name to avoid clashing with the id of a 'real' node or a reserved name
125  internalNodeID += "_geometry";
126  }
127  device << internalNodeID << "\t1\t" << geom.size() - 2;
128  for (size_t ii = 1; ii < geom.size() - 1; ++ii) {
129  Position pos = geom[(int)ii];
130  gch.cartesian2geo(pos);
131  pos.mul(geoScale);
132  device << "\t" << pos.x() << "\t" << pos.y();
133  }
134  device << "\n";
135  }
136  }
137  device.close();
138 }
139 
140 
141 void
143  OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_links_unsplitted.txt");
144  writeHeader(device, oc);
145  // write format specifier
146  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";
147  // write edges
148  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
149  NBEdge* e = (*i).second;
150  const int kph = speedInKph(e->getSpeed());
151  const std::string& betweenNodeID = (e->getGeometry().size() > 2) ? e->getID() : UNDEFINED;
152  device << e->getID() << "\t"
153  << e->getFromNode()->getID() << "\t"
154  << e->getToNode()->getID() << "\t"
155  << betweenNodeID << "\t"
156  << getGraphLength(e) << "\t"
157  << getAllowedTypes(e->getPermissions()) << "\t"
158  << "3\t" // Speed Category 1-8 XXX refine this
159  << UNDEFINED << "\t" // no special brunnel type (we don't know yet)
160  << getRoadClass(e) << "\t"
161  << getSpeedCategory(kph) << "\t"
162  << getNavteqLaneCode(e->getNumLanes()) << "\t"
163  << getSpeedCategoryUpperBound(kph) << "\t"
164  << kph << "\t"
165  << UNDEFINED << "\t" // NAME_ID1_REGIONAL XXX
166  << UNDEFINED << "\t" // NAME_ID2_LOCAL XXX
167  << UNDEFINED << "\t" // housenumbers_right
168  << UNDEFINED << "\t" // housenumbers_left
169  << UNDEFINED << "\t" // ZIP_CODE
170  << UNDEFINED << "\t" // AREA_ID
171  << UNDEFINED << "\t" // SUBAREA_ID
172  << "1\t" // through_traffic (allowed)
173  << UNDEFINED << "\t" // special_restrictions
174  << UNDEFINED << "\t" // extended_number_of_lanes
175  << UNDEFINED << "\t" // isRamp
176  << "0\t" // connection (between nodes always in order)
177  << "\n";
178  }
179 }
180 
181 
182 std::string
184  if (permissions == SVCFreeForAll) {
185  return "100000000000";
186  }
187  std::ostringstream oss;
188  oss << "0";
189  oss << ((permissions & SVC_PASSENGER) > 0 ? 1 : 0);
190  oss << ((permissions & SVC_PASSENGER) > 0 ? 1 : 0); // residential
191  oss << ((permissions & SVC_HOV) > 0 ? 1 : 0);
192  oss << ((permissions & SVC_PUBLIC_EMERGENCY) > 0 ? 1 : 0);
193  oss << ((permissions & SVC_TAXI) > 0 ? 1 : 0);
194  oss << ((permissions & (SVC_PUBLIC_TRANSPORT | SVC_BUS)) > 0 ? 1 : 0);
195  oss << ((permissions & SVC_DELIVERY) > 0 ? 1 : 0);
196  oss << ((permissions & SVC_TRANSPORT) > 0 ? 1 : 0);
197  oss << ((permissions & SVC_MOTORCYCLE) > 0 ? 1 : 0);
198  oss << ((permissions & SVC_BICYCLE) > 0 ? 1 : 0);
199  oss << ((permissions & SVC_PEDESTRIAN) > 0 ? 1 : 0);
200  return oss.str();
201 }
202 
203 
204 int
206  // quoting the navteq manual:
207  // As a general rule, Functional Road Class assignments have no direct
208  // correlation with other road attributes like speed, controlled access, route type, etc.
209  //
210  // we do a simple speed / lane-count mapping anyway
211  // XXX the resulting functional road class layers probably won't be connected as required
212  const int kph = speedInKph(edge->getSpeed());
213  if ((kph) > 100) {
214  return 0;
215  }
216  if ((kph) > 70) {
217  return 1;
218  }
219  if ((kph) > 50) {
220  return (edge->getNumLanes() > 1 ? 2 : 3);
221  }
222  if ((kph) > 30) {
223  return 3;
224  }
225  return 4;
226 }
227 
228 
229 int
231  if ((kph) > 130) {
232  return 1;
233  }
234  if ((kph) > 100) {
235  return 2;
236  }
237  if ((kph) > 90) {
238  return 3;
239  }
240  if ((kph) > 70) {
241  return 4;
242  }
243  if ((kph) > 50) {
244  return 5;
245  }
246  if ((kph) > 30) {
247  return 6;
248  }
249  if ((kph) > 10) {
250  return 7;
251  }
252  return 8;
253 }
254 
255 
256 int
258  if ((kph) > 130) {
259  return 131;
260  }
261  if ((kph) > 100) {
262  return 130;
263  }
264  if ((kph) > 90) {
265  return 100;
266  }
267  if ((kph) > 70) {
268  return 90;
269  }
270  if ((kph) > 50) {
271  return 70;
272  }
273  if ((kph) > 30) {
274  return 50;
275  }
276  if ((kph) > 10) {
277  return 30;
278  }
279  return 10;
280 }
281 
282 
283 unsigned int
284 NWWriter_DlrNavteq::getNavteqLaneCode(const unsigned int numLanes) {
285  const unsigned int code = (numLanes == 1 ? 1 :
286  (numLanes < 4 ? 2 : 3));
287  return numLanes * 10 + code;
288 }
289 
290 
291 SUMOReal
293  PositionVector geom = edge->getGeometry();
296  return geom.length();
297 }
298 
299 
300 void
302  OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_traffic_signals.txt");
303  writeHeader(device, oc);
304  const GeoConvHelper& gch = GeoConvHelper::getFinal();
305  const bool haveGeo = gch.usingGeoProjection();
306  const SUMOReal geoScale = pow(10.0f, haveGeo ? 5 : 2); // see NIImporter_DlrNavteq::GEO_SCALE
307  device.setPrecision(0);
308  // write format specifier
309  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";
310  // write record for every edge incoming to a tls controlled node
311  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
312  NBNode* n = (*i).second;
313  if (n->isTLControlled()) {
314  Position pos = n->getPosition();
315  gch.cartesian2geo(pos);
316  pos.mul(geoScale);
317  const EdgeVector& incoming = n->getIncomingEdges();
318  for (EdgeVector::const_iterator it = incoming.begin(); it != incoming.end(); ++it) {
319  NBEdge* e = *it;
320  device << e->getID() << "\t"
321  << "12\t" // POICOL_TYPE
322  << "LSA;NODEIDS#" << n->getID() << "#;LOCATION#-1#;\t"
323  << pos.x() << "\t"
324  << pos.y() << "\t"
325  << e->getID() << "\n";
326  }
327  }
328  }
329 }
330 
331 
332 /****************************************************************************/
333 
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges.
Definition: NBNode.h:170
void close()
Closes the device and removes it from the dictionary.
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
static unsigned int getNavteqLaneCode(const unsigned int numLanes)
get the lane number encoding
static int speedInKph(SUMOReal metersPerSecond)
get edge speed rounded to kmh
static void writeHeader(OutputDevice &device, const OptionsCont &oc)
write header comments (input paramters, date, etc...)
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition: NBNode.h:221
static int getRoadClass(NBEdge *edge)
get the navteq road class
static int getSpeedCategory(int kph)
get the navteq speed class based on the speed in km/h
The representation of a single edge during network building.
Definition: NBEdge.h:71
const std::string & getFullName() const
Definition: OptionsCont.h:622
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
static int getSpeedCategoryUpperBound(int kph)
get the SPEED_LIMIT as defined by elmar (upper bound of speed category)
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:196
static const std::string UNDEFINED
magic value for undefined stuff
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
const std::string & getID() const
Returns the id.
Definition: Named.h:60
void setPrecision(unsigned int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
void push_front_noDoublePos(const Position &p)
static void writeNodesUnsplitted(const OptionsCont &oc, NBNodeCont &nc, NBEdgeCont &ec)
Writes the nodes_unsplitted file.
const Position & getPosition() const
Returns the position of this node.
Definition: NBNode.h:158
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:198
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:59
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
NBEdgeCont & getEdgeCont()
Returns the edge container.
Definition: NBNetBuilder.h:154
A list of positions.
unsigned int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:338
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
static void writeLinksUnsplitted(const OptionsCont &oc, NBEdgeCont &ec)
Writes the links_unsplitted file.
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:142
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into XML-files (nodes, edges, connections, traffic lights)
const SVCPermissions SVCFreeForAll
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition: NBEdgeCont.h:190
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:2093
static std::string getAllowedTypes(SVCPermissions permissions)
build the ascii-bit-vector for column vehicle_type
SUMOReal length() const
Returns the length.
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:362
NBNodeCont & getNodeCont()
Returns the node container.
Definition: NBNetBuilder.h:162
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:38
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:499
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
A storage for options typed value containers)
Definition: OptionsCont.h:108
void mul(SUMOReal val)
Multiplies both positions with the given value.
Definition: Position.h:99
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
static SUMOReal getGraphLength(NBEdge *edge)
get the length of the edge when measured up to the junction center
Represents a single node (junction) during network building.
Definition: NBNode.h:74
static void writeTrafficSignals(const OptionsCont &oc, NBNodeCont &nc)
Writes the traffic_signals file.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
#define SUMOReal
Definition: config.h:215
void writeConfiguration(std::ostream &os, bool filled, bool complete, bool addComments) const
Writes the configuration.
void push_back_noDoublePos(const Position &p)
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:124
SUMOReal getSpeed() const
Returns the speed allowed on this edge.
Definition: NBEdge.h:422
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:64
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:134
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:354