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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // static methods for processing the coordinates conversion for the current net
18 /****************************************************************************/
19 #ifndef GeoConvHelper_h
20 #define GeoConvHelper_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <map>
29 #include <string>
30 #include <utils/geom/Position.h>
31 #include <utils/geom/Boundary.h>
32 
33 #ifdef PROJ_API_FILE
34 #include PROJ_API_FILE
35 #ifdef PROJ_VERSION_MAJOR
36 typedef PJ* projPJ;
37 #endif
38 #endif
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 
45 class OptionsCont;
46 class PositionVector;
47 class OutputDevice;
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
57 public:
58 
63 
65  GeoConvHelper(const std::string& proj, const Position& offset,
66  const Boundary& orig, const Boundary& conv, double scale = 1.0, double rot = 0.0, bool inverse = false, bool flatten = false);
67 
70 
75  static void addProjectionOptions(OptionsCont& oc);
76 
78  static bool init(OptionsCont& oc);
79 
81  static void init(const std::string& proj, const Position& offset, const Boundary& orig,
82  const Boundary& conv, double scale = 1.0);
83 
88  return myProcessing;
89  }
90 
93  return myLoaded;
94  }
95 
96  static int getNumLoaded() {
97  return myNumLoaded;
98  }
99 
103  static void computeFinal(bool lefthand = false);
104 
106  static const GeoConvHelper& getFinal() {
107  return myFinal;
108  }
109 
111  static void setLoaded(const GeoConvHelper& loaded);
112 
114  static void resetLoaded();
115 
117  void cartesian2geo(Position& cartesian) const;
118 
122  bool x2cartesian(Position& from, bool includeInBoundary = true);
123 
125  bool x2cartesian_const(Position& from) const;
126 
128  bool usingGeoProjection() const;
129 
131  bool usingInverseGeoProjection() const;
132 
134  void moveConvertedBy(double x, double y);
135 
137  const Boundary& getOrigBoundary() const;
138 
140  const Boundary& getConvBoundary() const;
141 
143  void setConvBoundary(const Boundary& boundary) {
144  myConvBoundary = boundary;
145  }
146 
148  const Position getOffset() const;
149 
151  const Position getOffsetBase() const;
152 
154  const std::string& getProjString() const;
155 
157  static void writeLocation(OutputDevice& into);
158 
159  bool operator==(const GeoConvHelper& o) const;
160 
161  bool operator!=(const GeoConvHelper& o) const {
162  return !(*this == o);
163  }
164 
165 private:
174  };
175 
177  std::string myProjString;
178 
179 #ifdef PROJ_API_FILE
180  projPJ myProjection;
182 
184  projPJ myInverseProjection;
185 
187  projPJ myGeoProjection;
188 #endif
189 
192 
194  double myGeoScale;
195 
197  double mySin;
198  double myCos;
199 
202 
205 
207  bool myFlatten;
208 
211 
214 
217 
220 
223 
225  static int myNumLoaded;
226 
229 
231  GeoConvHelper(const GeoConvHelper&) = delete;
232 };
233 
234 
235 #endif
236 
237 /****************************************************************************/
238 
static void writeLocation(OutputDevice &into)
writes the location element
void setConvBoundary(const Boundary &boundary)
sets the converted boundary
bool operator!=(const GeoConvHelper &o) const
static GeoConvHelper myProcessing
coordinate transformation to use for input conversion and processing
~GeoConvHelper()
Destructor.
const Boundary & getConvBoundary() const
Returns the converted boundary.
Position myOffset
The offset to apply.
static void computeFinal(bool lefthand=false)
compute the location attributes which will be used for output based on the loaded location data...
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:87
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
ProjectionMethod
projection method
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
double mySin
The rotation to apply to geo-coordinates.
Boundary myOrigBoundary
The boundary before conversion (x2cartesian)
static void setLoaded(const GeoConvHelper &loaded)
sets the coordinate transformation loaded from a location element
static GeoConvHelper & getLoaded()
the coordinate transformation that was loaded fron an input file
Definition: GeoConvHelper.h:92
const Boundary & getOrigBoundary() const
Returns the original boundary.
bool myFlatten
whether to discard z-data
static GeoConvHelper myLoaded
coordinate transformation loaded from a location element
const std::string & getProjString() const
Returns the original projection definition.
static void resetLoaded()
resets loaded location elements
bool myUseInverseProjection
Information whether inverse projection shall be used.
void moveConvertedBy(double x, double y)
Shifts the converted boundary by the given amounts.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
double myGeoScale
The scaling to apply to geo-coordinates.
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:56
static GeoConvHelper myFinal
coordinate transformation to use for writing the location element and for tracking the original coord...
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
ProjectionMethod myProjectionMethod
Information whether no projection shall be done.
std::string myProjString
A proj options string describing the proj.4-projection to use.
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
GeoConvHelper(OptionsCont &oc)
Constructor based on the stored options.
Boundary myConvBoundary
The boundary after conversion (x2cartesian)
static int myNumLoaded
the numer of coordinate transformations loaded from location elements
bool operator==(const GeoConvHelper &o) const
static int getNumLoaded()
Definition: GeoConvHelper.h:96
A storage for options typed value containers)
Definition: OptionsCont.h:90
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
bool usingInverseGeoProjection() const
Returns the information whether an inverse transformation will happen.
const Position getOffsetBase() const
Returns the network base.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation. ...
const Position getOffset() const
Returns the network offset.
GeoConvHelper & operator=(const GeoConvHelper &)
make assignment operator private