From d073fb92291373092ab61ae43bce3cb0e610ef11 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 02 十二月 2024 11:31:57 +0800 Subject: [PATCH] 1 --- src/main/java/com/se/simu/domain/dto/ResultDto.java | 24 +++++++ src/main/java/com/se/simu/service/Hdf5Service.java | 68 ++++++++++++++++++++++ src/main/java/com/se/simu/service/ResultService.java | 1 src/main/java/com/se/simu/controller/TestController.java | 27 +++++++- pom.xml | 6 ++ src/main/resources/application.yml | 1 6 files changed, 121 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 0ed76d3..b2a4172 100644 --- a/pom.xml +++ b/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> diff --git a/src/main/java/com/se/simu/controller/TestController.java b/src/main/java/com/se/simu/controller/TestController.java index 0c3486f..30a9fc9 100644 --- a/src/main/java/com/se/simu/controller/TestController.java +++ b/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); + } + } } diff --git a/src/main/java/com/se/simu/domain/dto/ResultDto.java b/src/main/java/com/se/simu/domain/dto/ResultDto.java index 61534a3..4ae214b 100644 --- a/src/main/java/com/se/simu/domain/dto/ResultDto.java +++ b/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; + } } diff --git a/src/main/java/com/se/simu/service/Hdf5Service.java b/src/main/java/com/se/simu/service/Hdf5Service.java new file mode 100644 index 0000000..2cd1f67 --- /dev/null +++ b/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); + + // 鏍规嵁鏁版嵁闆嗙殑缁村害鍒涘缓涓�涓狫ava鏁扮粍鏉ュ瓨鍌ㄦ暟鎹� + int[] buffer = new int[1]; + + // 璇诲彇鏁版嵁鍒癑ava鏁扮粍 + 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); + } + } +} diff --git a/src/main/java/com/se/simu/service/ResultService.java b/src/main/java/com/se/simu/service/ResultService.java index a2d5efe..a63cfc6 100644 --- a/src/main/java/com/se/simu/service/ResultService.java +++ b/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()); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8846ca6..fedfa4f 100644 --- a/src/main/resources/application.yml +++ b/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 -- Gitblit v1.9.3