SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NILoader.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Perfoms network import
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
38 #include <utils/options/Option.h>
41 #include <utils/common/ToString.h>
42 #include <netbuild/NBTypeCont.h>
43 #include <netbuild/NBNodeCont.h>
44 #include <netbuild/NBEdgeCont.h>
45 #include <netbuild/NBNetBuilder.h>
63 #include <utils/xml/XMLSubSys.h>
64 #include "NILoader.h"
67 
68 #ifdef HAVE_INTERNAL
69 #include <internal/HeightMapper.h>
70 #endif
71 
72 #ifdef CHECK_MEMORY_LEAKS
73 #include <foreign/nvwa/debug_new.h>
74 #endif // CHECK_MEMORY_LEAKS
75 
76 
77 // ===========================================================================
78 // method definitions
79 // ===========================================================================
81  : myNetBuilder(nb) {}
82 
83 
85 
86 
87 void
89  // load types first
90  NIXMLTypesHandler* handler =
92  loadXMLType(handler, oc.getStringVector("type-files"), "types");
93  // try to load height data so it is ready for use by other importers
94 #ifdef HAVE_INTERNAL
95  HeightMapper::loadIfSet(oc);
96 #endif
97  // try to load using different methods
108  if (oc.getBool("tls.discard-loaded") || oc.getBool("tls.discard-simple")) {
110  size_t removed = myNetBuilder.getTLLogicCont().getNumExtracted();
111  if (removed > 0) {
112  WRITE_MESSAGE(" Removed " + toString(removed) + " traffic lights before loading plain-XML");
113  }
114  }
115  loadXML(oc);
116  // check the loaded structures
117  if (myNetBuilder.getNodeCont().size() == 0) {
118  throw ProcessError("No nodes loaded.");
119  }
120  if (myNetBuilder.getEdgeCont().size() == 0) {
121  throw ProcessError("No edges loaded.");
122  }
123  // report loaded structures
124  WRITE_MESSAGE(" Import done:");
125  if (myNetBuilder.getDistrictCont().size() > 0) {
126  WRITE_MESSAGE(" " + toString(myNetBuilder.getDistrictCont().size()) + " districts loaded.");
127  }
128  WRITE_MESSAGE(" " + toString(myNetBuilder.getNodeCont().size()) + " nodes loaded.");
129  if (myNetBuilder.getTypeCont().size() > 0) {
130  WRITE_MESSAGE(" " + toString(myNetBuilder.getTypeCont().size()) + " types loaded.");
131  }
132  WRITE_MESSAGE(" " + toString(myNetBuilder.getEdgeCont().size()) + " edges loaded.");
134  WRITE_MESSAGE("The split of edges was performed " + toString(myNetBuilder.getEdgeCont().getNoEdgeSplits()) + " times.");
135  }
136  if (GeoConvHelper::getProcessing().usingGeoProjection()) {
137  WRITE_MESSAGE("Proj projection parameters used: '" + GeoConvHelper::getProcessing().getProjString() + "'.");
138  }
139 }
140 
141 
142 /* -------------------------------------------------------------------------
143  * file loading methods
144  * ----------------------------------------------------------------------- */
145 void
147  // load nodes
150  oc.getStringVector("node-files"), "nodes");
151  // load the edges
157  oc),
158  oc.getStringVector("edge-files"), "edges");
159  // load the connections
161  oc.getStringVector("connection-files"), "connections");
162  // load traffic lights (needs to come last, references loaded edges and connections)
165  oc.getStringVector("tllogic-files"), "traffic lights");
166 }
167 
168 
169 void
170 NILoader::loadXMLType(SUMOSAXHandler* handler, const std::vector<std::string>& files,
171  const std::string& type) {
172  // build parser
173  std::string exceptMsg = "";
174  // start the parsing
175  try {
176  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
177  if (!FileHelpers::exists(*file)) {
178  WRITE_ERROR("Could not open " + type + "-file '" + *file + "'.");
179  exceptMsg = "Process Error";
180  continue;
181  }
182  PROGRESS_BEGIN_MESSAGE("Parsing " + type + " from '" + *file + "'");
183  XMLSubSys::runParser(*handler, *file);
185  }
186  } catch (const XERCES_CPP_NAMESPACE::XMLException& toCatch) {
187  exceptMsg = TplConvert::_2str(toCatch.getMessage())
188  + "\n The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
189  } catch (const ProcessError& toCatch) {
190  exceptMsg = std::string(toCatch.what()) + "\n The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
191  } catch (...) {
192  exceptMsg = "The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
193  }
194  delete handler;
195  if (exceptMsg != "") {
196  throw ProcessError(exceptMsg);
197  }
198 }
199 
200 /****************************************************************************/
Importer for network edges stored in XML.
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
NBTypeCont & getTypeCont()
Returns the type container.
Definition: NBNetBuilder.h:170
size_t size() const
Returns the number of districts inside the container.
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:97
Importer for edge connections stored in XML.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given ArcView Shape files.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given dlr-navteq (aka Elmar-fomat) folder.
unsigned int getNoEdgeSplits() const
Returns the number of edge splits.
Definition: NBEdgeCont.h:289
SAX-handler base for SUMO-files.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything's ok.
Definition: XMLSubSys.cpp:114
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads network definition from the assigned option and stores it in the given network builder...
void loadXMLType(SUMOSAXHandler *handler, const std::vector< std::string > &files, const std::string &type)
Definition: NILoader.cpp:170
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given OSM file.
~NILoader()
Destructor.
Definition: NILoader.cpp:84
unsigned int size() const
Returns the number of known nodes.
Definition: NBNodeCont.h:275
const std::string & getFileName() const
returns the current file name
Importer for network nodes stored in XML.
NBEdgeCont & getEdgeCont()
Returns the edge container.
Definition: NBNetBuilder.h:154
static std::string _2str(const E *const data)
Definition: TplConvert.h:56
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given RoboCup Rescue League files.
unsigned int size() const
Returns the number of known types.
Definition: NBTypeCont.h:107
static bool exists(std::string path)
Checks whether the given file exists.
Definition: FileHelpers.cpp:57
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:198
void load(OptionsCont &oc)
Definition: NILoader.cpp:88
void loadXML(OptionsCont &oc)
Definition: NILoader.cpp:146
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:52
static void loadNetwork(OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:201
Importer for edge type information stored in XML.
NBNodeCont & getNodeCont()
Returns the node container.
Definition: NBNetBuilder.h:162
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
A storage for options typed value containers)
Definition: OptionsCont.h:108
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads network definition from the assigned option and stores it in the given network builder...
NBTrafficLightLogicCont & getTLLogicCont()
Returns the traffic light logics container.
Definition: NBNetBuilder.h:178
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given ITSUMO network files.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given MATSIM network files.
NBNetBuilder & myNetBuilder
The network builder to fill with loaded data.
Definition: NILoader.h:87
Importer for edge connections stored in XML.
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:199
size_t getNumExtracted() const
return the number of extracted traffic light definitions
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike)
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:197
NILoader(NBNetBuilder &nb)
Constructor.
Definition: NILoader.cpp:80
NBDistrictCont & getDistrictCont()
Returns the districts container.
Definition: NBNetBuilder.h:186
unsigned int size() const
Returns the number of edges.
Definition: NBEdgeCont.h:274