/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-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 GeoConvHelper.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date 2006-08-0118///19// static methods for processing the coordinates conversion for the current net20/****************************************************************************/21#pragma once22#include <config.h>2324#include <map>25#include <string>26#include <utils/geom/Position.h>27#include <utils/geom/Boundary.h>2829#ifdef PROJ_API_FILE30#include PROJ_API_FILE31#ifdef PROJ_VERSION_MAJOR32typedef PJ* projPJ;33#endif34#endif353637// ===========================================================================38// class declarations39// ===========================================================================4041class OptionsCont;42class PositionVector;43class OutputDevice;4445// ===========================================================================46// class definitions47// ===========================================================================48/**49* @class GeoConvHelper50* @brief static methods for processing the coordinates conversion for the current net51*/52class GeoConvHelper {53public:5455/**@brief Constructor based on the stored options56* @param[in] oc The OptionsCont from which to read options57*/58GeoConvHelper(OptionsCont& oc);5960/// @brief Constructor61GeoConvHelper(const std::string& proj, const Position& offset,62const Boundary& orig, const Boundary& conv, double scale = 1.0, double rot = 0.0, bool inverse = false, bool flatten = false);6364/// @brief Destructor65~GeoConvHelper();6667/**@brief Adds projection options to the given container68* @param[in] oc The options container to add the options to69* @todo let the container be retrieved70*/71static void addProjectionOptions(OptionsCont& oc);7273/// @brief Initialises the processing and the final instance using the given options74static bool init(OptionsCont& oc);7576/// @brief Initialises the processing and the final instance using the given proj.4-definition and complete network parameter77static void init(const std::string& proj, const Position& offset, const Boundary& orig,78const Boundary& conv, double scale = 1.0);7980/**@brief the coordinate transformation to use for input conversion and processing81* @note instance is modified during use: boundary may adapt to new coordinates82*/83static GeoConvHelper& getProcessing() {84return myProcessing;85}8687/// @brief the coordinate transformation that was loaded fron an input file88static GeoConvHelper& getLoaded() {89return myLoaded;90}9192static int getNumLoaded() {93return myNumLoaded;94}9596/**@brief compute the location attributes which will be used for output97* based on the loaded location data, the given options and the transformations applied during processing98*/99static void computeFinal(bool lefthand = false);100101/// @brief the coordinate transformation for writing the location element and for tracking the original coordinate system102static const GeoConvHelper& getFinal() {103return myFinal;104}105106/// @brief sets the coordinate transformation loaded from a location element107static void setLoaded(const GeoConvHelper& loaded);108109/// @brief registers the coordinate transformation as having been loaded from the given file110static void setLoadedPlain(const std::string& nodFile, const GeoConvHelper& loaded);111112static GeoConvHelper* getLoadedPlain(const std::string& plainFile, const std::string& suffix = ".edg.xml");113114/// @brief @brief resets loaded location elements115static void resetLoaded();116117/// @brief Converts the given cartesian (shifted) position to its geo (lat/long) representation118void cartesian2geo(Position& cartesian) const;119120/**@brief Converts the given coordinate into a cartesian and optionally update myConvBoundary121* @note: initializes UTM / DHDN projection on first use (select zone)122*/123bool x2cartesian(Position& from, bool includeInBoundary = true);124125/// @brief Converts the given coordinate into a cartesian using the previous initialisation126bool x2cartesian_const(Position& from) const;127128/// @brief Returns whether a transformation from geo to metric coordinates will be performed129bool usingGeoProjection() const;130131/// @brief Returns the information whether an inverse transformation will happen132bool usingInverseGeoProjection() const;133134/// @brief Shifts the converted boundary by the given amounts135void moveConvertedBy(double x, double y);136137/// @brief Returns the original boundary138const Boundary& getOrigBoundary() const;139140/// @brief Returns the converted boundary141const Boundary& getConvBoundary() const;142143/// @brief sets the converted boundary144void setConvBoundary(const Boundary& boundary) {145myConvBoundary = boundary;146}147148/// @brief Returns the network offset149const Position getOffset() const;150151/// @brief Returns the network base152const Position getOffsetBase() const;153154/// @brief Returns the original projection definition155const std::string& getProjString() const;156157/// @brief init projString such as 'UTM' in loaded projection158void resolveAbstractProjection();159160/// @brief @brief writes the location element161static void writeLocation(OutputDevice& into);162163bool operator==(const GeoConvHelper& o) const;164165bool operator!=(const GeoConvHelper& o) const {166return !(*this == o);167}168169private:170/// @brief projection method171enum ProjectionMethod {172NONE,173SIMPLE,174UTM,175DHDN,176DHDN_UTM,177PROJ178};179180/// @brief A proj options string describing the proj.4-projection to use181std::string myProjString;182183#ifdef PROJ_API_FILE184void initProj(const std::string& proj);185186#ifdef PROJ_VERSION_MAJOR187bool checkError(projPJ projection) const;188#endif189190/// @brief The proj.4-projection to use191projPJ myProjection;192193/// @brief The inverse proj.4-projection to use first194projPJ myInverseProjection;195196/// @brief The geo proj.4-projection which is the target of the inverse projection197projPJ myGeoProjection;198#endif199200/// @brief The offset to apply201Position myOffset;202203/// @brief The scaling to apply to geo-coordinates204double myGeoScale;205206/// @brief The rotation to apply to geo-coordinates207double mySin;208double myCos;209210/// @brief Information whether no projection shall be done211ProjectionMethod myProjectionMethod;212213/// @brief Information whether inverse projection shall be used214bool myUseInverseProjection;215216/// @brief whether to discard z-data217bool myFlatten;218219/// @brief The boundary before conversion (x2cartesian)220Boundary myOrigBoundary;221222/// @brief The boundary after conversion (x2cartesian)223Boundary myConvBoundary;224225/// @brief coordinate transformation to use for input conversion and processing226static GeoConvHelper myProcessing;227228/// @brief coordinate transformation loaded from a location element229static GeoConvHelper myLoaded;230231/// @brief coordinate transformation to use for writing the location element and for tracking the original coordinate system232static GeoConvHelper myFinal;233234/// @brief the numer of coordinate transformations loaded from location elements235static int myNumLoaded;236237/// @brief the projections loaded from .nod.xml (to be re-used when loading edg.xml)238static std::map<std::string, std::pair<std::string, Position> > myLoadedPlain;239240/// @brief make assignment operator private241GeoConvHelper& operator=(const GeoConvHelper&);242243/// @brief invalidated copy constructor.244GeoConvHelper(const GeoConvHelper&) = delete;245};246247248