Skip to content

Commit

Permalink
GeoHEIF: Fixed respecting CRS axis order (e.g., for EPSG:4326)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Desruisseaux <[email protected]>
  • Loading branch information
jerstlouis and desruisseaux committed Nov 28, 2024
1 parent 4aee058 commit e44de7f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
12 changes: 12 additions & 0 deletions frmts/heif/heifdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,14 @@ CPLErr GDALHEIFDataset::GetGeoTransform(double *padfTransform)
heif_item_get_property_raw_data(m_hCtxt, item_id, prop_ids[i],
data->data());
geoHEIF.setModelTransformation(data->data(), data->size());

// NOTE: Calling this here will ensure that CRS has been set up,
// since QGIS will invoke GDALGetGeoTransform() before
// GetSpatialRef() is ever called.
// This reading of CRS should probably be done outside
// of GetSpatialRef()
GetSpatialRef();

geoHEIF.GetGeoTransform(padfTransform);
return CE_None;
}
Expand All @@ -857,6 +865,10 @@ CPLErr GDALHEIFDataset::GetGeoTransform(double *padfTransform)
/************************************************************************/
const OGRSpatialReference *GDALHEIFDataset::GetSpatialRef() const
{
// REVIEW: This function being declared this-const should mean
// that it cannot possibly modify this object.
// Calling geoHEIF.GetSpatialRef() the first time
// breaks this assumption.
if (geoHEIF.has_SRS())
return geoHEIF.GetSpatialRef();

Expand Down
27 changes: 21 additions & 6 deletions gcore/geoheif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,26 @@ void GeoHEIF::setModelTransformation(const uint8_t *payload, size_t length)

CPLErr GeoHEIF::GetGeoTransform(double *padfTransform) const
{
padfTransform[1] = modelTransform[1];
padfTransform[2] = modelTransform[2];
padfTransform[0] = modelTransform[0];
padfTransform[4] = modelTransform[4];
padfTransform[5] = modelTransform[5];
padfTransform[3] = modelTransform[3];
int nAxes = 0;
const int *axes = has_SRS() ? OSRGetDataAxisToSRSAxisMapping(OGRSpatialReference::ToHandle(&m_oSRS), &nAxes) : nullptr;
if(axes && axes[0] != 1)
{
padfTransform[1] = modelTransform[4];
padfTransform[2] = modelTransform[5];
padfTransform[0] = modelTransform[3];
padfTransform[4] = modelTransform[1];
padfTransform[5] = modelTransform[2];
padfTransform[3] = modelTransform[3];
}
else
{
padfTransform[1] = modelTransform[1];
padfTransform[2] = modelTransform[2];
padfTransform[0] = modelTransform[0];
padfTransform[4] = modelTransform[4];
padfTransform[5] = modelTransform[5];
padfTransform[3] = modelTransform[3];
}
return CE_None;
}

Expand Down Expand Up @@ -150,6 +164,7 @@ void GeoHEIF::extractSRS(const uint8_t *payload, size_t length) const
CPLDebug("GeoHEIF", "CRS encoding is not supported");
return;
}
m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
}

void GeoHEIF::addGCPs(const uint8_t *data, size_t length)
Expand Down

0 comments on commit e44de7f

Please sign in to comment.