How to use QGIS geotiff in matlab?

9 views (last 30 days)
Anna Hayden
Anna Hayden on 10 Jul 2017
Answered: Chad Greene on 20 Jul 2017
Hi All,
For starters, I am using R2017a on a Mac.
I am using ship sounding bathymetry (water depth) data in QGIS to produce maps in GeoTiff format. QGIS produces a .tiff and .tfw (world file). What I am trying to do is use these maps from QGIS in Matlab, and calculate the difference between the ship sounding data and other bathymetry data (i.e GEBCO, ETOPO)
I have tried using geotiffread to read in the geotiff file but receive the error:
Error using geotiffinfo>readinfo (line 259) The file 'Bathymetry_test.tiff' does not contain any GeoTIFF Tags. Use the function IMFINFO to obtain information about the file.
My .tiff file does not seem to have associated coordinates, however, I am able to import the worldfile using the worldfileread function.
My question is: How can I assign coordinates from the .tfw worldfile to my .tiff file?

Answers (1)

Chad Greene
Chad Greene on 20 Jul 2017
Hi Anna,
This situation comes up a lot. If the tiff data are regular in lat/lon, you'll need to know the extents (in lat and lon) of the data and the resolution (in degrees) of the data. If the data are in regular distance (meters or kilometers), you'll need to know the extents of the x,y coordinates and the spatial resolution of the grid. Then make a grid with meshgrid. So if your data are regular in geo coordinates, maybe it's
[lon,lat] = meshgrid(-180:0.25:180,90:-0.25,-90);
for a 1/4 degree global grid. There's a good chance the pixel centers would actually be offset by 1/8 degree, but you get the idea. Then should be able to use imread to read the geotiff, whether it does or does not have geo coded information. Something like
Z = imread('myfile.tif');
And then use interp2 to interpolate.
zi = interp2(lon,lat,Z,loni,lati);
You might have to tinker with flipping the image via fliplr or flipud, and you might have to do a rotation with rot90. Just check to make sure everything is in the right place with
pcolor(lon,lat,Z)
or
pcolor(x,y,z)
Before interpolating.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!