Index: gdal/gcore/gdaljp2metadata.cpp =================================================================== --- gdal/gcore/gdaljp2metadata.cpp (revision 24401) +++ gdal/gcore/gdaljp2metadata.cpp (working copy) @@ -795,13 +795,25 @@ adfGeoTransform[0] = adfGeoTransform[3]; adfGeoTransform[3] = dfTemp; + int swapWith1Index = 4; + int swapWith2Index = 5; + + if( CSLTestBoolean( CPLGetConfigOption( "GDAL_JP2K_ALT_OFFSETVECTOR_ORDER", + "FALSE" ) ) ) + { + swapWith1Index = 5; + swapWith2Index = 4; + CPLDebug( "GMLJP2", "Choosing alternate GML \"\" order based on " + "GDAL_JP2K_ALT_OFFSETVECTOR_ORDER." ); + } + dfTemp = adfGeoTransform[1]; - adfGeoTransform[1] = adfGeoTransform[4]; - adfGeoTransform[4] = dfTemp; + adfGeoTransform[1] = adfGeoTransform[swapWith1Index]; + adfGeoTransform[swapWith1Index] = dfTemp; dfTemp = adfGeoTransform[2]; - adfGeoTransform[2] = adfGeoTransform[5]; - adfGeoTransform[5] = dfTemp; + adfGeoTransform[2] = adfGeoTransform[swapWith2Index]; + adfGeoTransform[swapWith2Index] = dfTemp; } return pszProjection != NULL && bSuccess; @@ -1001,6 +1013,23 @@ adfOrigin[0] = adfOrigin[1]; adfOrigin[1] = dfTemp; + if( CSLTestBoolean( CPLGetConfigOption( "GDAL_JP2K_ALT_OFFSETVECTOR_ORDER", + "FALSE" ) ) ) + { + CPLDebug( "GMLJP2", "Choosing alternate GML \"\" order based on " + "GDAL_JP2K_ALT_OFFSETVECTOR_ORDER." ); + + /* In this case the swapping is done in an "X" pattern */ + dfTemp = adfXVector[0]; + adfXVector[0] = adfYVector[1]; + adfYVector[1] = dfTemp; + + dfTemp = adfYVector[0]; + adfYVector[0] = adfXVector[1]; + adfXVector[1] = dfTemp; + } + else + { dfTemp = adfXVector[0]; adfXVector[0] = adfXVector[1]; adfXVector[1] = dfTemp; @@ -1008,6 +1037,7 @@ dfTemp = adfYVector[0]; adfYVector[0] = adfYVector[1]; adfYVector[1] = dfTemp; + } } /* -------------------------------------------------------------------- */ Index: gdal/swig/perl/lib/Geo/GDAL.dox =================================================================== --- gdal/swig/perl/lib/Geo/GDAL.dox (revision 24401) +++ gdal/swig/perl/lib/Geo/GDAL.dox (working copy) @@ -110,7 +110,8 @@ # 'GDAL_PAM_ENABLED', 'GDAL_PAM_MODE', 'GDAL_PAM_PROXY_DIR', # 'GDAL_MAX_DATASET_POOL_SIZE', 'GDAL_FORCE_CACHING', 'GDAL_CACHEMAX', # 'GDAL_SWATH_SIZE', 'PROJSO', 'CENTER_LONG', -# 'OGR_DEBUG_ORGANIZE_POLYGONS', and 'OGR_ORGANIZE_POLYGONS'. +# 'OGR_DEBUG_ORGANIZE_POLYGONS', 'OGR_ORGANIZE_POLYGONS', +# and 'GDAL_JP2K_ALT_OFFSETVECTOR_ORDER'. # Consult the GDAL main documentation for the semantics of config options. # @param value A value for the option, typically 'YES', 'NO', # undef, a path, or a filename. Index: autotest/gdrivers/data/gmljp2_dtedsm_epsg_4326_axes_alt_offsetVector.jp2 =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: autotest\gdrivers\data\gmljp2_dtedsm_epsg_4326_axes_alt_offsetVector.jp2 ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: autotest/gdrivers/jp2kak.py =================================================================== --- autotest/gdrivers/jp2kak.py (revision 24401) +++ autotest/gdrivers/jp2kak.py (working copy) @@ -391,6 +391,43 @@ return 'success' ############################################################################### +# Test reading a file with axis orientation set properly for an alternate +# axis order coordinate system (urn:...:EPSG::4326). +# In addition, the source .jp2 file's embedded GML has the alternate order +# between the offsetVector tags, and the "GDAL_JP2K_ALT_OFFSETVECTOR_ORDER" +# option is turned on to match that situation. +# This test case was adapted from the "jp2kak_7()" case above. + +def jp2kak_17(): + + if gdaltest.jp2kak_drv is None: + return 'skip' + + gdal.SetConfigOption( 'GDAL_JP2K_ALT_OFFSETVECTOR_ORDER', 'YES' ) + + ds = gdal.Open( 'data/gmljp2_dtedsm_epsg_4326_axes_alt_offsetVector.jp2' ) + + gt = ds.GetGeoTransform() + gte = (42.999583333333369,0.008271349862259,0, + 34.000416666666631,0,-0.008271349862259) + + if abs(gt[0] - gte[0]) > 0.0000001 or abs(gt[3] - gte[3]) > 0.000001 \ + or abs(gt[1] - gte[1]) > 0.000000000005 \ + or abs(gt[2] - gte[2]) > 0.000000000005 \ + or abs(gt[4] - gte[4]) > 0.000000000005 \ + or abs(gt[5] - gte[5]) > 0.000000000005: + gdaltest.post_reason( 'did not get expected geotransform' ) + print('got: ', gt) + gdal.SetConfigOption( 'GDAL_JP2K_ALT_OFFSETVECTOR_ORDER', 'NO' ) + return 'fail' + + ds = None + + gdal.SetConfigOption( 'GDAL_JP2K_ALT_OFFSETVECTOR_ORDER', 'NO' ) + + return 'success' + +############################################################################### # Cleanup. def jp2kak_cleanup(): @@ -416,6 +453,7 @@ jp2kak_14, jp2kak_15, jp2kak_16, + jp2kak_17, jp2kak_cleanup ] if __name__ == '__main__':