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.org/sumo
3 // Copyright (C) 2001-2022 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 resetLoaded();
112 
114  void cartesian2geo(Position& cartesian) const;
115 
119  bool x2cartesian(Position& from, bool includeInBoundary = true);
120 
122  bool x2cartesian_const(Position& from) const;
123 
125  bool usingGeoProjection() const;
126 
128  bool usingInverseGeoProjection() const;
129 
131  void moveConvertedBy(double x, double y);
132 
134  const Boundary& getOrigBoundary() const;
135 
137  const Boundary& getConvBoundary() const;
138 
140  void setConvBoundary(const Boundary& boundary) {
141  myConvBoundary = boundary;
142  }
143 
145  const Position getOffset() const;
146 
148  const Position getOffsetBase() const;
149 
151  const std::string& getProjString() const;
152 
154  static void writeLocation(OutputDevice& into);
155 
156  bool operator==(const GeoConvHelper& o) const;
157 
158  bool operator!=(const GeoConvHelper& o) const {
159  return !(*this == o);
160  }
161 
162 private:
170  PROJ
171  };
172 
174  std::string myProjString;
175 
176 #ifdef PROJ_API_FILE
177  void initProj(const std::string& proj);
178 
180  projPJ myProjection;
181 
183  projPJ myInverseProjection;
184 
186  projPJ myGeoProjection;
187 #endif
188 
191 
193  double myGeoScale;
194 
196  double mySin;
197  double myCos;
198 
201 
204 
206  bool myFlatten;
207 
210 
213 
216 
219 
222 
224  static int myNumLoaded;
225 
228 
230  GeoConvHelper(const GeoConvHelper&) = delete;
231 };
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
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.
bool usingInverseGeoProjection() const
Returns the information whether an inverse transformation will happen.
bool operator==(const GeoConvHelper &o) const
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 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.