|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Importer for networks stored in OpenStreetMap format 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 #ifndef NIImporter_OpenStreetMap_h 00020 #define NIImporter_OpenStreetMap_h 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #include <string> 00033 #include <map> 00034 #include <utils/xml/SUMOSAXHandler.h> 00035 #include <utils/common/UtilExceptions.h> 00036 00037 00038 // =========================================================================== 00039 // class declarations 00040 // =========================================================================== 00041 class NBEdge; 00042 class NBEdgeCont; 00043 class NBNetBuilder; 00044 class NBNode; 00045 class NBNodeCont; 00046 class NBTrafficLightLogicCont; 00047 class NBTypeCont; 00048 class OptionsCont; 00049 00050 00051 // =========================================================================== 00052 // class definitions 00053 // =========================================================================== 00059 class NIImporter_OpenStreetMap { 00060 public: 00072 static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb); 00073 00074 00075 protected: 00078 struct NIOSMNode { 00080 int id; 00082 double lon; 00084 double lat; 00086 bool tlsControlled; 00087 }; 00088 00089 00092 struct Edge { 00094 std::string id; 00096 std::string streetName; 00098 int myNoLanes; 00100 double myMaxSpeed; 00102 std::string myHighWayType; 00104 std::string myIsOneWay; 00106 std::vector<int> myCurrentNodes; 00108 bool myCurrentIsRoad; 00109 }; 00110 00111 00112 NIImporter_OpenStreetMap(); 00113 00114 ~NIImporter_OpenStreetMap(); 00115 00116 void _loadNetwork(const OptionsCont& oc, NBNetBuilder& nb); 00117 00118 private: 00119 00121 static const std::string compoundTypeSeparator; 00122 00123 class CompareNodes; 00124 class SubstituteNode; 00125 class SimilarEdge; 00126 00128 std::map<int, NIOSMNode*> myOSMNodes; 00129 std::map<std::string, Edge*> myEdges; 00130 00145 NBNode* insertNodeChecking(int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc); 00146 00147 00160 void insertEdge(Edge* e, int index, NBNode* from, NBNode* to, 00161 const std::vector<int> &passed, NBEdgeCont& ec, NBTypeCont& tc); 00162 00163 00164 00169 class NodesHandler : public SUMOSAXHandler { 00170 public: 00175 NodesHandler(std::map<int, NIOSMNode*> &toFill) throw(); 00176 00177 00179 ~NodesHandler() throw(); 00180 00181 00182 protected: 00184 00185 00193 void myStartElement(int element, const SUMOSAXAttributes& attrs) throw(ProcessError); 00194 00195 00202 void myEndElement(int element) throw(ProcessError); 00204 00205 00206 private: 00208 std::map<int, NIOSMNode*> &myToFill; 00209 00211 int myLastNodeID; 00212 00214 bool myIsInValidNodeTag; 00215 00217 int myHierarchyLevel; 00218 00219 00220 private: 00222 NodesHandler(const NodesHandler& s); 00223 00225 NodesHandler& operator=(const NodesHandler& s); 00226 00227 }; 00228 00229 00230 00235 class EdgesHandler : public SUMOSAXHandler { 00236 public: 00242 EdgesHandler(const std::map<int, NIOSMNode*> &osmNodes, 00243 std::map<std::string, Edge*> &toFill) throw(); 00244 00245 00247 ~EdgesHandler() throw(); 00248 00249 00250 protected: 00252 00253 00261 void myStartElement(int element, const SUMOSAXAttributes& attrs) throw(ProcessError); 00262 00263 00270 void myEndElement(int element) throw(ProcessError); 00272 00273 00274 private: 00276 const std::map<int, NIOSMNode*> &myOSMNodes; 00277 00279 std::map<std::string, Edge*> &myEdgeMap; 00280 00282 Edge* myCurrentEdge; 00283 00285 std::vector<int> myParentElements; 00286 00288 std::map<std::string, SUMOReal> mySpeedMap; 00289 00290 00291 private: 00293 EdgesHandler(const EdgesHandler& s); 00294 00296 EdgesHandler& operator=(const EdgesHandler& s); 00297 00298 }; 00299 00300 00301 }; 00302 00303 00304 #endif 00305 00306 /****************************************************************************/ 00307