diff --git a/Code/IO/otbImageFileReader.txx b/Code/IO/otbImageFileReader.txx index 55c30e5197ff6d2b70907972376582f04483a713..753c15e482859f923eb926336a62ae8a488a4e12 100644 --- a/Code/IO/otbImageFileReader.txx +++ b/Code/IO/otbImageFileReader.txx @@ -478,12 +478,21 @@ ImageFileReader<TOutputImage, ConvertPixelTraits> std::string projRef; itk::ExposeMetaData(dict, MetaDataKey::ProjectionRefKey, projRef); + // Compute spacing for an identity geotransform at current resolution + unsigned int resolution; + itk::ExposeMetaData<unsigned int>(dict, + MetaDataKey::ResolutionFactor, + resolution); + double idSpacing = 1.0; + if (resolution != 0) + idSpacing = 1.0 * vcl_pow((double)2.0, (double)resolution); + const double Epsilon = 1.0E-12; if ( projRef.empty() - && vcl_abs(origin[0] - 0.5) > Epsilon - && vcl_abs(origin[1] - 0.5) > Epsilon - && vcl_abs(spacing[0] - 1) > Epsilon - && vcl_abs(spacing[1] - 1) > Epsilon) + && vcl_abs(origin[0] - 0.5 * spacing[0]) > Epsilon + && vcl_abs(origin[1] - 0.5 * spacing[1]) > Epsilon + && vcl_abs(spacing[0] - idSpacing) > Epsilon + && vcl_abs(spacing[1] - idSpacing) > Epsilon) { std::string wgs84ProjRef = "GEOGCS[\"GCS_WGS_1984\", DATUM[\"D_WGS_1984\", SPHEROID[\"WGS_1984\", 6378137, 298.257223563]],"