3

I am generating a number of plots in Matlab. I want to overlay these over maps I have created in QGIS. I thought the best way would be to import the maps as a geotiff into Matlab and then overlay my plots over the image. I have saved the project as an image, generating a tiff and a tiffw file.

I got stuck trying to import and display the tiff and tiffw file in Matlab. I am working with QGIS 2.10.1 and Matlab R2012b.


Here is what i have tried so far:

Matlab has a geotiffread() function to read geotiff files. Using this function to read the .tiff produces the following error.

Error using geotiffinfo>readinfo (line 259) The file 'GeoTest.tiff' does not contain any GeoTIFF Tags. Use the function IMFINFO to obtain information about the file.

I was able to import the .tiffw file into matlab using the code.

filename = 'GeoTest.tiff';
RGB = imread(filename);
worldFileName = getworldfilename(filename);
R = worldfileread(worldFileName, 'planar', size(RGB))

But still have to figure out how to put that into a figure together with my plot.

  • Hi Martin, can you elaborate on what "got stuck" means? Did you try something? Is there an error message? – Matthias Kuhn Aug 29 '15 at 8:29
  • I'll edit my question to elaborate a bit more. It was a combination of error messages and not sure what to do. – Martijn Aug 29 '15 at 8:49
1

In QGIS, export the map as in image via 'save as image' in the file menu and choose 'tiff' as the file type. This will produce both a .tiff and a .tiffw file. The .tiffw file is known as a World File. As far as I can tell the .tiff file is not a GeoTiff file, or at least, Matlab does not recognise it as a GeoTiff file.

There seems to be an issue with the way QGIS generates its tiff files, to fix this do the following:

Open the file in an image processing program (I used ImageJ) and then save the file as a new tiff file.

In Matlab, use mapshow() to display the 'new' tiff file. Make sure the tiffw file is in the same directory.

mapshow('myMap.tiff')
ha = mapshow(X1,Y1,'DisplayType','point','Marker','s','MarkerEdgeColor','k')
hb = mapshow(X2,Y2,'DisplayType','point','Marker','o','MarkerEdgeColor','k')
legend([ha hb],'Stations', 'Assets');    
axis off

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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