Skip to content

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
std::cout << std::endl << "Wkt ProjectionRef: " << pszProjection << std::endl;

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

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