Skip to content

Commit 9d9979e

Browse files
authored
[Backport] ESPG to EPSG rename, and enable use of non-CH1903 geotiffs… (#68)
* [Backport] ESPG to EPSG rename, and enable use of non-CH1903 geotiffs (#67) * Add UTM 32N * Add offset layer * Fix format
1 parent 0778982 commit 9d9979e

File tree

7 files changed

+43
-17
lines changed

7 files changed

+43
-17
lines changed

grid_map_geo/include/grid_map_geo/grid_map_geo.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
#include "transform.hpp"
4444
struct Location {
45-
ESPG espg{ESPG::WGS84};
45+
EPSG epsg{EPSG::WGS84};
4646
Eigen::Vector3d position{Eigen::Vector3d::Zero()};
4747
};
4848

@@ -71,16 +71,16 @@ class GridMapGeo {
7171
* @param src_coord
7272
* @param origin
7373
*/
74-
void setGlobalOrigin(ESPG src_coord, const Eigen::Vector3d origin);
74+
void setGlobalOrigin(EPSG src_coord, const Eigen::Vector3d origin);
7575

7676
/**
7777
* @brief Get the Global Origin object
7878
*
7979
* @param src_coord
8080
* @param origin
8181
*/
82-
void getGlobalOrigin(ESPG& src_coord, Eigen::Vector3d& origin) {
83-
src_coord = maporigin_.espg;
82+
void getGlobalOrigin(EPSG& src_coord, Eigen::Vector3d& origin) {
83+
src_coord = maporigin_.epsg;
8484
origin = maporigin_.position;
8585
};
8686

@@ -147,6 +147,19 @@ class GridMapGeo {
147147
bool AddLayerDistanceTransform(const double surface_distance, const std::string& layer_name,
148148
std::string reference_layer = "elevation");
149149

150+
/**
151+
* @brief Add layer with offset
152+
*
153+
* @param surface_distance surface distance to compute. If smaller than zero, will compute the offset transform
154+
* beneath the reference layer
155+
* @param layer_name
156+
* @return true
157+
* @return false
158+
*/
159+
160+
bool AddLayerOffsetTransform(const double surface_distance, const std::string& layer_name,
161+
std::string reference_layer = "elevation");
162+
150163
/**
151164
* @brief Add layer using distance transform
152165
*

grid_map_geo/include/grid_map_geo/transform.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
#include <Eigen/Dense>
3838

39-
enum class ESPG { ECEF = 4978, WGS84 = 4326, WGS84_32N = 32632, CH1903_LV03 = 21781 };
39+
enum class EPSG { ECEF = 4978, WGS84 = 4326, WGS84_32N = 32632, CH1903_LV03 = 21781, WGS84_10N = 32610 };
4040

4141
/**
4242
* @brief Helper function for transforming using gdal
@@ -46,7 +46,7 @@ enum class ESPG { ECEF = 4978, WGS84 = 4326, WGS84_32N = 32632, CH1903_LV03 = 21
4646
* @param source_coordinates
4747
* @return Eigen::Vector3d
4848
*/
49-
Eigen::Vector3d transformCoordinates(ESPG src_coord, ESPG tgt_coord, const Eigen::Vector3d source_coordinates);
49+
Eigen::Vector3d transformCoordinates(EPSG src_coord, EPSG tgt_coord, const Eigen::Vector3d source_coordinates);
5050

5151
/**
5252
* @brief Helper function for transforming using gdal
@@ -56,6 +56,6 @@ Eigen::Vector3d transformCoordinates(ESPG src_coord, ESPG tgt_coord, const Eigen
5656
* @param source_coordinates
5757
* @return Eigen::Vector3d
5858
*/
59-
Eigen::Vector3d transformCoordinates(ESPG src_coord, const std::string wkt, const Eigen::Vector3d source_coordinates);
59+
Eigen::Vector3d transformCoordinates(EPSG src_coord, const std::string wkt, const Eigen::Vector3d source_coordinates);
6060

6161
#endif // GRID_MAP_GEO_TRANSFORM_H

grid_map_geo/src/grid_map_geo.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ bool GridMapGeo::initializeFromGeotiff(const std::string &path) {
118118

119119
double mapcenter_e = originX + pixelSizeX * width * 0.5;
120120
double mapcenter_n = originY + pixelSizeY * height * 0.5;
121-
maporigin_.espg = ESPG::CH1903_LV03;
122121
maporigin_.position = Eigen::Vector3d(mapcenter_e, mapcenter_n, 0.0);
122+
maporigin_.epsg = static_cast<EPSG>(std::stoi(spatial_ref->GetAttrValue("AUTHORITY", 1)));
123123

124124
Eigen::Vector2d position{Eigen::Vector2d::Zero()};
125125

@@ -285,6 +285,19 @@ bool GridMapGeo::AddLayerDistanceTransform(const double surface_distance, const
285285
return true;
286286
}
287287

288+
bool GridMapGeo::AddLayerOffsetTransform(const double surface_distance, const std::string &layer_name,
289+
std::string reference_layer) {
290+
grid_map_.add(layer_name);
291+
292+
for (grid_map::GridMapIterator iterator(grid_map_); !iterator.isPastEnd(); ++iterator) {
293+
const grid_map::Index MapIndex = *iterator;
294+
Eigen::Vector3d center_pos;
295+
grid_map_.getPosition3(reference_layer, MapIndex, center_pos);
296+
grid_map_.at(layer_name, MapIndex) = center_pos(2) + surface_distance;
297+
}
298+
return true;
299+
}
300+
288301
bool GridMapGeo::AddLayerHorizontalDistanceTransform(const double surface_distance, const std::string &layer_name,
289302
std::string reference_layer) {
290303
grid_map_.add(layer_name);
@@ -321,9 +334,9 @@ bool GridMapGeo::AddLayerOffset(const double offset_distance, const std::string
321334
return true;
322335
}
323336

324-
void GridMapGeo::setGlobalOrigin(ESPG src_coord, const Eigen::Vector3d origin) {
337+
void GridMapGeo::setGlobalOrigin(EPSG src_coord, const Eigen::Vector3d origin) {
325338
// Transform global origin into CH1903 / LV03 coordinates
326-
maporigin_.espg = src_coord;
339+
maporigin_.epsg = src_coord;
327340
maporigin_.position = origin;
328341
}
329342

grid_map_geo/src/test_tif_loader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class MapPublisher : public rclcpp::Node {
7272
}
7373
};
7474
timer_ = this->create_wall_timer(5s, timer_callback);
75-
ESPG epsg;
75+
EPSG epsg;
7676
Eigen::Vector3d map_origin;
7777
map_->getGlobalOrigin(epsg, map_origin);
7878

grid_map_geo/src/transform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include <gdal/ogr_spatialref.h>
4646
#endif
4747

48-
Eigen::Vector3d transformCoordinates(ESPG src_coord, ESPG tgt_coord, const Eigen::Vector3d source_coordinates) {
48+
Eigen::Vector3d transformCoordinates(EPSG src_coord, EPSG tgt_coord, const Eigen::Vector3d source_coordinates) {
4949
OGRSpatialReference source, target;
5050
source.importFromEPSG(static_cast<int>(src_coord));
5151
target.importFromEPSG(static_cast<int>(tgt_coord));
@@ -61,7 +61,7 @@ Eigen::Vector3d transformCoordinates(ESPG src_coord, ESPG tgt_coord, const Eigen
6161
return target_coordinates;
6262
}
6363

64-
Eigen::Vector3d transformCoordinates(ESPG src_coord, const std::string wkt, const Eigen::Vector3d source_coordinates) {
64+
Eigen::Vector3d transformCoordinates(EPSG src_coord, const std::string wkt, const Eigen::Vector3d source_coordinates) {
6565
OGRSpatialReference source, target;
6666
char* wkt_string = const_cast<char*>(wkt.c_str());
6767
source.importFromEPSG(static_cast<int>(src_coord));

grid_map_geo/test/unit/test_grid_map_geo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
TEST(GridMapTest, geoTransform) {
88
Eigen::Vector3d berghaus_wgs84(46.7209147, 9.9219592, 488.0);
99
Eigen::Vector3d berghaus_lv03(789823.96735451114, 177416.47911055354, 440.3752994351089);
10-
Eigen::Vector3d tranformed_lv03 = transformCoordinates(ESPG::WGS84, ESPG::CH1903_LV03, berghaus_wgs84);
10+
Eigen::Vector3d tranformed_lv03 = transformCoordinates(EPSG::WGS84, EPSG::CH1903_LV03, berghaus_wgs84);
1111
EXPECT_NEAR(tranformed_lv03(0), berghaus_lv03(0), 0.0001);
1212
EXPECT_NEAR(tranformed_lv03(1), berghaus_lv03(1), 0.0001);
1313
// EXPECT_NEAR(tranformed_lv03(2), berghaus_lv03(2), 0.0001);
14-
Eigen::Vector3d tranformed_wgs84 = transformCoordinates(ESPG::CH1903_LV03, ESPG::WGS84, berghaus_lv03);
14+
Eigen::Vector3d tranformed_wgs84 = transformCoordinates(EPSG::CH1903_LV03, EPSG::WGS84, berghaus_lv03);
1515
EXPECT_NEAR(tranformed_wgs84(0), berghaus_wgs84(0), 0.0001);
1616
EXPECT_NEAR(tranformed_wgs84(1), berghaus_wgs84(1), 0.0001);
1717
// EXPECT_NEAR(tranformed_wgs84(2), berghaus_wgs84(2), 0.0001);
@@ -25,7 +25,7 @@ TEST(GridMapTest, geoTransform) {
2525
"PARAMETER[\"rectified_grid_angle\", 90], PARAMETER[\"scale_factor\", 1], PARAMETER[\"false_easting\", 600000], "
2626
"PARAMETER[\"false_northing\", 200000], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"Y\", EAST], "
2727
"AXIS[\"X\", NORTH], AUTHORITY[\"EPSG\", \"21781\"]]";
28-
Eigen::Vector3d tranformed_lv032 = transformCoordinates(ESPG::WGS84, wkt, berghaus_wgs84);
28+
Eigen::Vector3d tranformed_lv032 = transformCoordinates(EPSG::WGS84, wkt, berghaus_wgs84);
2929
EXPECT_NEAR(tranformed_lv032(0), berghaus_lv03(0), 0.0001);
3030
EXPECT_NEAR(tranformed_lv032(1), berghaus_lv03(1), 0.0001);
3131
// EXPECT_NEAR(tranformed_lv032(2), berghaus_lv03(2), 0.0001);

grid_map_geo_msgs/msg/GeographicMapInfo.msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
std_msgs/Header header
55

66

7-
# ESPG of the coordinate the map is in
7+
# EPSG of the coordinate the map is in
88
uint16 geo_coordinate
99

1010
# Size of the map in pixels

0 commit comments

Comments
 (0)