@@ -141,7 +141,8 @@ bool GridMapGeo::initializeFromGeotiff(const std::string &path) {
141
141
return true ;
142
142
}
143
143
144
- bool GridMapGeo::initializeFromVrt (const std::string &path, const Eigen::Vector2d &map_center, Eigen::Vector2d &extent) {
144
+ bool GridMapGeo::initializeFromVrt (const std::string &path, const Eigen::Vector2d &map_center,
145
+ Eigen::Vector2d &extent) {
145
146
GDALAllRegister ();
146
147
GDALDataset *dataset = (GDALDataset *)GDALOpen (path.c_str (), GA_ReadOnly);
147
148
if (!dataset) {
@@ -175,18 +176,16 @@ bool GridMapGeo::initializeFromVrt(const std::string &path, const Eigen::Vector2
175
176
std::cout << " Width: " << width << " Height: " << height << " Resolution: " << resolution << std::endl;
176
177
177
178
// pixelSizeY is negative because the origin of the image is the north-east corner and positive
178
- // Y pixel coordinates go towards the south
179
- int grid_width = extent (0 )/ std::abs (resolution);
180
- int grid_height = extent (1 )/ std::abs (resolution);
179
+ // Y pixel coordinates go towards the south
180
+ int grid_width = extent (0 ) / std::abs (resolution);
181
+ int grid_height = extent (1 ) / std::abs (resolution);
181
182
const double lengthX = resolution * grid_width;
182
183
const double lengthY = resolution * grid_height;
183
184
grid_map::Length length (lengthX, lengthY);
184
185
std::cout << " length: " << length.transpose () << std::endl;
185
186
186
- double mapcenter_e = map_center (0 );
187
- double mapcenter_n = map_center (1 );
188
187
maporigin_.espg = static_cast <ESPG>(std::stoi (epsg_code));
189
- maporigin_.position = Eigen::Vector3d (mapcenter_e, mapcenter_n, 0.0 );
188
+ maporigin_.position = map_center. head ( 2 );
190
189
191
190
Eigen::Vector2d position{Eigen::Vector2d::Zero ()};
192
191
@@ -197,13 +196,13 @@ bool GridMapGeo::initializeFromVrt(const std::string &path, const Eigen::Vector2
197
196
grid_map_.add (" elevation" );
198
197
GDALRasterBand *elevationBand = dataset->GetRasterBand (1 );
199
198
200
- Eigen::Vector2d center_px ((mapcenter_e - geoTransform[0 ])/geoTransform[1 ], (mapcenter_n - geoTransform[3 ])/geoTransform[5 ]);
199
+ Eigen::Vector2d center_px ((map_center (1 ) - geoTransform[0 ]) / geoTransform[1 ],
200
+ (map_center (0 ) - geoTransform[3 ]) / geoTransform[5 ]);
201
201
202
202
const auto raster_io_x_offset = center_px.x () - grid_width / 2 ;
203
203
const auto raster_io_y_offset = center_px.y () - grid_height / 2 ;
204
204
std::cout << " center_px: " << center_px.transpose () << std::endl;
205
205
206
-
207
206
std::vector<float > data (grid_width * grid_height, 0 .0f );
208
207
const auto raster_err = elevationBand->RasterIO (GF_Read, raster_io_x_offset, raster_io_y_offset, grid_width,
209
208
grid_height, &data[0 ], grid_width, grid_height, GDT_Float32, 0 , 0 );
@@ -227,8 +226,8 @@ bool GridMapGeo::initializeFromVrt(const std::string &path, const Eigen::Vector2
227
226
static_transformStamped.header .stamp = ros::Time::now ();
228
227
static_transformStamped.header .frame_id = name_coordinate;
229
228
static_transformStamped.child_frame_id = frame_id_;
230
- static_transformStamped.transform .translation .x = mapcenter_e ;
231
- static_transformStamped.transform .translation .y = mapcenter_n ;
229
+ static_transformStamped.transform .translation .x = map_center ( 0 ) ;
230
+ static_transformStamped.transform .translation .y = map_center ( 1 ) ;
232
231
static_transformStamped.transform .translation .z = 0.0 ;
233
232
static_transformStamped.transform .rotation .x = 0.0 ;
234
233
static_transformStamped.transform .rotation .y = 0.0 ;
0 commit comments