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 
GeoConvHelper::writeLocation
static void writeLocation(OutputDevice &into)
writes the location element
Definition: GeoConvHelper.cpp:557
Boundary.h
GeoConvHelper::NONE
Definition: GeoConvHelper.h:168
GeoConvHelper::operator!=
bool operator!=(const GeoConvHelper &o) const
Definition: GeoConvHelper.h:161
GeoConvHelper::getConvBoundary
const Boundary & getConvBoundary() const
Returns the converted boundary.
Definition: GeoConvHelper.cpp:490
GeoConvHelper::operator=
GeoConvHelper & operator=(const GeoConvHelper &)
make assignment operator private
Definition: GeoConvHelper.cpp:138
GeoConvHelper::x2cartesian_const
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation.
Definition: GeoConvHelper.cpp:418
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
GeoConvHelper::ProjectionMethod
ProjectionMethod
projection method
Definition: GeoConvHelper.h:167
GeoConvHelper::myCos
double myCos
Definition: GeoConvHelper.h:198
GeoConvHelper::setConvBoundary
void setConvBoundary(const Boundary &boundary)
sets the converted boundary
Definition: GeoConvHelper.h:143
GeoConvHelper::setLoaded
static void setLoaded(const GeoConvHelper &loaded)
sets the coordinate transformation loaded from a location element
Definition: GeoConvHelper.cpp:540
GeoConvHelper::PROJ
Definition: GeoConvHelper.h:173
GeoConvHelper::getProcessing
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:87
GeoConvHelper::myLoaded
static GeoConvHelper myLoaded
coordinate transformation loaded from a location element
Definition: GeoConvHelper.h:219
GeoConvHelper::getOffset
const Position getOffset() const
Returns the network offset.
Definition: GeoConvHelper.cpp:496
GeoConvHelper::getLoaded
static GeoConvHelper & getLoaded()
the coordinate transformation that was loaded fron an input file
Definition: GeoConvHelper.h:92
PositionVector
A list of positions.
Definition: PositionVector.h:46
GeoConvHelper
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:56
GeoConvHelper::init
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
Definition: GeoConvHelper.cpp:201
GeoConvHelper::x2cartesian
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
Definition: GeoConvHelper.cpp:327
GeoConvHelper::usingGeoProjection
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
Definition: GeoConvHelper.cpp:282
GeoConvHelper::getProjString
const std::string & getProjString() const
Returns the original projection definition.
Definition: GeoConvHelper.cpp:508
GeoConvHelper::myOrigBoundary
Boundary myOrigBoundary
The boundary before conversion (x2cartesian)
Definition: GeoConvHelper.h:210
GeoConvHelper::moveConvertedBy
void moveConvertedBy(double x, double y)
Shifts the converted boundary by the given amounts.
Definition: GeoConvHelper.cpp:477
GeoConvHelper::~GeoConvHelper
~GeoConvHelper()
Destructor.
Definition: GeoConvHelper.cpp:95
GeoConvHelper::myConvBoundary
Boundary myConvBoundary
The boundary after conversion (x2cartesian)
Definition: GeoConvHelper.h:213
GeoConvHelper::myUseInverseProjection
bool myUseInverseProjection
Information whether inverse projection shall be used.
Definition: GeoConvHelper.h:204
GeoConvHelper::getFinal
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
Definition: GeoConvHelper.h:106
GeoConvHelper::GeoConvHelper
GeoConvHelper(OptionsCont &oc)
Constructor based on the stored options.
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
GeoConvHelper::addProjectionOptions
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
Definition: GeoConvHelper.cpp:249
GeoConvHelper::myProjString
std::string myProjString
A proj options string describing the proj.4-projection to use.
Definition: GeoConvHelper.h:177
GeoConvHelper::getOrigBoundary
const Boundary & getOrigBoundary() const
Returns the original boundary.
Definition: GeoConvHelper.cpp:484
GeoConvHelper::cartesian2geo
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
Definition: GeoConvHelper.cpp:294
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
GeoConvHelper::getOffsetBase
const Position getOffsetBase() const
Returns the network base.
Definition: GeoConvHelper.cpp:502
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
GeoConvHelper::DHDN
Definition: GeoConvHelper.h:171
GeoConvHelper::SIMPLE
Definition: GeoConvHelper.h:169
GeoConvHelper::myFlatten
bool myFlatten
whether to discard z-data
Definition: GeoConvHelper.h:207
GeoConvHelper::operator==
bool operator==(const GeoConvHelper &o) const
Definition: GeoConvHelper.cpp:122
Position.h
GeoConvHelper::myNumLoaded
static int myNumLoaded
the numer of coordinate transformations loaded from location elements
Definition: GeoConvHelper.h:225
GeoConvHelper::DHDN_UTM
Definition: GeoConvHelper.h:172
GeoConvHelper::UTM
Definition: GeoConvHelper.h:170
GeoConvHelper::myGeoScale
double myGeoScale
The scaling to apply to geo-coordinates.
Definition: GeoConvHelper.h:194
GeoConvHelper::myOffset
Position myOffset
The offset to apply.
Definition: GeoConvHelper.h:191
GeoConvHelper::computeFinal
static void computeFinal(bool lefthand=false)
compute the location attributes which will be used for output based on the loaded location data,...
Definition: GeoConvHelper.cpp:514
GeoConvHelper::usingInverseGeoProjection
bool usingInverseGeoProjection() const
Returns the information whether an inverse transformation will happen.
Definition: GeoConvHelper.cpp:288
config.h
GeoConvHelper::myFinal
static GeoConvHelper myFinal
coordinate transformation to use for writing the location element and for tracking the original coord...
Definition: GeoConvHelper.h:222
GeoConvHelper::myProjectionMethod
ProjectionMethod myProjectionMethod
Information whether no projection shall be done.
Definition: GeoConvHelper.h:201
GeoConvHelper::resetLoaded
static void resetLoaded()
resets loaded location elements
Definition: GeoConvHelper.cpp:551
GeoConvHelper::mySin
double mySin
The rotation to apply to geo-coordinates.
Definition: GeoConvHelper.h:197
GeoConvHelper::myProcessing
static GeoConvHelper myProcessing
coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:216
GeoConvHelper::getNumLoaded
static int getNumLoaded()
Definition: GeoConvHelper.h:96