/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file NIImporter_DlrNavteq.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @author Jakob Erdmann17/// @date Mon, 14.04.200818///19// Importer for networks stored in Elmar's format20/****************************************************************************/21#pragma once22#include <config.h>2324#include <string>25#include <map>26#include <utils/common/UtilExceptions.h>27#include <utils/importio/LineHandler.h>282930// ===========================================================================31// class declarations32// ===========================================================================33class NBEdgeCont;34class NBNetBuilder;35class NBNodeCont;36class NBTrafficLightLogicCont;37class NBTypeCont;38class OptionsCont;39class PositionVector;40class StringTokenizer;414243// ===========================================================================44// class definitions45// ===========================================================================46/**47* @class NIImporter_DlrNavteq48* @brief Importer for networks stored in Elmar's format49*50*/51class NIImporter_DlrNavteq {52public:53/** @brief Loads content of the optionally given dlr-navteq (aka Elmar-fomat) folder54*55* If the option "dlr-navteq-prefix" is set, the file(s) stored therein is read and56* the network definition stored therein is stored within the given network57* builder.58*59* If the option "dlr-navteq-prefix" is not set, this method simply returns.60*61* @param[in] oc The options to use62* @param[in] nb The network builder to fill63*/64static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);6566/// @brief scaling factor for geo coordinates (DLRNavteq format uses this to increase floating point precisions)67static const std::string GEO_SCALE;6869/// @brief decides whether the edge length of the input format should be used70static bool keepLength;7172/// @brief magic value for undefined stuff73static const std::string UNDEFINED;7475protected:76/**77* @class NodesHandler78* @brief Importer of nodes stored in unsplit elmar format79*80* Being a LineHandler, this class retrieves each line from a LineReader81* and parses these information assuming they contain node definitions82* in DLRNavteq's unsplit format.83*/84class NodesHandler : public LineHandler {85public:86/** @brief Constructor87* @param[in, filled] nc The node control to insert loaded nodes into88* @param[in] file The name of the parsed file89* @param[in, geoms] geoms Storage for read edge geometries90*/91NodesHandler(NBNodeCont& nc, const std::string& file,92std::map<std::string, PositionVector>& geoms);939495/// @brief Destructor96~NodesHandler();979899/** @brief Parsing method100*101* Implementation of the LineHandler-interface called by a LineReader;102* interprets the retrieved information and stores it into "myNodeCont".103* Additionally, edge geometries are parsed and stored into "myGeoms".104*105* @param[in] result The read line106* @return Whether the parsing shall continue107* @exception ProcessError if something fails108* @see LineHandler::report109*/110bool report(const std::string& result);111112113protected:114// @brief The node container to store parsed nodes into115NBNodeCont& myNodeCont;116117/// @brief A container for parsed geometries118std::map<std::string, PositionVector>& myGeoms;119120121private:122/// @brief Invalidated copy constructor.123NodesHandler(const NodesHandler&);124125/// @brief Invalidated assignment operator.126NodesHandler& operator=(const NodesHandler&);127128};129130131/**132* @class EdgesHandler133* @brief Importer of edges stored in unsplit elmar format134*135* Being a LineHandler, this class retrieves each line from a LineReader136* and parses these information assuming they contain edge definitions137* in DLRNavteq's unsplit format.138*/139class EdgesHandler : public LineHandler {140141public:142/** @brief Constructor143* @param[in] nc The node control to retrieve nodes from144* @param[in, filled] ec The edge control to insert loaded edges into145* @param[in] tc The type control to retrieve types from146* @param[in] file The name of the parsed file147* @param[in] geoms The previously read edge geometries148* @param[in] streetNames The previously read street names149*/150EdgesHandler(NBNodeCont& nc, NBEdgeCont& ec, NBTypeCont& tc,151const std::string& file,152std::map<std::string, PositionVector>& geoms,153std::map<std::string, std::string>& streetNames);154155156/// @brief Destructor157~EdgesHandler();158159160/** @brief Parsing method161*162* Implementation of the LineHandler-interface called by a LineReader;163* interprets the retrieved information and stores it into "myEdgeCont".164* @param[in] result The read line165* @return Whether the parsing shall continue166* @exception ProcessError if something fails167* @see LineHandler::report168*/169bool report(const std::string& result);170171172protected:173/// @brief The node container to get the referenced nodes from174NBNodeCont& myNodeCont;175176/// @brief The edge container to store loaded edges into177NBEdgeCont& myEdgeCont;178179/// @brief The type container to retrieve type info from180NBTypeCont& myTypeCont;181182/// @brief Previously read edge geometries (manipulated during use)183std::map<std::string, PositionVector>& myGeoms;184185/// @brief Previously read streat names (non-const because operate[] is more convenient)186std::map<std::string, std::string>& myStreetNames;187188/// @brief Whether node positions shall not be added to the edge's geometry189bool myTryIgnoreNodePositions;190191/// @brief version number of current file192double myVersion;193194/// @brief the version number of the edge file being parsed195std::vector<int> myColumns;196197/// @brief the file being parsed198const std::string myFile;199200static const int MISSING_COLUMN;201202enum ColumnName {203LINK_ID = 0,204NODE_ID_FROM,205NODE_ID_TO,206BETWEEN_NODE_ID,207LENGTH,208VEHICLE_TYPE,209FORM_OF_WAY,210BRUNNEL_TYPE,211FUNCTIONAL_ROAD_CLASS,212SPEED_CATEGORY,213NUMBER_OF_LANES,214SPEED_LIMIT,215SPEED_RESTRICTION,216NAME_ID1_REGIONAL,217NAME_ID2_LOCAL,218HOUSENUMBERS_RIGHT,219HOUSENUMBERS_LEFT,220ZIP_CODE,221AREA_ID,222SUBAREA_ID,223THROUGH_TRAFFIC,224SPECIAL_RESTRICTIONS,225EXTENDED_NUMBER_OF_LANES,226ISRAMP,227CONNECTION228};229230std::string getColumn(const StringTokenizer& st, ColumnName name, const std::string fallback = "");231232private:233/// @brief build the street name for the given ids234std::string getStreetNameFromIDs(const std::string& regionalID, const std::string& localID) const;235236237private:238/// @brief Invalidated copy constructor.239EdgesHandler(const EdgesHandler&);240241/// @brief Invalidated assignment operator.242EdgesHandler& operator=(const EdgesHandler&);243244};245246247/**248* @class TrafficlightsHandler249* @brief Importer of traffic lights stored in DLRNavteq's (aka elmar) format250*251* Being a LineHandler, this class retrieves each line from a LineReader252* and parses these information assuming they contain traffic light definitions253* in DLRNavteq's format.254*/255class TrafficlightsHandler : public LineHandler {256public:257/** @brief Constructor258* @param[in] nc The node control to retrieve nodes from259* @param[in, filled] tlc The traffic lights container to fill260* @param[in] file The name of the parsed file261*/262TrafficlightsHandler(NBNodeCont& nc, NBTrafficLightLogicCont& tlc,263NBEdgeCont& ne, const std::string& file);264265266/// @brief Destructor267~TrafficlightsHandler();268269270/** @brief Parsing method271*272* Implementation of the LineHandler-interface called by a LineReader;273* interprets the retrieved information and alters the nodes.274* @param[in] result The read line275* @return Whether the parsing shall continue276* @exception ProcessError if something fails277* @see LineHandler::report278*/279bool report(const std::string& result);280281282protected:283/// @brief The node container to get the referenced nodes from284NBNodeCont& myNodeCont;285286/// @brief The traffic lights container to add built tls to287NBTrafficLightLogicCont& myTLLogicCont;288289/// @brief The edge container to get the referenced edges from290NBEdgeCont& myEdgeCont;291292293private:294/// @brief Invalidated copy constructor.295TrafficlightsHandler(const TrafficlightsHandler&);296297/// @brief Invalidated assignment operator.298TrafficlightsHandler& operator=(const TrafficlightsHandler&);299300};301302303/**304* @class NamesHandler305* @brief Importer of street names in DLRNavteq's (aka elmar) format306*307* Being a LineHandler, this class retrieves each line from a LineReader308* and parses these information assuming they contain name definitions309* in DLRNavteq's format.310*/311class NamesHandler : public LineHandler {312public:313/** @brief Constructor314* @param[in] file The name of the parsed file315* @param[filled] streetNames output container for read names316*/317NamesHandler(const std::string& file, std::map<std::string, std::string>& streetNames);318319320/// @brief Destructor321~NamesHandler();322323324/** @brief Parsing method325*326* Implementation of the LineHandler-interface called by a LineReader;327* interprets the retrieved information and stores the streetNames328* @param[in] result The read line329* @return Whether the parsing shall continue330* @exception ProcessError if something fails331* @see LineHandler::report332*/333bool report(const std::string& result);334335336protected:337/// @brief The container for storing read names338std::map<std::string, std::string>& myStreetNames;339340341private:342/// @brief Invalidated copy constructor.343NamesHandler(const NamesHandler&);344345/// @brief Invalidated assignment operator.346NamesHandler& operator=(const NamesHandler&);347348};349350351/**352* @class TimeRestrictionsHandler353* @brief Importer of street names in DLRNavteq's (aka elmar) format354*355* Being a LineHandler, this class retrieves each line from a LineReader356* and parses these information assuming they contain name definitions357* in DLRNavteq's format.358*/359class TimeRestrictionsHandler : public LineHandler {360public:361/** @brief Constructor362* @param[in] file The name of the parsed file363* @param[filled] streetNames output container for read names364*/365TimeRestrictionsHandler(NBEdgeCont& ec, NBDistrictCont& dc, time_t constructionTime);366367368/// @brief Destructor369~TimeRestrictionsHandler();370371372/** @brief Parsing method373*374* Implementation of the LineHandler-interface called by a LineReader;375* interprets the retrieved information and stores the streetNames376* @param[in] result The read line377* @return Whether the parsing shall continue378* @exception ProcessError if something fails379* @see LineHandler::report380*/381bool report(const std::string& result);382383void printSummary();384385386protected:387/// @brief The edge container388NBEdgeCont& myEdgeCont;389NBDistrictCont& myDistrictCont;390391/// @brief The date for which to build the network (in case some edges are still under construction)392time_t myConstructionTime;393time_t myCS_min;394time_t myCS_max;395int myConstructionEntries;396int myNotStarted;397int myUnderConstruction;398int myFinished;399int myRemovedEdges; // only counts those not already removed through other options400401402private:403/// @brief Invalidated copy constructor.404TimeRestrictionsHandler(const TimeRestrictionsHandler&);405406/// @brief Invalidated assignment operator.407TimeRestrictionsHandler& operator=(const TimeRestrictionsHandler&);408409};410411412/**413* @class ProhibitionHandler414* @brief Imports prohibitions regarding connectivity415*416* Being a LineHandler, this class retrieves each line from a LineReader417* and parses these information assuming they contain prohibited manoeuver definitions418* in DLRNavteq's format.419*/420class ProhibitionHandler : public LineHandler {421public:422/** @brief Constructor423* @param[in] file The name of the parsed file424* @param[filled] streetNames output container for read names425*/426ProhibitionHandler(NBEdgeCont& ne, const std::string& file, time_t constructionTime);427428429/// @brief Destructor430~ProhibitionHandler();431432433/** @brief Parsing method434*435* Implementation of the LineHandler-interface called by a LineReader;436* interprets the retrieved information and stores the streetNames437* @param[in] result The read line438* @return Whether the parsing shall continue439* @exception ProcessError if something fails440* @see LineHandler::report441*/442bool report(const std::string& result);443444445protected:446/// @brief The edge container to store loaded edges into447NBEdgeCont& myEdgeCont;448const std::string myFile;449double myVersion;450time_t myConstructionTime;451452453private:454/// @brief Invalidated copy constructor.455ProhibitionHandler(const ProhibitionHandler&);456457/// @brief Invalidated assignment operator.458ProhibitionHandler& operator=(const ProhibitionHandler&);459460};461462463/**464* @class ConnectedLanesHandler465* @brief Imports prohibitions regarding connectivity466*467* Being a LineHandler, this class retrieves each line from a LineReader468* and parses these information assuming they contain prohibited manoeuver definitions469* in DLRNavteq's format.470*/471class ConnectedLanesHandler : public LineHandler {472public:473/** @brief Constructor474* @param[in] file The name of the parsed file475* @param[filled] streetNames output container for read names476*/477ConnectedLanesHandler(NBEdgeCont& ne);478479480/// @brief Destructor481~ConnectedLanesHandler();482483484/** @brief Parsing method485*486* Implementation of the LineHandler-interface called by a LineReader;487* interprets the retrieved information and stores the streetNames488* @param[in] result The read line489* @return Whether the parsing shall continue490* @exception ProcessError if something fails491* @see LineHandler::report492*/493bool report(const std::string& result);494495496protected:497/// @brief The edge container to store loaded edges into498NBEdgeCont& myEdgeCont;499500501private:502/// @brief Invalidated copy constructor.503ConnectedLanesHandler(const ConnectedLanesHandler&);504505/// @brief Invalidated assignment operator.506ConnectedLanesHandler& operator=(const ConnectedLanesHandler&);507508};509510511static double readVersion(const std::string& line, const std::string& file);512static int readPrefixedInt(const std::string& s, const std::string& prefix, int fallBack = 0);513static time_t readTimeRec(const std::string& start, const std::string& duration);514static time_t readDate(const std::string& yyyymmdd);515516};517518519