1
1
2
2
#include < terrain_navigation_ros/geo_conversions.h>
3
3
4
- Eigen::Vector3d GeoConversions::transformCoordinates (EPSG src_coord, EPSG tgt_coord,
5
- const Eigen::Vector3d source_coordinates) {
6
- Eigen::Vector3d target_coordinates;
7
- if (src_coord == EPSG::WGS84 && tgt_coord == EPSG::CH1903_LV03) {
8
- GeoConversions::_forward (source_coordinates (0 ), source_coordinates (1 ), source_coordinates (2 ), target_coordinates (0 ),
9
- target_coordinates (1 ), target_coordinates (2 ));
10
- return target_coordinates;
11
- } else if (src_coord == EPSG::CH1903_LV03 && tgt_coord == EPSG::WGS84) {
12
- GeoConversions::_reverse (source_coordinates (0 ), source_coordinates (1 ), source_coordinates (2 ), target_coordinates (0 ),
13
- target_coordinates (1 ), target_coordinates (2 ));
14
- return target_coordinates;
15
- } else
16
- return GeoConversions::_transformUsingGDAL (src_coord, tgt_coord, source_coordinates);
17
- };
18
-
19
4
Eigen::Vector3d _transformUsingGDAL (EPSG src_coord, EPSG tgt_coord, const Eigen::Vector3d source_coordinates) {
20
5
OGRSpatialReference source, target;
21
6
source.importFromEPSG (static_cast <int >(src_coord));
@@ -39,8 +24,23 @@ Eigen::Vector3d _transformUsingGDAL(EPSG src_coord, EPSG tgt_coord, const Eigen:
39
24
return target_coordinates;
40
25
};
41
26
42
- static void GeoConversions::_forward (const double lat, const double lon, const double alt, double &y, double &x,
43
- double &h) {
27
+ Eigen::Vector3d GeoConversions::transformCoordinates (EPSG src_coord, EPSG tgt_coord,
28
+ const Eigen::Vector3d source_coordinates) {
29
+ Eigen::Vector3d target_coordinates;
30
+ if (src_coord == EPSG::WGS84 && tgt_coord == EPSG::CH1903_LV03) {
31
+ _forward (source_coordinates (0 ), source_coordinates (1 ), source_coordinates (2 ), target_coordinates (0 ),
32
+ target_coordinates (1 ), target_coordinates (2 ));
33
+ return target_coordinates;
34
+ } else if (src_coord == EPSG::CH1903_LV03 && tgt_coord == EPSG::WGS84) {
35
+ _reverse (source_coordinates (0 ), source_coordinates (1 ), source_coordinates (2 ), target_coordinates (0 ),
36
+ target_coordinates (1 ), target_coordinates (2 ));
37
+ return target_coordinates;
38
+ }
39
+ // else
40
+ return _transformUsingGDAL (src_coord, tgt_coord, source_coordinates);
41
+ };
42
+
43
+ void GeoConversions::_forward (const double lat, const double lon, const double alt, double &y, double &x, double &h) {
44
44
// 1. Convert the ellipsoidal latitudes φ and longitudes λ into arcseconds ["]
45
45
const double lat_arc = lat * 3600.0 ;
46
46
const double lon_arc = lon * 3600.0 ;
@@ -66,8 +66,7 @@ static void GeoConversions::_forward(const double lat, const double lon, const d
66
66
h = alt - 49.55 + 2.73 * lon_aux + 6.94 * lat_aux;
67
67
};
68
68
69
- static void GeoConversions::_reverse (const double y, const double x, const double h, double &lat, double &lon,
70
- double &alt) {
69
+ void GeoConversions::_reverse (const double y, const double x, const double h, double &lat, double &lon, double &alt) {
71
70
// 1. Convert the projection coordinates E (easting) and N (northing) in LV95 (or y / x in LV03) into the civilian
72
71
// system (Bern = 0 / 0) and express in the unit [1000 km]: E' = (E – 2600000 m)/1000000 = (y – 600000 m)/1000000
73
72
// N' = (N – 1200000 m)/1000000 = (x – 200000 m)/1000000
0 commit comments