Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get espg from tif data #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/grid_map_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ bool GridMapGeo::initializeFromGeotiff(const std::string &path) {

const OGRSpatialReference *spatial_ref = dataset->GetSpatialRef();
std::string name_coordinate = spatial_ref->GetAttrValue("geogcs");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note - GetSpacialRef can return null, so the code would segfault from a nullptr dereference if the user supplied the path to a dataset that didn't have one.
https://gdal.org/doxygen/classGDALDataset.html#a9bd7f8b54ff4c12756976c7a0116d49a

std::string epsg_code = spatial_ref->GetAttrValue("AUTHORITY", 1);
// Get image metadata
unsigned width = dataset->GetRasterXSize();
unsigned height = dataset->GetRasterYSize();
Expand All @@ -99,7 +100,7 @@ bool GridMapGeo::initializeFromGeotiff(const std::string &path) {

double mapcenter_e = originX + pixelSizeX * width * 0.5;
double mapcenter_n = originY + pixelSizeY * height * 0.5;
maporigin_.espg = ESPG::CH1903_LV03;
maporigin_.espg = static_cast<ESPG>(std::stoi(epsg_code));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, std::stoi could throw if the OGRSpatialReference doesn't have the AUTHORITY attribute because it will return null. You might want to wrap it in try-catch, or return early if the epsg_code == nullptr

maporigin_.position = Eigen::Vector3d(mapcenter_e, mapcenter_n, 0.0);

Eigen::Vector2d position{Eigen::Vector2d::Zero()};
Expand Down
Loading