我有一个较大的XYZ文件(300276x3,此文件包含x和y坐标(不是纬度/经度,而是极坐标)和仰角z),我想知道是否有可能将其转换为网格数据集(nxm矩阵) )。可以从以下位置下载xyz文件:
并通过以下方式导入到matlab中:
AIS_SEC = importdata('AIS_SEC.xyz');
我试过了:
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')
imagesc(gRho)
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.
我试过了:
% 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.
我现在可以使用scatter3绘制nx3文件(见图)
scatter3(XYZ(:,1),XYZ(:,2),XYZ(:,3),2,XYZ(:,3)) ;
colorbar
但是我想用imagesc来做。因此,我想将nx3文件转换为nxm矩阵(栅格/网格格式),另外,我希望将其作为在QGIS中使用的geotiff文件。
谢谢!
您快要在那里了……查看有关得到的数组大小的消息,结果可能是unique(X)
300276个唯一值的结果,这可能是由于某些嘈杂的数据所致。
因此,您可以在需要的域上定义一些新值,而不是使用griddata
这些大值X
和Y
向量:
% make some sample data
N = 1000;
xv = linspace(-10,10,N);
yv = linspace(-10,10,N);
[XV,YV] = meshgrid(xv,yv);
ZV = XV.^2 + YV.^2;
% make into long vectors:
X = XV(:);
Y = YV(:);
Z = ZV(:);
% make x and y vector to interpolate z
N = 50; % size of new grid
xv = linspace(min(X), max(X), N);
yv = linspace(min(Y), max(Y), N);
[XV,YV] = meshgrid(xv,yv);
% use griddata to find right Z for each x,y pair
ZV_grid = griddata(X,Y,Z,XV,YV);
% look at result
figure();
subplot(211)
imagesc(ZV);
subplot(212);
imagesc(ZV_grid)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句