xingjinshuang
2025-02-20 0890b7861feae74bdcfd1851e577db6b9f31d484
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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);
        }
    }
}