AI出,NC转TIF,NC数据是单年,需要读取变量名称
clc;
clear;
% 读取NC文件
datadir = 'J:\third\co2dlwrf\dswrf\mean\year\'; % 指定批量数据所在的文件夹
filelist = dir([datadir, 'yearmean_*.nc']); % 列出所有满足指定类型的文件
[A, R] = geotiffread('J:\VPD\final\pre\pre_1982_sum.tif'); % 该处路径为上述Arcgis中导出带坐标系的TIFF文件需要调整
info = geotiffinfo('J:\VPD\final\pre\pre_1982_sum.tif'); % 该处路径为上述Arcgis中导出带坐标系的TIFF文件需要调整
for year = 1982:2018
% 构建.nc文件路径
ncFilePath = [datadir, 'yearmean_', num2str(year), '.nc'];
% 显示nc文件内容
ncdisp(ncFilePath);
% 读取经度、纬度和数据变量
lon = ncread(ncFilePath, 'lon');
lat = ncread(ncFilePath, 'lat');
tmp = ncread(ncFilePath, 'dswrf');
% 数据处理
data = tmp'; % 转置数据
data(data == -32768.0) = NaN; % 设置无效值
data = data * 0.1; % 调整数据比例
% 定义地理参考信息
R = georasterref('RasterSize', size(data), 'Latlim', [double(min(lat)) double(max(lat))], 'Lonlim', [double(min(lon)) double(max(lon))]);
% 构建输出.tif文件名
filename1 = ['J:\third\co2dlwrf\dswrf\mean\yearmean_', num2str(year), '.tif'];
% 写入GeoTIFF文件
geotiffwrite(filename1, data, R, 'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
end