1
13693261870
2024-12-02 d073fb92291373092ab61ae43bce3cb0e610ef11
1
已添加1个文件
已修改5个文件
127 ■■■■■ 文件已修改
pom.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/controller/TestController.java 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/domain/dto/ResultDto.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/Hdf5Service.java 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/ResultService.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -141,6 +141,12 @@
            <artifactId>caffeine</artifactId>
            <version>2.9.3</version>
        </dependency>
        <!--hdf5-->
        <dependency>
            <groupId>org.hdfgroup</groupId>
            <artifactId>hdf-java</artifactId>
            <version>2.6.1</version>
        </dependency>
    </dependencies>
    <build>
src/main/java/com/se/simu/controller/TestController.java
@@ -4,10 +4,7 @@
import com.se.simu.domain.vo.R;
import com.se.simu.helper.ShpHelper;
import com.se.simu.helper.StringHelper;
import com.se.simu.service.GedbService;
import com.se.simu.service.ResultService;
import com.se.simu.service.SimuService;
import com.se.simu.service.UwService;
import com.se.simu.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@@ -33,6 +30,9 @@
    @Resource
    SimuService simuService;
    @Resource
    Hdf5Service hdf5Service;
    @Resource
    ResultService resultService;
@@ -67,7 +67,7 @@
            @ApiImplicitParam(name = "time", value = "时间", dataType = "String", paramType = "query", example = "2024-11-07 09:23:42")
    })
    @GetMapping("/testResuslt")
    public R<Object> testResuslt(String path,String time) {
    public R<Object> testResuslt(String path, String time) {
        try {
            DataPo data = new DataPo();
            data.setEpsg(4548);
@@ -141,4 +141,21 @@
            return fail(ex, null);
        }
    }
    @ApiOperation(value = "testH5 *")
    @GetMapping("/testH5")
    public R<Object> testH5() {
        try {
            DataPo data = new DataPo();
            data.setEpsg(4548);
            data.setInPath("20241010095328");
            data.setStartTime(StringHelper.YMDHMS_FORMAT.parse("2024-09-30 00:00:00"));
            hdf5Service.test(data);
            return success("ok");
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
}
src/main/java/com/se/simu/domain/dto/ResultDto.java
@@ -19,6 +19,10 @@
    private String flowPath;
    private String h5Path;
    private String inPath;
    private String outPath;
    private String temp;
@@ -36,13 +40,15 @@
        this.buildingList = new ArrayList<>();
    }
    public ResultDto(String serviceName, String terrainFile, String buildingFile, String waterPath, String flowPath, String outPath, int epsg) {
    public ResultDto(String serviceName, String terrainFile, String buildingFile, String waterPath, String flowPath, String inPath, String outPath, int epsg) {
        this();
        this.serviceName = serviceName;
        this.terrainFile = terrainFile;
        this.buildingFile = buildingFile;
        this.waterPath = waterPath;
        this.flowPath = flowPath;
        this.inPath = inPath + File.separator + serviceName;
        this.h5Path = this.inPath + File.separator + ".save" + File.separator + serviceName + ".h5";
        this.outPath = outPath + File.separator + serviceName;
        this.temp = outPath + File.separator + serviceName + File.separator + "temp";
        this.epsg = epsg;
@@ -101,6 +107,14 @@
        this.flowPath = flowPath;
    }
    public String getInPath() {
        return inPath;
    }
    public void setInPath(String inPath) {
        this.inPath = inPath;
    }
    public String getOutPath() {
        return outPath;
    }
@@ -148,4 +162,12 @@
    public void setSpatialReference(SpatialReference spatialReference) {
        this.spatialReference = spatialReference;
    }
    public String getH5Path() {
        return h5Path;
    }
    public void setH5Path(String h5Path) {
        this.h5Path = h5Path;
    }
}
src/main/java/com/se/simu/service/Hdf5Service.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,68 @@
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 lombok.extern.slf4j.Slf4j;
import ncsa.hdf.hdf5lib.H5;
import ncsa.hdf.hdf5lib.HDF5Constants;
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);
    }
    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;
            datasetId = H5.H5Dopen(fileId, "data");
            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]);
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (datasetId > 0) H5.H5Dclose(datasetId);
            if (fileId > 0) H5.H5Dclose(fileId);
        }
    }
}
src/main/java/com/se/simu/service/ResultService.java
@@ -51,6 +51,7 @@
                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());
src/main/resources/application.yml
@@ -99,6 +99,7 @@
  #inPath: D:\simu\in
  inPath: D:\simu\uwsolver
  outPath: D:\simu\out
  #
  host: http://106.120.22.26:8024/
  user: admin
  pwd: admin