-
Notifications
You must be signed in to change notification settings - Fork 19
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
base: master
Are you sure you want to change the base?
Conversation
@@ -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"); |
There was a problem hiding this comment.
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
@@ -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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works with the datasets we use, but could be improved to not crash on other datasets that don't have the expected attributes.
Happy to merge as-is and have those nullptr checks and robustness stuff added later.
Problem Description
The ESPG code was hardcoded before. This PR acquires the code from the tif file directly