how to create a georefernce matrix from 2d lat and lon matrix
조회 수: 18 (최근 30일)
이전 댓글 표시
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.
채택된 답변
Andreas Westergaard
2021년 4월 14일
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
Natalia
2024년 2월 29일
편집: Natalia
2024년 2월 29일
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
추가 답변 (1개)
KSSV
2017년 3월 28일
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
Hamidreza Norouzi
2019년 1월 10일
But she asked when x and y are two 2-D matrices, not vectors. I have the same question.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!