1

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 (834x1115). 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?

2
  • Generally one defines the coordinate reference as a discrete step.
    – Vince
    Commented Apr 24, 2020 at 13:19
  • You may generate a tfw or aux.xml file to define the position of your raster (it is used usually in a projected CRS, not in geographic coordinates).
    – Zoltan
    Commented Apr 24, 2020 at 20:53

2 Answers 2

1

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.

1

I'm uncertain if I understand what is going on entirely but maybe this helps. You can set a projection if you know it to be the correct one through Python:

import gdal
import osr

fn = '/path/to/my/infile.tif'

#define a projection
spatref = osr.SpatialReference()
spatref.ImportFromEPSG(4326)
crs_wkt = spatref.ExportToWkt()

# open in edit mode, omit the 1 if you want read only mode
ds = gdal.Open(fn, 1) 
# set the projection
ds.SetProjection(crs_wkt)
#close the dataset
ds.FlushCache()
ds = None

I hope this helps.

1
  • Thank you! Will have a go on this!
    – Idalh
    Commented Jun 5, 2020 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.