I'm using rasterio to write data to a TIFF image. The original data was extracted from a TIFF image, that was projected in UTM 17 North, or EPSG 32617. I'm writing the data to EPSG 4326, and am also rotating the data by 60 degrees. The problem is that after writing the TIFF, the image extent has mixed coordinates, both UTM and lat/long. Below is the script that writes the TIFF image:
with rio.open(infile) as dataset:
data = np.array([dataset.read(i) for i in dataset.indexes])
a=50
b=0
c=-82.43117030230272
d=0
e=-50
f=28.01738650165293
aft=Affine(a,b,c,b,e,f)*Affine.rotation(60)
md = {'crs': CRS.from_epsg(4326),
'driver': 'GTiff',
'height': 1500,
'width': 6000,
'count': 1,
'dtype': dtype('float64'),
'nodata': -99999,
'transform': aft}
# output a geo-referenced tiff
outfile = 'al09_15_wlmax_EGOM-RTv20bchk_GAHM_swan_ofcl_mvb_uga_mMSL_50.-00835.000270.6000.1500.llr.tiff'
dst = rio.open(outfile, 'w', **md)
try:
dst.write(data)
logger.info(f"Wrote TIF file to {outfile}")
except:
logger.error(f"Failed to write TIF file to {outfile}")
dst.close()
Here are the contents of aft and md.
aft:
Affine(25.000000000000007, -43.30127018922193, -82.43117030230272,
-43.30127018922193, -25.000000000000007, 28.01738650165293)
md:
{'crs': CRS.from_epsg(4326), 'driver': 'GTiff', 'height': 1500, 'width': 6000, 'count': 1, 'dtype': dtype('float64'), 'nodata': -99999, 'transform': Affine(25.000000000000007, -43.30127018922193, -82.43117030230272,
-43.30127018922193, -25.000000000000007, 28.01738650165293)}
After producing the TIFF image, and loading it into QGIS the extent has mixed values as show in the below image:
Why would this be happening?
Yes a & e are in meters and for some reason I did not change them!
infile
already been reprojected from EPSG 32617 to EPSG 4326? If not, you either need to do so before reading or actually reproject it using rasterio. Just changing the CRS in the metadata won't reproject your data. Your affine has mixed values, looks like decimal degree coordinates for c & f but metres for a & e