LCOV - code coverage report
Current view: top level - src/utils/geom - GeoConvHelper.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 2 2
Test Date: 2024-11-22 15:46:21 Functions: - 0 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    GeoConvHelper.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    2006-08-01
      19              : ///
      20              : // static methods for processing the coordinates conversion for the current net
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include <map>
      26              : #include <string>
      27              : #include <utils/geom/Position.h>
      28              : #include <utils/geom/Boundary.h>
      29              : 
      30              : #ifdef PROJ_API_FILE
      31              : #include PROJ_API_FILE
      32              : #ifdef PROJ_VERSION_MAJOR
      33              : typedef PJ* projPJ;
      34              : #endif
      35              : #endif
      36              : 
      37              : 
      38              : // ===========================================================================
      39              : // class declarations
      40              : // ===========================================================================
      41              : 
      42              : class OptionsCont;
      43              : class PositionVector;
      44              : class OutputDevice;
      45              : 
      46              : // ===========================================================================
      47              : // class definitions
      48              : // ===========================================================================
      49              : /**
      50              :  * @class GeoConvHelper
      51              :  * @brief static methods for processing the coordinates conversion for the current net
      52              :  */
      53              : class GeoConvHelper {
      54              : public:
      55              : 
      56              :     /**@brief Constructor based on the stored options
      57              :      * @param[in] oc The OptionsCont from which to read options
      58              :      */
      59              :     GeoConvHelper(OptionsCont& oc);
      60              : 
      61              :     /// @brief Constructor
      62              :     GeoConvHelper(const std::string& proj, const Position& offset,
      63              :                   const Boundary& orig, const Boundary& conv, double scale = 1.0, double rot = 0.0, bool inverse = false, bool flatten = false);
      64              : 
      65              :     /// @brief Destructor
      66              :     ~GeoConvHelper();
      67              : 
      68              :     /**@brief Adds projection options to the given container
      69              :      * @param[in] oc The options container to add the options to
      70              :      * @todo let the container be retrieved
      71              :      */
      72              :     static void addProjectionOptions(OptionsCont& oc);
      73              : 
      74              :     /// @brief Initialises the processing and the final instance using the given options
      75              :     static bool init(OptionsCont& oc);
      76              : 
      77              :     /// @brief Initialises the processing and the final instance using the given proj.4-definition and complete network parameter
      78              :     static void init(const std::string& proj, const Position& offset, const Boundary& orig,
      79              :                      const Boundary& conv, double scale = 1.0);
      80              : 
      81              :     /**@brief the coordinate transformation to use for input conversion and processing
      82              :      * @note instance is modified during use: boundary may adapt to new coordinates
      83              :      */
      84              :     static GeoConvHelper& getProcessing() {
      85              :         return myProcessing;
      86              :     }
      87              : 
      88              :     /// @brief the coordinate transformation that was loaded fron an input file
      89              :     static GeoConvHelper& getLoaded() {
      90              :         return myLoaded;
      91              :     }
      92              : 
      93              :     static int getNumLoaded() {
      94       590512 :         return myNumLoaded;
      95              :     }
      96              : 
      97              :     /**@brief compute the location attributes which will be used for output
      98              :      * based on the loaded location data, the given options and the transformations applied during processing
      99              :      */
     100              :     static void computeFinal(bool lefthand = false);
     101              : 
     102              :     /// @brief the coordinate transformation for writing the location element and for tracking the original coordinate system
     103              :     static const GeoConvHelper& getFinal() {
     104              :         return myFinal;
     105              :     }
     106              : 
     107              :     /// @brief sets the coordinate transformation loaded from a location element
     108              :     static void setLoaded(const GeoConvHelper& loaded);
     109              : 
     110              :     /// @brief registers the coordinate transformation as having been loaded from the given file
     111              :     static void setLoadedPlain(const std::string& nodFile, const GeoConvHelper& loaded);
     112              : 
     113              :     static GeoConvHelper* getLoadedPlain(const std::string& plainFile, const std::string& suffix = ".edg.xml");
     114              : 
     115              :     /// @brief @brief resets loaded location elements
     116              :     static void resetLoaded();
     117              : 
     118              :     /// @brief Converts the given cartesian (shifted) position to its geo (lat/long) representation
     119              :     void cartesian2geo(Position& cartesian) const;
     120              : 
     121              :     /**@brief Converts the given coordinate into a cartesian and optionally update myConvBoundary
     122              :      * @note: initializes UTM / DHDN projection on first use (select zone)
     123              :      */
     124              :     bool x2cartesian(Position& from, bool includeInBoundary = true);
     125              : 
     126              :     /// @brief Converts the given coordinate into a cartesian using the previous initialisation
     127              :     bool x2cartesian_const(Position& from) const;
     128              : 
     129              :     /// @brief Returns whether a transformation from geo to metric coordinates will be performed
     130              :     bool usingGeoProjection() const;
     131              : 
     132              :     /// @brief Returns the information whether an inverse transformation will happen
     133              :     bool usingInverseGeoProjection() const;
     134              : 
     135              :     /// @brief Shifts the converted boundary by the given amounts
     136              :     void moveConvertedBy(double x, double y);
     137              : 
     138              :     /// @brief Returns the original boundary
     139              :     const Boundary& getOrigBoundary() const;
     140              : 
     141              :     /// @brief Returns the converted boundary
     142              :     const Boundary& getConvBoundary() const;
     143              : 
     144              :     /// @brief sets the converted boundary
     145              :     void setConvBoundary(const Boundary& boundary) {
     146              :         myConvBoundary = boundary;
     147              :     }
     148              : 
     149              :     /// @brief Returns the network offset
     150              :     const Position getOffset() const;
     151              : 
     152              :     /// @brief Returns the network base
     153              :     const Position getOffsetBase() const;
     154              : 
     155              :     /// @brief Returns the original projection definition
     156              :     const std::string& getProjString() const;
     157              : 
     158              :     /// @brief init projString such as 'UTM' in loaded projection
     159              :     void resolveAbstractProjection();
     160              : 
     161              :     /// @brief @brief writes the location element
     162              :     static void writeLocation(OutputDevice& into);
     163              : 
     164              :     bool operator==(const GeoConvHelper& o) const;
     165              : 
     166              :     bool operator!=(const GeoConvHelper& o) const {
     167         2326 :         return !(*this == o);
     168              :     }
     169              : 
     170              : private:
     171              :     /// @brief projection method
     172              :     enum ProjectionMethod {
     173              :         NONE,
     174              :         SIMPLE,
     175              :         UTM,
     176              :         DHDN,
     177              :         DHDN_UTM,
     178              :         PROJ
     179              :     };
     180              : 
     181              :     /// @brief A proj options string describing the proj.4-projection to use
     182              :     std::string myProjString;
     183              : 
     184              : #ifdef PROJ_API_FILE
     185              :     void initProj(const std::string& proj);
     186              : 
     187              : #ifdef PROJ_VERSION_MAJOR
     188              :     bool checkError(projPJ projection) const;
     189              : #endif
     190              : 
     191              :     /// @brief The proj.4-projection to use
     192              :     projPJ myProjection;
     193              : 
     194              :     /// @brief The inverse proj.4-projection to use first
     195              :     projPJ myInverseProjection;
     196              : 
     197              :     /// @brief The geo proj.4-projection which is the target of the inverse projection
     198              :     projPJ myGeoProjection;
     199              : #endif
     200              : 
     201              :     /// @brief The offset to apply
     202              :     Position myOffset;
     203              : 
     204              :     /// @brief The scaling to apply to geo-coordinates
     205              :     double myGeoScale;
     206              : 
     207              :     /// @brief The rotation to apply to geo-coordinates
     208              :     double mySin;
     209              :     double myCos;
     210              : 
     211              :     /// @brief Information whether no projection shall be done
     212              :     ProjectionMethod myProjectionMethod;
     213              : 
     214              :     /// @brief Information whether inverse projection shall be used
     215              :     bool myUseInverseProjection;
     216              : 
     217              :     /// @brief whether to discard z-data
     218              :     bool myFlatten;
     219              : 
     220              :     /// @brief The boundary before conversion (x2cartesian)
     221              :     Boundary myOrigBoundary;
     222              : 
     223              :     /// @brief The boundary after conversion (x2cartesian)
     224              :     Boundary myConvBoundary;
     225              : 
     226              :     /// @brief coordinate transformation to use for input conversion and processing
     227              :     static GeoConvHelper myProcessing;
     228              : 
     229              :     /// @brief coordinate transformation loaded from a location element
     230              :     static GeoConvHelper myLoaded;
     231              : 
     232              :     /// @brief coordinate transformation to use for writing the location element and for tracking the original coordinate system
     233              :     static GeoConvHelper myFinal;
     234              : 
     235              :     /// @brief the numer of coordinate transformations loaded from location elements
     236              :     static int myNumLoaded;
     237              : 
     238              :     /// @brief the projections loaded from .nod.xml (to be re-used when loading edg.xml)
     239              :     static std::map<std::string, std::pair<std::string, Position> > myLoadedPlain;
     240              : 
     241              :     /// @brief make assignment operator private
     242              :     GeoConvHelper& operator=(const GeoConvHelper&);
     243              : 
     244              :     /// @brief invalidated copy constructor.
     245              :     GeoConvHelper(const GeoConvHelper&) = delete;
     246              : };
        

Generated by: LCOV version 2.0-1