UTM.cpp
Go to the documentation of this file.
2 
3 #include <GeographicLib/UTMUPS.hpp>
4 
5 namespace lanelet {
6 namespace projection {
7 
8 UtmProjector::UtmProjector(Origin origin, const bool useOffset, const bool throwInPaddingArea)
9  : Projector(origin), useOffset_{useOffset}, throwInPaddingArea_{throwInPaddingArea} {
10  double x = 0;
11  double y = 0;
12  GeographicLib::UTMUPS::Forward(this->origin().position.lat, this->origin().position.lon, zone_,
13  isInNorthernHemisphere_, x, y);
14  if (useOffset_) {
15  xOffset_ = x;
16  yOffset_ = y;
17  }
18 }
19 
21  BasicPoint3d utm{0., 0., gps.ele};
22  int zone{};
23  bool northp{};
24  try {
25  GeographicLib::UTMUPS::Forward(gps.lat, gps.lon, zone, northp, utm.x(), utm.y());
26  } catch (GeographicLib::GeographicErr& e) {
27  throw ForwardProjectionError(e.what());
28  }
29 
30  if (zone != zone_ || northp != isInNorthernHemisphere_) {
31  if (throwInPaddingArea_) {
32  throw ForwardProjectionError("You have left the UTM zone or changed the hemisphere!");
33  }
34  // try to transfer to the desired zone
35  double xAfterTransfer = 0;
36  double yAfterTransfer = 0;
37  int zoneAfterTransfer = 0;
38  try {
39  GeographicLib::UTMUPS::Transfer(zone, northp, utm.x(), utm.y(), zone_, isInNorthernHemisphere_, xAfterTransfer,
40  yAfterTransfer, zoneAfterTransfer);
41  } catch (GeographicLib::GeographicErr& e) {
42  throw ForwardProjectionError(e.what());
43  }
44 
45  if (zoneAfterTransfer != zone_) {
46  throw ForwardProjectionError("You have left the padding area of the UTM zone!");
47  }
48  utm.x() = xAfterTransfer;
49  utm.y() = yAfterTransfer;
50  }
51 
52  if (useOffset_) {
53  utm.x() -= xOffset_;
54  utm.y() -= yOffset_;
55  }
56 
57  return utm;
58 }
59 
61  GPSPoint gps{0., 0., utm.z()};
62  try {
63  GeographicLib::UTMUPS::Reverse(zone_, isInNorthernHemisphere_, useOffset_ ? utm.x() + xOffset_ : utm.x(),
64  useOffset_ ? utm.y() + yOffset_ : utm.y(), gps.lat, gps.lon);
65  } catch (GeographicLib::GeographicErr& e) {
66  throw ReverseProjectionError(e.what());
67  }
68 
69  if (throwInPaddingArea_) {
70  // for zone compliance testing:
71  try {
72  forward(gps);
73  } catch (ForwardProjectionError& e) {
74  throw ReverseProjectionError(e.what());
75  };
76  }
77  return gps;
78 }
79 
80 } // namespace projection
81 } // namespace lanelet
lanelet::projection::UtmProjector::isInNorthernHemisphere_
bool isInNorthernHemisphere_
Definition: UTM.h:17
lanelet::projection::UtmProjector::zone_
int zone_
Definition: UTM.h:16
lanelet::projection::UtmProjector::UtmProjector
UtmProjector(Origin origin, bool useOffset=true, bool throwInPaddingArea=false)
Definition: UTM.cpp:8
lanelet
lanelet::projection::UtmProjector::useOffset_
bool useOffset_
Definition: UTM.h:17
lanelet::BasicPoint3d
Eigen::Vector3d BasicPoint3d
lanelet::projection::UtmProjector::forward
BasicPoint3d forward(const GPSPoint &gps) const override
Definition: UTM.cpp:20
lanelet::projection::UtmProjector::throwInPaddingArea_
bool throwInPaddingArea_
Definition: UTM.h:17
lanelet::Projector
lanelet::ReverseProjectionError
lanelet::projection::UtmProjector::yOffset_
double yOffset_
Definition: UTM.h:18
lanelet::Origin
lanelet::GPSPoint::lat
double lat
lanelet::projection::UtmProjector::xOffset_
double xOffset_
Definition: UTM.h:18
UTM.h
lanelet::GPSPoint::lon
double lon
lanelet::projection::UtmProjector::reverse
GPSPoint reverse(const BasicPoint3d &utm) const override
Definition: UTM.cpp:60
lanelet::GPSPoint::ele
double ele
lanelet::ForwardProjectionError
lanelet::GPSPoint


lanelet2_projection
Author(s): Maximilian Naumann , Fabian Poggenhans , Jan-Hendrik Pauls , MichaƂ Antkiewicz
autogenerated on Thu Mar 6 2025 03:26:06