43
43
#include < grid_map_ros/GridMapRosConverter.hpp>
44
44
45
45
#include " grid_map_geo/geo_conversions.h"
46
+ #include < gdal/ogr_spatialref.h>
47
+
48
+ void transformCoordinates (int src_coord, const double &x, const double &y, const double &z, int tgt_coord,
49
+ double &x_t , double &y_t , double &z_t ) {
50
+ OGRSpatialReference source, target;
51
+ source.importFromEPSG (src_coord);
52
+ target.importFromEPSG (tgt_coord);
53
+
54
+ OGRPoint p;
55
+ p.setX (x);
56
+ p.setY (y);
57
+ p.setZ (z);
58
+ p.assignSpatialReference (&source);
59
+
60
+ p.transformTo (&target);
61
+ x_t = p.getX ();
62
+ y_t = p.getY ();
63
+ z_t = p.getZ ();
64
+ return ;
65
+ }
46
66
47
- void LoadTerrainFromVrt (std::string path, const Eigen::Vector3d &query_position, const Eigen::Vector2d &offset, grid_map::GridMap &map, grid_map::GridMap &vrt_map_object) {
67
+ void LoadTerrainFromVrt (std::string path, const Eigen::Vector3d &query_position, const Eigen::Vector2d &offset,
68
+ grid_map::GridMap &map, grid_map::GridMap &vrt_map_object) {
48
69
std::shared_ptr<GridMapGeo> vrt_map = std::make_shared<GridMapGeo>();
49
70
50
71
Eigen::Vector3d query_position_lv03 = query_position;
51
72
// / Convert LV03 to WGS84
52
73
Eigen::Vector3d map_center_wgs84; // Map center in WGS84
53
- GeoConversions::reverse (query_position_lv03 (0 ), query_position_lv03 (1 ), query_position_lv03 (2 ), map_center_wgs84.x (),
74
+ // GeoConversions::reverse(query_position_lv03(0), query_position_lv03(1), query_position_lv03(2), map_center_wgs84.x(),
75
+ // map_center_wgs84.y(), map_center_wgs84.z());
76
+ transformCoordinates (21781 , query_position_lv03 (0 ), query_position_lv03 (1 ), query_position_lv03 (2 ), 4326 , map_center_wgs84.x (),
54
77
map_center_wgs84.y (), map_center_wgs84.z ());
55
78
56
79
std::cout << " Loading VRT Map:" << std::endl;
57
80
std::cout << " - map_center_wgs84:" << map_center_wgs84.transpose () << std::endl;
58
- // /TODO: Discover extent from corners
81
+ // / TODO: Discover extent from corners
59
82
Eigen::Vector2d extent_wgs84 (0.5 , 0.5 );
60
83
vrt_map->initializeFromVrt (path, map_center_wgs84.head (2 ), extent_wgs84);
61
84
std::cout << " - Success!" << std::endl;
@@ -70,9 +93,9 @@ void LoadTerrainFromVrt(std::string path, const Eigen::Vector3d &query_position,
70
93
map.setFrameId (" map" );
71
94
for (grid_map::GridMapIterator iterator (map); !iterator.isPastEnd (); ++iterator) {
72
95
const grid_map::Index index = *iterator;
73
- Eigen::Vector2d cell_position; // Position of cell relative to map coordinates
96
+ Eigen::Vector2d cell_position; // Position of cell relative to map coordinates
74
97
map.getPosition (index, cell_position);
75
- auto cell_position_lv03 = cell_position + query_position_lv03.head (2 );// Position of cell in CH1903/LV03
98
+ auto cell_position_lv03 = cell_position + query_position_lv03.head (2 ); // Position of cell in CH1903/LV03
76
99
double dummy;
77
100
Eigen::Vector2d cell_position_wgs84;
78
101
GeoConversions::reverse (cell_position_lv03 (0 ), cell_position_lv03 (1 ), 0.0 , cell_position_wgs84.x (),
@@ -106,7 +129,7 @@ int main(int argc, char **argv) {
106
129
107
130
for (int i = 0 ; i < 4 ; i++) {
108
131
Eigen::Vector3d offset = static_cast <double >(i) * Eigen::Vector3d (2500.0 , 2500.0 , 0.0 );
109
- Eigen::Vector3d query_position = test_position + offset;
132
+ Eigen::Vector3d query_position = test_position + offset;
110
133
111
134
grid_map::GridMap map;
112
135
grid_map::GridMap vrt_map;
@@ -117,13 +140,11 @@ int main(int argc, char **argv) {
117
140
grid_map::GridMapRosConverter::toMessage (map, msg);
118
141
map_pub.publish (msg);
119
142
120
-
121
143
grid_map_msgs::GridMap msg2;
122
144
grid_map::GridMapRosConverter::toMessage (vrt_map, msg2);
123
145
map_pub2.publish (msg2);
124
146
}
125
147
126
-
127
148
ros::spin ();
128
149
return 0 ;
129
150
}
0 commit comments