'osr.TransformPoint flips x and y if file in ENVI RAW is provided
I want to transform the corner coordinates of a UTM projected file into longlat. If I read coordinates from a GeoTIFF, the function works as expected. But, after converting the GeoTiff to ENVI raw file (with gdal_translate), the coordinates are flipped:
from osgeo import gdal
from osgeo import osr
def corner2longlat(fname):
dataset = gdal.Open(fname, gdal.GA_ReadOnly)
ds_geotrans = dataset.GetGeoTransform()
X = ds_geotrans[0]
Y = ds_geotrans[3] + dataset.RasterYSize * ds_geotrans[5]
srs_projection = dataset.GetProjectionRef()
srs = osr.SpatialReference()
srs.ImportFromWkt(srs_projection)
srsLatLong = srs.CloneGeogCS()
ct = osr.CoordinateTransformation(srs, srsLatLong)
latlon = ct.TransformPoint(X, Y)
print(srs_projection)
print([latlon[0], latlon[1]])
image_tif = "all_bands.tif"
image_raw = "all_bands.raw"
corner2longlat(image_tif) gives then:
PROJCS["WGS 84 / UTM zone 43N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",75],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","32643"]]
[41.463751886708124, 74.99976050569691]
corner2longlat(image_raw) gives then:
PROJCS["WGS 84 / UTM zone 43N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",75],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]]
[74.99976050569691, 41.463751886708124]
Does anybody have an idea how that could happen?
Thank you in advance
Lukas
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
