@@ -62,23 +62,23 @@ GridMapGeo::GridMapGeo(const std::string &frame_id) { frame_id_ = frame_id; }
62
62
63
63
GridMapGeo::~GridMapGeo () {}
64
64
65
- bool GridMapGeo::Load (const std::string &map_path, const std::string & color_map_path) {
66
- bool loaded = initializeFromGeotiff (map_path);
65
+ bool GridMapGeo::Load (const std::string &map_path, const std::string color_map_path) {
66
+ bool loaded = initializeFromGdalDataset (map_path);
67
67
if (!color_map_path.empty ()) { // Load color layer if the color path is nonempty
68
68
bool color_loaded = addColorFromGeotiff (color_map_path);
69
69
}
70
70
if (!loaded) return false ;
71
71
return true ;
72
72
}
73
73
74
- bool GridMapGeo::initializeFromGeotiff (const std::string &path) {
74
+ bool GridMapGeo::initializeFromGdalDataset (const std::string &path) {
75
75
GDALAllRegister ();
76
76
const auto dataset = GDALDatasetUniquePtr (GDALDataset::FromHandle (GDALOpen (path.c_str (), GA_ReadOnly)));
77
77
if (!dataset) {
78
78
std::cout << " Failed to open" << std::endl;
79
79
return false ;
80
80
}
81
- std::cout << std::endl << " Loading GeoTIFF file for gridmap" << std::endl;
81
+ std::cout << std::endl << " Loading GDAL Dataset for gridmap" << std::endl;
82
82
83
83
double originX, originY, pixelSizeX, pixelSizeY;
84
84
std::array<double , 6 > geoTransform;
@@ -104,17 +104,19 @@ bool GridMapGeo::initializeFromGeotiff(const std::string &path) {
104
104
105
105
const OGRSpatialReference *spatial_ref = dataset->GetSpatialRef ();
106
106
coordinate_name_ = spatial_ref->GetAttrValue (" geogcs" );
107
+
107
108
// Get image metadata
108
109
unsigned width = dataset->GetRasterXSize ();
109
110
unsigned height = dataset->GetRasterYSize ();
110
111
double resolution = pixelSizeX;
111
- std::cout << " Width : " << width << " Height : " << height << " Resolution : " << resolution << std::endl;
112
+ std::cout << __LINE__ << " RasterX : " << width << " RasterY : " << height << " pixelSizeX : " << pixelSizeX << std::endl;
112
113
113
114
// pixelSizeY is negative because the origin of the image is the north-east corner and positive
114
115
// Y pixel coordinates go towards the south
115
116
const double lengthX = resolution * width;
116
117
const double lengthY = resolution * height;
117
118
grid_map::Length length (lengthX, lengthY);
119
+ std::cout << __LINE__ << " GMLX: " << lengthX << " GMLY: " << lengthY << std::endl;
118
120
119
121
double mapcenter_e = originX + pixelSizeX * width * 0.5 ;
120
122
double mapcenter_n = originY + pixelSizeY * height * 0.5 ;
@@ -128,18 +130,18 @@ bool GridMapGeo::initializeFromGeotiff(const std::string &path) {
128
130
grid_map_.add (" elevation" );
129
131
GDALRasterBand *elevationBand = dataset->GetRasterBand (1 );
130
132
131
- std::vector<float > data (width * height, 0 .0f );
132
- elevationBand->RasterIO (GF_Read, 0 , 0 , width, height, &data[0 ], width, height, GDT_Float32, 0 , 0 );
133
+ // std::vector<float> data(width * height, 0.0f);
134
+ // elevationBand->RasterIO(GF_Read, 0, 0, width, height, &data[0], width, height, GDT_Float32, 0, 0);
133
135
134
- grid_map::Matrix &layer_elevation = grid_map_[" elevation" ];
135
- for (grid_map::GridMapIterator iterator (grid_map_); !iterator.isPastEnd (); ++iterator) {
136
- const grid_map::Index gridMapIndex = *iterator;
137
- // TODO: This may be wrong if the pixelSizeY > 0
138
- int x = width - 1 - gridMapIndex (0 );
139
- int y = gridMapIndex (1 );
136
+ // grid_map::Matrix &layer_elevation = grid_map_["elevation"];
137
+ // for (grid_map::GridMapIterator iterator(grid_map_); !iterator.isPastEnd(); ++iterator) {
138
+ // const grid_map::Index gridMapIndex = *iterator;
139
+ // // TODO: This may be wrong if the pixelSizeY > 0
140
+ // int x = width - 1 - gridMapIndex(0);
141
+ // int y = gridMapIndex(1);
140
142
141
- layer_elevation (x, y) = data[gridMapIndex (0 ) + width * gridMapIndex (1 )];
142
- }
143
+ // layer_elevation(x, y) = data[gridMapIndex(0) + width * gridMapIndex(1)];
144
+ // }
143
145
144
146
return true ;
145
147
}
@@ -169,7 +171,7 @@ bool GridMapGeo::addColorFromGeotiff(const std::string &path) {
169
171
unsigned width = dataset->GetRasterXSize ();
170
172
unsigned height = dataset->GetRasterYSize ();
171
173
double resolution = pixelSizeX;
172
- std::cout << " Width: " << width << " Height: " << height << " Resolution: " << resolution << std::endl;
174
+ std::cout << __LINE__ << " Width: " << width << " Height: " << height << " Resolution: " << resolution << std::endl;
173
175
174
176
// pixelSizeY is negative because the origin of the image is the north-east corner and positive
175
177
// Y pixel coordinates go towards the south
@@ -230,7 +232,7 @@ bool GridMapGeo::addLayerFromGeotiff(const std::string &layer_name, const std::s
230
232
unsigned width = dataset->GetRasterXSize ();
231
233
unsigned height = dataset->GetRasterYSize ();
232
234
double resolution = pixelSizeX;
233
- std::cout << " Width: " << width << " Height: " << height << " Resolution: " << resolution << std::endl;
235
+ std::cout << __LINE__ << " Width: " << width << " Height: " << height << " Resolution: " << resolution << std::endl;
234
236
235
237
// pixelSizeY is negative because the origin of the image is the north-east corner and positive
236
238
// Y pixel coordinates go towards the south
0 commit comments