multi raster files into netcdf4

5 ビュー (過去 30 日間)
Sri Adiyanti
Sri Adiyanti 2023 年 6 月 28 日
コメント済み: Sri Adiyanti 2023 年 9 月 4 日
Hi, anyone has a m script handy to convert GIS multiple (240 files) raster files (same size) into 1 netcdf4 file?

採用された回答

Niranjan Sundararajan
Niranjan Sundararajan 2023 年 7 月 12 日
Hey there,
Hope this helps.
directory = 'path_to_directory';
fileList = dir(fullfile(directory, '*.tif')); %assuming .tif files
info = geotiffinfo(fullfile(directory, fileList(1).name));
R = info.SpatialRef;
data = zeros(R.RasterSize(1), R.RasterSize(2), numel(fileList));
for i = 1:numel(fileList)
filename = fullfile(directory, fileList(i).name);
data(:, :, i) = geotiffread(filename);
end
ncid = netcdf.create('output.nc', 'NETCDF4');
dimid_x = netcdf.defDim(ncid, 'x', R.RasterSize(2));
dimid_y = netcdf.defDim(ncid, 'y', R.RasterSize(1));
dimid_time = netcdf.defDim(ncid, 'time', numel(fileList));
varid_data = netcdf.defVar(ncid, 'data', 'double', [dimid_x, dimid_y, dimid_time]);
varid_x = netcdf.defVar(ncid, 'x', 'double', dimid_x);
varid_y = netcdf.defVar(ncid, 'y', 'double', dimid_y);
varid_time = netcdf.defVar(ncid, 'time', 'double', dimid_time);
netcdf.putAtt(ncid, varid_data, 'units', 'your_units');
netcdf.putAtt(ncid, varid_x, 'units', 'your_units');
netcdf.putAtt(ncid, varid_y, 'units', 'your_units');
netcdf.putAtt(ncid, varid_time, 'units', 'your_units');
netcdf.endDef(ncid);
netcdf.putVar(ncid, varid_data, data);
netcdf.putVar(ncid, varid_x, R.XLimWorld);
netcdf.putVar(ncid, varid_y, R.YLimWorld);
netcdf.putVar(ncid, varid_time, 1:numel(fileList));
netcdf.close(ncid);
  1 件のコメント
Sri Adiyanti
Sri Adiyanti 2023 年 9 月 4 日
Thankyou.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by