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

Get espg from tif data #61

wants to merge 1 commit into from

Conversation

Jaeyoung-Lim
Copy link
Member

Problem Description
The ESPG code was hardcoded before. This PR acquires the code from the tif file directly

@Jaeyoung-Lim Jaeyoung-Lim requested a review from Ryanf55 March 30, 2024 15:56
@@ -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

@@ -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

Copy link
Collaborator

@Ryanf55 Ryanf55 left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants