Creating a GeoTIFF with 3 large matrices (Latitude, Longitude, Data) [satellite images]

5 views (last 30 days)
Dear all,
I am trying to create a GeoTIFF from 3 matrices, each of 2000x2048. Let's call them:
Lat = 2000x2048
Lon = 2000x2048
Data = 2000x2048
Now, being the coordinates not equally spaced accross the scene, I cannot use the approach where xmin xmax ymin ymax define the 4 corners.
I can do that, but when I export the file to a GeoTIFF, this is wrongly georeferenced, resulting in something "flat" like this (assuming x and y axis had coordinates):
What I am after is exactly what geoshow does. For example I can obtain the image below from:
geoshow(Lat,Lon,Data,'DisplayType', 'surface')
colormap jet, clim([250 320]), colorbar;
And this is what I get:
Now, how can I create something like this, that can be exported as a GeoTIFF?
*Please note, I tried to create meshgrids but unsurprisingsly I get the following error:
Requested 4096000x4096000 (125000.0GB) array exceeds maximum array size preference (13.9GB). This might cause MATLAB to become
unresponsive.
Any help would be much appreciated!

Answers (1)

Ashutosh Thakur
Ashutosh Thakur on 19 Dec 2023
Hi Simone,
I can understand that you want to export a GeoTIFF file, You can follow the below suggestions in achieving this objective:
  • Create a Spatial Referencing Object using "georasterref" or "georefcells" based on latitude and longitude matrices.
  • Also determine the geographic extent of your data based on the minimum and maximum latitude and longitude values.
  • Now write the data to a GeoTIFF file using "geotiffwrite" function.
You can take reference from the below mentioned pseudocode:
% Example dataincluding latitude and longitude
Lat = ...;
Lon = ...;
Data = ...;
% georastreff
R = georasterref('RasterSize', size(Data), ...
'LatitudeLimits', [min(Lat(:)), max(Lat(:))], ...
'LongitudeLimits', [min(Lon(:)), max(Lon(:))]);
% Define geographic extent
extent = [min(Lon(:)), max(Lon(:)), min(Lat(:)), max(Lat(:))];
% Write data to GeoTIFF
geotiffwrite('output_file.tif', Data, R, 'GeoKeyDirectoryTag', extent);
Also kindly refer to the following documentation links regarding "georasterref" or "geotiffwrite" operations:
I hope this helps.
Thanks.

Categories

Find more on Reference Applications in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!