Convert large xyz file into grid

조회 수: 86 (최근 30일)
Yoni Verhaegen -WE-1718-
Yoni Verhaegen -WE-1718- 2019년 10월 21일
댓글: Sara 2020년 12월 7일
I have a large XYZ file (300276x3, this file includes x and y coordinates (not lat/lon, but polar stereographic) and elevation z) and I'm wondering if it would be possible to convert this into a gridded dataset (n x m matrix). The xyz file can be downloaded from:
and imported in matlab by:
AIS_SEC = importdata('');
I tried:
X= XYZ(:,1);
Y= XYZ(:,2);
Z= XYZ(:,3);
xr = sort(unique(X));
yr = sort(unique(Y));
gRho = zeros(length(yr),length(xr));
gRho = griddata(X,Y,Z,xr,yr')
Requested 300276x300276 (671.8GB) array exceeds maximum array size preference. Creation of arrays
greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size
limit or preference panel for more information.
I tried:
% Get coordinate vectors
x = unique(XYZ(:,1)) ;
y = unique(XYZ(:,2)) ;
% dimensions of the data
nx = length(x) ;
ny = length(y) ;
% Frame matrix of grid
D = reshape(XYZ(:,3),[ny,nx]) ;
% flip matrix to adjust for plot
H = flipud(H) ;
% Transpose the matrix
H = H' ; % Check if is required
surf(x,y,H) ;
Error using reshape
To RESHAPE the number of elements must not change.
I can now plot the nx3 file with scatter3 (see image)
scatter3(XYZ(:,1),XYZ(:,2),XYZ(:,3),2,XYZ(:,3)) ;
But I'd like to do it with imagesc. Hence, I would like to convert the nx3 file into a nxm matrix (in raster/gridded format) and as en extra I would like it as a geotiff file for use in QGIS.
  댓글 수: 3
Chad Greene
Chad Greene 2020년 9월 26일
Have you seen my xyz2grid function? I think it'll do what you want.
Sara 2020년 12월 7일
Hi, where is the function? i did not see it in the MATLAB helo. I also I did net know where I can the download

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

답변 (2개)

Chad Greene
Chad Greene 2020년 9월 26일
Try my xyz2grid function. It's fast, easy to use, and one of the examples in that documentation link shows how to grid up an Antarctic dataset just like yours.

Bibhu Das
Bibhu Das 2019년 10월 21일
If its a 2D data try to figure out min. and max. of X and Y. Then reshape the z column so that size z is equal to 300276. Finally you can contour it.


Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by