package com.se.simu.service; import cn.hutool.core.io.FileUtil; import com.se.simu.config.PropertiesConfig; import com.se.simu.domain.dto.LayerDto; import com.se.simu.domain.dto.ResultDto; import com.se.simu.domain.po.DataPo; import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.File; @Slf4j @Service @SuppressWarnings("ALL") public class Hdf5Service { @Resource PropertiesConfig config; public void test(DataPo data) throws Exception { String basePath = config.getInPath() + File.separator + data.getInPath() + File.separator; ResultDto dto = new ResultDto( data.getInPath(), basePath + config.getTerrainFile(), basePath + config.getBuildingFile(), basePath + config.getWaterPath(), basePath + config.getFlowPath(), config.getInPath(), config.getOutPath(), data.getEpsg()); LayerDto layer = new LayerDto(config.getVer(), data.getEpsg(), config.getSizes()); process(dto, layer); } // https://blog.51cto.com/u_16213355/12235346 private void process(ResultDto dto, LayerDto layer) throws Exception { int fileId = 0; int datasetId = 0; try { if (!FileUtil.exist(dto.getH5Path())) return; fileId = H5.H5Fopen(dto.getH5Path(), HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT); if (fileId == 0) return; // H5F_OBJ_DATASET,H5E_DATASET,H5G_DATASET=1, //int dsCount = H5.H5Fget_obj_count(fileId, HDF5Constants.H5G_DATASET); //for (int i = 0; i < dsCount; i++) { // System.out.println("Dataset: " + ""); //} //datasetId = H5.H5Dopen(fileId, "", HDF5Constants.H5P_DEFAULT); int groupId = H5.H5Gopen(fileId, "data"); if (groupId == 0) return; /*datasetId = H5.H5Dopen(fileId, "data", HDF5Constants.H5P_DEFAULT); if (datasetId == 0) return; // 获取数据集的维度 //long[] dims = H5.H5Dget_dims(datasetId); // 根据数据集的维度创建一个Java数组来存储数据 int[] buffer = new int[1]; // 读取数据到Java数组 int herr = H5.H5Dread(datasetId, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, buffer); // 输出读取到的数据 System.out.println(buffer[0]);*/ H5.H5Dclose(groupId); } catch (Exception ex) { ex.printStackTrace(); } finally { if (fileId > 0) H5.H5Dclose(fileId); } } }