필터 지우기
필터 지우기

how to create a georefernce matrix from 2d lat and lon matrix

조회 수: 18 (최근 30일)
rajasweta datta
rajasweta datta 2017년 3월 25일
편집: Natalia 2024년 2월 29일
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
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
rajasweta datta
rajasweta datta 2023년 2월 7일
편집: rajasweta datta 2023년 2월 7일
please try this link
the function coverts 2d matrix of lat, lon and data into a georeferenced dataset, helpful for model outputs.
all 3 values can be csv files, 2 for lat and long and other for data
code for example
lon <- raster(as.matrix(read.csv(paste0(basefolder,"lon.csv"),header=FALSE)))
lat <- raster(as.matrix(read.csv(paste0(basefolder,"lat.csv"),header=FALSE)))
x <- raster(as.matrix(read.csv(file,header=FALSE)))
result <- rasterizeRegCM(x,lat,lon)
writeRaster(result,paste0(substr(file,1,nchar(file)-4),".tif"))
Natalia
Natalia 2024년 2월 29일
편집: Natalia 2024년 2월 29일
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
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
Hamidreza Norouzi 2019년 1월 10일
But she asked when x and y are two 2-D matrices, not vectors. I have the same question.
rajasweta datta
rajasweta datta 2019년 1월 18일
Hi ,
I got the solution but I actually had take help of R for this, if you still have the problem I might be able to help.
regards
Raj

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by