Fix spatial reference equality tests
Summary
Closes #2055 (closed) Closes #2051 (closed)
In issues #2055 (closed) and #2051 (closed) there are examples of application failing with an error message stating that the spatial reference between the input image and the input vector data is not the same, even if the printed SRS look the same.
The error actually comes from how the SRS are compared. This MR solve this bug.
Rationale
This is an error caused by how the axis of the spatial reference are handled in GDAL. Depending on the spatial reference, the coordinates of the spatial reference might be [lon,lat] or [lat/long] (in the case of geographical spatial reference). In GDAL 2 the "traditional GIS" order was used i.e [lat,long], independently on how they are defined in spatial reference system. In GDAL 3 however, the order defined by the spatial reference system is followed, but it is possible to force the GIS order by applying the OGRSpatialReference method SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER)
. See this paragraph in GDAL's documentation.
Spatial reference are often compared with the OGRSpatialReference::IsSame(other)
method from GDAL. Starting with GDAL 3, if the axis order are different in the two OGRSpatialReference
objects the method will return false.
In particular, in two classes of OTB ,ImageSampleExtractorFilter
and PersistentImageToOGRLayerFilter
, the spatial reference of the input datasource is compared to the spatial reference of the input image. This is done by instantiating a spatial reference from the WKT string attached to the image and by comparating it with the IsSame
method to the OGRSpatialReference
object stored in the Datasource
object. The latter has been created by the ogr driver associated with the input vector data and in most case the traditional GIS order has been enforced by OGR. But as the spatial reference from the image WKT don't necessarily follow this order the test fail.
Therefore, the bug happens when the input spatial reference does not follow the GIS order, for example with WGS84
(see the bug reports).
The fix is to apply the same axis order to both spatial references.
Additional notes
Other classes use the IsSame
method, but there are not subject to this bug :
-
SampleSelection
andPolygonClassStatistics
: compare two spatial references created from wkt strings - TestHelper : compare two spatial references from Datasource.
Copyright
The copyright owner is CNES and has signed the ORFEO ToolBox Contributor License Agreement.
Check before merging:
- All discussions are resolved
- At least 2
👍 votes from core developers, no👎 vote. - The feature branch is (reasonably) up-to-date with the base branch
- Dashboard is green
- Copyright owner has signed the ORFEO ToolBox Contributor License Agreement
- Optionally, run
git diff develop... -U0 --no-color | clang-format-diff.py -p1 -i
on latest changes and commit