Eclipse SUMO - Simulation of Urban MObility
GeoConvHelper.h
Go to the documentation of this file.
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 /****************************************************************************/
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 // ===========================================================================
54 public:
55 
60 
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 
67 
72  static void addProjectionOptions(OptionsCont& oc);
73 
75  static bool init(OptionsCont& oc);
76 
78  static void init(const std::string& proj, const Position& offset, const Boundary& orig,
79  const Boundary& conv, double scale = 1.0);
80 
85  return myProcessing;
86  }
87 
90  return myLoaded;
91  }
92 
93  static int getNumLoaded() {
94  return myNumLoaded;
95  }
96 
100  static void computeFinal(bool lefthand = false);
101 
103  static const GeoConvHelper& getFinal() {
104  return myFinal;
105  }
106 
108  static void setLoaded(const GeoConvHelper& loaded);
109 
111  static void setLoadedPlain(const std::string& nodFile, const GeoConvHelper& loaded);
112 
113  static GeoConvHelper* getLoadedPlain(const std::string& edgFile);
114 
116  static void resetLoaded();
117 
119  void cartesian2geo(Position& cartesian) const;
120 
124  bool x2cartesian(Position& from, bool includeInBoundary = true);
125 
127  bool x2cartesian_const(Position& from) const;
128 
130  bool usingGeoProjection() const;
131 
133  bool usingInverseGeoProjection() const;
134 
136  void moveConvertedBy(double x, double y);
137 
139  const Boundary& getOrigBoundary() const;
140 
142  const Boundary& getConvBoundary() const;
143 
145  void setConvBoundary(const Boundary& boundary) {
146  myConvBoundary = boundary;
147  }
148 
150  const Position getOffset() const;
151 
153  const Position getOffsetBase() const;
154 
156  const std::string& getProjString() const;
157 
160 
162  static void writeLocation(OutputDevice& into);
163 
164  bool operator==(const GeoConvHelper& o) const;
165 
166  bool operator!=(const GeoConvHelper& o) const {
167  return !(*this == o);
168  }
169 
170 private:
178  PROJ
179  };
180 
182  std::string myProjString;
183 
184 #ifdef PROJ_API_FILE
185  void initProj(const std::string& proj);
186 
188  projPJ myProjection;
189 
191  projPJ myInverseProjection;
192 
194  projPJ myGeoProjection;
195 #endif
196 
199 
201  double myGeoScale;
202 
204  double mySin;
205  double myCos;
206 
209 
212 
214  bool myFlatten;
215 
218 
221 
224 
227 
230 
232  static int myNumLoaded;
233 
235  static std::map<std::string, std::pair<std::string, Position> > myLoadedPlain;
236 
239 
241  GeoConvHelper(const GeoConvHelper&) = delete;
242 };
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:53
static void resetLoaded()
resets loaded location elements
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:84
static void setLoadedPlain(const std::string &nodFile, const GeoConvHelper &loaded)
registers the coordinate transformation as having been loaded from the given file
const Position getOffset() const
Returns the network offset.
static void writeLocation(OutputDevice &into)
writes the location element
Boundary myOrigBoundary
The boundary before conversion (x2cartesian)
void setConvBoundary(const Boundary &boundary)
sets the converted boundary
ProjectionMethod
projection method
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
GeoConvHelper & operator=(const GeoConvHelper &)
make assignment operator private
ProjectionMethod myProjectionMethod
Information whether no projection shall be done.
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
GeoConvHelper(OptionsCont &oc)
Constructor based on the stored options.
Position myOffset
The offset to apply.
void moveConvertedBy(double x, double y)
Shifts the converted boundary by the given amounts.
static GeoConvHelper * getLoadedPlain(const std::string &edgFile)
bool usingInverseGeoProjection() const
Returns the information whether an inverse transformation will happen.
bool operator==(const GeoConvHelper &o) const
void resolveAbstractProjection()
init projString such as 'UTM' in loaded projection
const std::string & getProjString() const
Returns the original projection definition.
const Boundary & getOrigBoundary() const
Returns the original boundary.
double mySin
The rotation to apply to geo-coordinates.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
static GeoConvHelper & getLoaded()
the coordinate transformation that was loaded fron an input file
Definition: GeoConvHelper.h:89
static GeoConvHelper myLoaded
coordinate transformation loaded from a location element
static int getNumLoaded()
Definition: GeoConvHelper.h:93
static GeoConvHelper myFinal
coordinate transformation to use for writing the location element and for tracking the original coord...
static void setLoaded(const GeoConvHelper &loaded)
sets the coordinate transformation loaded from a location element
double myGeoScale
The scaling to apply to geo-coordinates.
const Position getOffsetBase() const
Returns the network base.
GeoConvHelper(const GeoConvHelper &)=delete
invalidated copy constructor.
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
bool myFlatten
whether to discard z-data
bool myUseInverseProjection
Information whether inverse projection shall be used.
Boundary myConvBoundary
The boundary after conversion (x2cartesian)
static void computeFinal(bool lefthand=false)
compute the location attributes which will be used for output based on the loaded location data,...
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
const Boundary & getConvBoundary() const
Returns the converted boundary.
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation.
~GeoConvHelper()
Destructor.
std::string myProjString
A proj options string describing the proj.4-projection to use.
bool operator!=(const GeoConvHelper &o) const
static int myNumLoaded
the numer of coordinate transformations loaded from location elements
static std::map< std::string, std::pair< std::string, Position > > myLoadedPlain
the projections loaded from .nod.xml (to be re-used when loading edg.xml)
static GeoConvHelper myProcessing
coordinate transformation to use for input conversion and processing
A storage for options typed value containers)
Definition: OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.