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-2018 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 HAVE_PROJ
34 #include <proj_api.h>
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:
171  };
172 
174  std::string myProjString;
175 
176 #ifdef HAVE_PROJ
177  projPJ myProjection;
179 
181  projPJ myInverseProjection;
182 
184  projPJ myGeoProjection;
185 #endif
186 
189 
191  double myGeoScale;
192 
194  double mySin;
195  double myCos;
196 
199 
202 
204  bool myFlatten;
205 
208 
211 
214 
217 
220 
222  static int myNumLoaded;
223 
226 
228  GeoConvHelper(const GeoConvHelper&) = delete;
229 };
230 
231 
232 #endif
233 
234 /****************************************************************************/
235 
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:84
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:89
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:53
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:93
A storage for options typed value containers)
Definition: OptionsCont.h:92
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