SUMO - Simulation of Urban MObility
NIImporter_OpenStreetMap.h
Go to the documentation of this file.
00001 /****************************************************************************/
00010 // Importer for networks stored in OpenStreetMap format
00011 /****************************************************************************/
00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00014 /****************************************************************************/
00015 //
00016 //   This file is part of SUMO.
00017 //   SUMO is free software: you can redistribute it and/or modify
00018 //   it under the terms of the GNU General Public License as published by
00019 //   the Free Software Foundation, either version 3 of the License, or
00020 //   (at your option) any later version.
00021 //
00022 /****************************************************************************/
00023 #ifndef NIImporter_OpenStreetMap_h
00024 #define NIImporter_OpenStreetMap_h
00025 
00026 
00027 // ===========================================================================
00028 // included modules
00029 // ===========================================================================
00030 #ifdef _MSC_VER
00031 #include <windows_config.h>
00032 #else
00033 #include <config.h>
00034 #endif
00035 
00036 #include <string>
00037 #include <map>
00038 #include <utils/xml/SUMOSAXHandler.h>
00039 #include <utils/common/UtilExceptions.h>
00040 
00041 
00042 // ===========================================================================
00043 // class declarations
00044 // ===========================================================================
00045 class NBEdge;
00046 class NBEdgeCont;
00047 class NBNetBuilder;
00048 class NBNode;
00049 class NBNodeCont;
00050 class NBTrafficLightLogicCont;
00051 class NBTypeCont;
00052 class OptionsCont;
00053 
00054 
00055 // ===========================================================================
00056 // class definitions
00057 // ===========================================================================
00063 class NIImporter_OpenStreetMap {
00064 public:
00076     static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
00077 
00078 
00079 protected:
00082     struct NIOSMNode {
00084         long id;
00086         double lon;
00088         double lat;
00090         bool tlsControlled;
00091     };
00092 
00093 
00096     struct Edge {
00098         std::string id;
00100         std::string streetName;
00102         int myNoLanes;
00104         double myMaxSpeed;
00106         std::string myHighWayType;
00108         std::string  myIsOneWay;
00110         std::vector<long> myCurrentNodes;
00112         bool myCurrentIsRoad;
00113     };
00114 
00115 
00116     NIImporter_OpenStreetMap();
00117 
00118     ~NIImporter_OpenStreetMap();
00119 
00120     void load(const OptionsCont& oc, NBNetBuilder& nb);
00121 
00122 private:
00126     class CompareNodes {
00127         public:
00128             bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
00129                 return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
00130             }
00131     };
00132 
00133 
00135     static const std::string compoundTypeSeparator;
00136 
00137     class CompareEdges;
00138 
00142     std::map<long, NIOSMNode*> myOSMNodes;
00143 
00145     std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
00146 
00147 
00148     std::map<std::string, Edge*> myEdges;
00149 
00164     NBNode* insertNodeChecking(long id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
00165 
00166 
00179     int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
00180                     const std::vector<long> &passed, NBNetBuilder& nb);
00181 
00182 
00183     protected:
00184         static const SUMOReal MAXSPEED_UNGIVEN;
00185 
00190     friend class NodesHandler;
00191     class NodesHandler : public SUMOSAXHandler {
00192     public:
00198         NodesHandler(std::map<long, NIOSMNode*> &toFill, 
00199                 std::set<NIOSMNode*, CompareNodes> &uniqueNodes);
00200 
00201 
00203         ~NodesHandler() ;
00204 
00205 
00206     protected:
00208 
00209 
00217         void myStartElement(int element, const SUMOSAXAttributes& attrs) ;
00218 
00219 
00226         void myEndElement(int element) ;
00228 
00229 
00230     private:
00231 
00233         std::map<long, NIOSMNode*> &myToFill;
00234 
00236         long myLastNodeID;
00237 
00239         bool myIsInValidNodeTag;
00240 
00242         int myHierarchyLevel;
00243 
00245         std::set<NIOSMNode*, CompareNodes> &myUniqueNodes;
00246 
00247 
00248     private:
00250         NodesHandler(const NodesHandler& s);
00251 
00253         NodesHandler& operator=(const NodesHandler& s);
00254 
00255     };
00256 
00257 
00258 
00263     class EdgesHandler : public SUMOSAXHandler {
00264     public:
00270         EdgesHandler(const std::map<long, NIOSMNode*> &osmNodes,
00271                      std::map<std::string, Edge*> &toFill) ;
00272 
00273 
00275         ~EdgesHandler() ;
00276 
00277 
00278     protected:
00280 
00281 
00289         void myStartElement(int element, const SUMOSAXAttributes& attrs) ;
00290 
00291 
00298         void myEndElement(int element) ;
00300 
00301 
00302     private:
00304         const std::map<long, NIOSMNode*> &myOSMNodes;
00305 
00307         std::map<std::string, Edge*> &myEdgeMap;
00308 
00310         Edge* myCurrentEdge;
00311 
00313         std::vector<int> myParentElements;
00314 
00316         std::map<std::string, SUMOReal> mySpeedMap;
00317 
00318 
00319     private:
00321         EdgesHandler(const EdgesHandler& s);
00322 
00324         EdgesHandler& operator=(const EdgesHandler& s);
00325 
00326     };
00327 
00328 
00329 };
00330 
00331 
00332 #endif
00333 
00334 /****************************************************************************/
00335 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines