[GIS] Define projection of TIFF file when exporting from Python

coordinate systemgdalpythonqgis

I am struggling with getting spatial data into a readable TIFF file with the right projection. As far as I can understand, my problem is that the longitude and latitude is not saved as the projection when I save it to TIFF file in Python, but it uses the dimensions of array as the projection coordinates/size (834×1115). I have also tried saving it as a NetCDF file but this does also not work. I tried thorugh QGIS to export it to the right projection but this does also not work. I have longitude and latitude for every point but somehow this is not saved in the file, so QGIS reads it this way.
This is an example of what the data looks like using gdalinfo:

Driver: GTiff/GeoTIFF
Files: yearly_precipitation_2008.tif
       yearly_precipitation_2008.tif.aux.xml
Size is 1115, 834
Coordinate System is `'
Metadata:
  TIFFTAG_IMAGEDESCRIPTION={"shape": [1, 834, 1115]}
  TIFFTAG_RESOLUTIONUNIT=1 (unitless)
  TIFFTAG_SOFTWARE=tifffile.py
  TIFFTAG_XRESOLUTION=1
  TIFFTAG_YRESOLUTION=1
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  834.0)
Upper Right ( 1115.0,    0.0)
Lower Right ( 1115.0,  834.0)
Center      (  557.5,  417.0)
Band 1 Block=1115x1 Type=Float32, ColorInterp=Gray
  Min=0.415 Max=7.939 
  Minimum=0.415, Maximum=7.939, Mean=2.033, StdDev=1.026
  Metadata:
    STATISTICS_APPROXIMATE=YES
    STATISTICS_MAXIMUM=7.9388275146484
    STATISTICS_MEAN=2.0331832805082
    STATISTICS_MINIMUM=0.41479951143265
    STATISTICS_STDDEV=1.025994406909
    STATISTICS_VALID_PERCENT=43.73

Follow up:
I ave tried to reproject doing this using the command line:

gdalwarp -wm 2000 – srs ”+proj=longlat +ellps=WGS84 +datum=WGS84 
+no_defs” – t_srs "EPSG:4326" -tr 926.6254331 -926.6254331 -te 
1226864.395378 3990864.002497 -80399.894893 4896300.006573 -r cubic -ot 
Float32 -co COMPRESS=DEFLATE -co PREDICTOR=2 -co ZLEVEL=9 -overwrite 
NETCDF: /Users/.../TIFF_files/yearly_precipitation_2008.nc:pred /Users
/.../TIFF_files/yearly_precipitation_2008.tif

But then I get the error ERROR 4: –: No such file or directory eventhough the directory and files does excist. Does anyone know how to fix this?

Best Answer

So with a lot of help I came up with this to solve the problem using gdal:

gdalwarp -wm 2000 -s_srs "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" -t_srs "EPSG:4326" -tr 1100 -1100  -te -80950.000 3979450.000 1145550.000 4896850.000 -r cubic -ot Float32 -co COMPRESS=DEFLATE -co PREDICTOR=2 -co ZLEVEL=9 -overwrite NETCDF:yearly_precipitation_2008.nc:pred yearly_precipitation_2008.tif

This works for this file, but I am struggling with another one. Hope somebody can use this for something.

Related Question