how to create a georefernce matrix from 2d lat and lon matrix
16 views (last 30 days)
Show older comments
rajasweta datta
on 25 Mar 2017
How can I create a GeoTIFF file from a 2d matrix of latitude and a 2D matrix of longitude and a 2d matrix of data like temperature? I need to combine the lat long and data to create a GeoTIFF file. The purpose is to create a temp file with each pixel representing lat-long and temperature.
Accepted Answer
Andreas Westergaard
on 14 Apr 2021
I have tried to find a solution to this, but have yet to find a way in Matlab. The example from KSSV seems to work nicely if you have 1D arrays with lat lon coordinates which can be converted to an evenly spaced grid. However, for the problem OP refer to with a 2D lat lon which may not be evenly spaced or aligned within meridians it may not work/give a wrong georeference.
If you have a matrix "lat" and matrix "lon" and matrix "data" in a WGS84 coordinate system, then the function
geoshow(lat,lon,data,'DisplayType', 'surface');
seems to work to plot the data as a map. The problem from there is to export the map as e.g. a geotiff.
So any ideas on either exporting the map from the geoshow-figure or creating a reference matrix "R" from a 2D lat, 2D lon, 2D data input would be fantastic!?
5 Comments
Natalia
on 29 Feb 2024
Edited: Natalia
on 29 Feb 2024
Hello, rajasweta datta
i was wondering if can i ask you for help to solve this? I am facing the same problem but in my case i have sometimes matrices with 2D dimensions, let's say ccaug=111x74 where 111 is longitude and 74 latitude, also my lat=111x74 and lon=111x74 and i have another matrix ccyraug=111x74x30, where 30 is my time (30 years), so in this case i have values within my domain 111x74. Should i use the same approach ? convert my matrices to .cvs and how can i convert each of the 30 years? and then how can i use the function you provided in R to apply it to my 30 years matrix? I've never used R before so it may be a bit tricky for me to use it for the first time.
Thanks in advance
More Answers (1)
KSSV
on 28 Mar 2017
Let x, y be your vectors of longitude,latitude respectively. And data be your temperature matrix.
xmin = min(x) ; xmax = max(x) ;
ymin = min(y) ; ymax = max(y) ;
R = georasterref('RasterSize',size(data),'LatitudeLimits',[ymin,ymax],'LongitudeLimits',[xmin,xmax]);
geotiffwrite('myfile.tif',data,R) % write data to .tif file
%%Read geotiff file
[A, R] = geotiffread(tiffile);
figure
mapshow(A, R);
axis image off
2 Comments
Hamidreza Norouzi
on 10 Jan 2019
But she asked when x and y are two 2-D matrices, not vectors. I have the same question.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!