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

10 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Andreas Westergaard
Andreas Westergaard el 14 de Abr. de 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 comentarios
rajasweta datta
rajasweta datta el 7 de Feb. de 2023
Editada: rajasweta datta el 7 de Feb. de 2023
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 el 29 de Feb. de 2024
Editada: Natalia el 29 de Feb. de 2024
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

Iniciar sesión para comentar.

Más respuestas (1)

KSSV
KSSV el 28 de Mzo. de 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 comentarios
Hamidreza Norouzi
Hamidreza Norouzi el 10 de En. de 2019
But she asked when x and y are two 2-D matrices, not vectors. I have the same question.
rajasweta datta
rajasweta datta el 18 de En. de 2019
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

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by