From 73ca802381bd76cc1a5bd608e4a1e5ef12de88a2 Mon Sep 17 00:00:00 2001 From: wuww <252740454@qq.com> Date: 星期日, 04 五月 2025 20:46:46 +0800 Subject: [PATCH] 完成求解器对接~ --- src/main/java/com/se/nsl/service/ResolveService.java | 66 +++++++++++++++++++++++++++----- 1 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/se/nsl/service/ResolveService.java b/src/main/java/com/se/nsl/service/ResolveService.java index fd7425a..462aae4 100644 --- a/src/main/java/com/se/nsl/service/ResolveService.java +++ b/src/main/java/com/se/nsl/service/ResolveService.java @@ -13,6 +13,7 @@ import com.se.nsl.helper.WebHelper; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; +import org.apache.axis.utils.StringUtils; import org.gdal.ogr.Geometry; import org.gdal.ogr.ogr; import org.springframework.beans.factory.annotation.Autowired; @@ -27,6 +28,8 @@ import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -40,8 +43,12 @@ @Resource PropertiesConfig config; - @Autowired - private UwService uwService; + + @Resource + UwService uwService; + + @Resource + TestService testService; public int start(Simu simu) { Date now = new Date(); @@ -90,17 +97,17 @@ try { DataPo data = JSONUtil.toBean(simu.getData(), DataPo.class); - update(simu, 1, "寮�濮�"); - + update(simu, 1, "鍒濆鍖栧弬鏁�"); initArgs(data); - String rs = callUwSolver(data); - //gedbService.copeVectors(token, data, db); - //update(simu, 3, null); - //gedbService.copeDem(token, data); + update(simu, 2, "璋冪敤姹傝В鍣�"); + callUwSolver(data); - //update(simu, 4, null); - //uwService.createRainFile(data); + update(simu, 3, "璋冪敤Zarr杞琓if"); + callZarr2tif(data); + + update(simu, 4, "瑙f瀽鏁版嵁"); + createNsl(data); update(simu, 10, "瀹屾垚"); } catch (Exception ex) { @@ -158,8 +165,17 @@ return callBat(cmd); } + /** + * 璋冪敤zarr2tif + */ private String callZarr2tif(DataPo data) throws Exception { - String cmd = ""; + File uwBat = new File(config.getUwSolverBat()); + String zarrFile = uwBat.getParent() + File.separator + "result.zarr"; + String inPath = config.getInPath() + File.separator + data.getInPath(); + String terrainFile = inPath + File.separator + config.getDemFile(); + String waterPath = inPath + File.separator + "depth"; + + String cmd = String.format("%s \"%s\" \"%s\" \"%s\" \"%s\"", config.getZarr2tifBat(), "depth", zarrFile, terrainFile, waterPath); return callBat(cmd); } @@ -189,4 +205,32 @@ return null; } } + + private void createNsl(DataPo data) throws Exception { + String inPath = config.getInPath() + File.separator + data.getInPath() + File.separator + "depth"; + procTifs(inPath, inPath, data.getStartTime()); + + testService.test(data); + } + + private void procTifs(String tifPath, String outPath, Date startTime) { + SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(startTime); + + for (File file : new File(tifPath).listFiles()) { + if (!file.exists() || !file.isDirectory()) continue; + + File tif = new File(tifPath + "\\" + file.getName() + File.separator + "depth.tif"); + if (!tif.exists() || tif.isDirectory()) continue; + + calendar.add(Calendar.SECOND, 1); + String newName = df.format(calendar.getTime()); + String newFile = outPath + File.separator + newName + ".tif"; + + System.out.println(newFile); + tif.renameTo(new File(newFile)); + file.delete(); + } + } } -- Gitblit v1.9.3