matlab代码12个月FVC\EVI\NDVI等数据逐像元最大值合成得年数据,逐年输出

适用于需要最大值合成方法的数据,植被数据等

folderPath = 'J:\PTJPL ET8218\驱动因子\FVC\month'; % 修改为你的文件夹路径

% 导入纬度数据
[aa, R] = geotiffread(fullfile(folderPath, 'FVC_1982_1.tif'));
info = geotiffinfo(fullfile(folderPath, 'FVC_1982_1.tif'));

% 定义年份范围
startYear = 1982;
endYear = 2018;
years = startYear:endYear;

% 获取所有栅格文件的列表
filePattern = fullfile(folderPath, 'FVC_*.tif');
rasterFiles = dir(filePattern);

% 初始化一个结构数组来存储每年的最大合成结果
annualMaxFVC = struct();

% 循环遍历每一年
for year = years
    % 初始化一个列表来存储每月的FVC数据
    monthlyFVC = [];

    % 循环遍历每个月
    for month = 1:12
        % 构造文件名
        fileName = sprintf('FVC_%d_%d.tif', year, month);
        filePath = fullfile(folderPath, fileName);
        
        % 检查文件是否存在
        if isfile(filePath)
            % 读取栅格数据
            fvcData = imread(filePath);
            
            % 如果是第一个月,初始化monthlyFVC矩阵
            if isempty(monthlyFVC)
                monthlyFVC = fvcData;
            else
                % 对于每个像元,更新最大FVC值
                monthlyFVC = max(monthlyFVC, fvcData);
            end
        end
    end

    % 将每年的最大FVC值存储在结构数组中
    annualMaxFVC(year - startYear + 1).year = year;
    annualMaxFVC(year - startYear + 1).maxFVC = monthlyFVC;

    % 保存每年的最大FVC值为新的tif文件
    outputFileName = sprintf('FVC_Max_%d.tif', year);
    outputFilePath = fullfile(folderPath, outputFileName);

    % 将 double 类型的 FVC 值转换为 [0, 10000] 范围的 uint16 类型,以保持精度
    monthlyFVC_scaled = uint16(monthlyFVC * 10000);

    geotiffwrite(outputFilePath, monthlyFVC_scaled, R);

    fprintf('Year %d processed and saved to %s\n', year, outputFilePath);
end

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值