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 890253 : 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& edgFile); 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 : /// @brief The proj.4-projection to use 188 : projPJ myProjection; 189 : 190 : /// @brief The inverse proj.4-projection to use first 191 : projPJ myInverseProjection; 192 : 193 : /// @brief The geo proj.4-projection which is the target of the inverse projection 194 : projPJ myGeoProjection; 195 : #endif 196 : 197 : /// @brief The offset to apply 198 : Position myOffset; 199 : 200 : /// @brief The scaling to apply to geo-coordinates 201 : double myGeoScale; 202 : 203 : /// @brief The rotation to apply to geo-coordinates 204 : double mySin; 205 : double myCos; 206 : 207 : /// @brief Information whether no projection shall be done 208 : ProjectionMethod myProjectionMethod; 209 : 210 : /// @brief Information whether inverse projection shall be used 211 : bool myUseInverseProjection; 212 : 213 : /// @brief whether to discard z-data 214 : bool myFlatten; 215 : 216 : /// @brief The boundary before conversion (x2cartesian) 217 : Boundary myOrigBoundary; 218 : 219 : /// @brief The boundary after conversion (x2cartesian) 220 : Boundary myConvBoundary; 221 : 222 : /// @brief coordinate transformation to use for input conversion and processing 223 : static GeoConvHelper myProcessing; 224 : 225 : /// @brief coordinate transformation loaded from a location element 226 : static GeoConvHelper myLoaded; 227 : 228 : /// @brief coordinate transformation to use for writing the location element and for tracking the original coordinate system 229 : static GeoConvHelper myFinal; 230 : 231 : /// @brief the numer of coordinate transformations loaded from location elements 232 : static int myNumLoaded; 233 : 234 : /// @brief the projections loaded from .nod.xml (to be re-used when loading edg.xml) 235 : static std::map<std::string, std::pair<std::string, Position> > myLoadedPlain; 236 : 237 : /// @brief make assignment operator private 238 : GeoConvHelper& operator=(const GeoConvHelper&); 239 : 240 : /// @brief invalidated copy constructor. 241 : GeoConvHelper(const GeoConvHelper&) = delete; 242 : };