MATLAB: How to write a GeoTiff file with corresponding coordinates

geotiffgeotiffwriteMapping ToolboxMATLAB

I have the following:
  • a latitude array 'lat' (1×1128 single)
  • a longitude array 'lon' (1×968)
  • a value matrix 'value' (1128×968 double)
How can I write this into a GeoTiff file so that values have the corresponding coordinates of lat and lon, i.e. a lat,lon,value grid?
Thanks

Best Answer

First use the following lines to create the referencing matrix (R):
% load the value matrix and lat and lon arrays
value = Value_matrix;
lat = lat_array;
lon = lon_array;
% Create the referencing matrix (R)
R = georasterref('RasterSize',size(value), ...
'LatitudeLimits',[min(lat) max(lat)],'LongitudeLimits',[min(lon) max(lon)]);
then choose a name for your file and Write your GeoTIFF file:
filename = datafile('value.tif');
geotiffwrite(filename,value,R)