From d45e75a608ce07a56cf82a829ce6bd740e672eeb Mon Sep 17 00:00:00 2001
From: wuww <252740454@qq.com>
Date: 星期二, 15 四月 2025 12:22:11 +0800
Subject: [PATCH] 添加png收集方法

---
 src/main/java/com/se/nsl/service/TestService.java |   21 +++++++++-
 src/test/java/com/se/nsl/AppTest.java             |   50 ++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/se/nsl/service/TestService.java b/src/main/java/com/se/nsl/service/TestService.java
index dc05269..c381cf7 100644
--- a/src/main/java/com/se/nsl/service/TestService.java
+++ b/src/main/java/com/se/nsl/service/TestService.java
@@ -224,7 +224,7 @@
     }
 
     public void setWaterHeight(LayerDto layer, List<String> files) {
-        files.parallelStream().forEach(file -> {
+        /*files.parallelStream().forEach(file -> {
             Dataset ds = null;
             try {
                 ds = gdal.Open(file, gdalconstConstants.GA_ReadOnly);
@@ -236,7 +236,24 @@
             } finally {
                 if (null != ds) ds.delete();
             }
-        });
+        });*/
+
+        int c = files.size();
+        int step = c <= 1 ? 1 : c / 10;
+        for (int i = 0; i < c; i += step) {
+            Dataset ds = null;
+            try {
+                ds = gdal.Open(files.get(i), gdalconstConstants.GA_ReadOnly);
+                if (null == ds || 0 == ds.getRasterCount()) return;
+
+                double[] mm = new double[2];
+                ds.GetRasterBand(1).ComputeRasterMinMax(mm, 0);
+                layer.getWaters().setHeight(mm[0], mm[1]);
+            } finally {
+                if (null != ds) ds.delete();
+            }
+        }
+
         layer.getExtension().setMaxHeight(layer.getExtension().getMaxHeight() + layer.getWaters().getMaxHeight());
         layer.getExtension().setMaxHeight(ComHelper.getMaxVal(layer.getExtension().getMaxHeight(), 1000000));
         layer.getExtension().setMinHeight(ComHelper.getMaxVal(layer.getExtension().getMinHeight(), 1000000));
diff --git a/src/test/java/com/se/nsl/AppTest.java b/src/test/java/com/se/nsl/AppTest.java
index 2affd86..6407bf8 100644
--- a/src/test/java/com/se/nsl/AppTest.java
+++ b/src/test/java/com/se/nsl/AppTest.java
@@ -1,6 +1,7 @@
 package com.se.nsl;
 
 import com.se.nsl.helper.GdalHelper;
+import javafx.scene.input.DataFormat;
 import org.gdal.gdal.Dataset;
 import org.gdal.gdal.Driver;
 import org.gdal.gdal.gdal;
@@ -21,8 +22,10 @@
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 
 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@@ -30,7 +33,7 @@
     @Test
     public void procDepthFiles() {
         String path = "D:\\other\\simu\\uwsolver\\20250412\\depth";
-        for (File file : new File(path).listFiles()) {
+        /*for (File file : new File(path).listFiles()) {
             if (!file.exists() || !file.isDirectory()) continue;
 
             File tif = new File(path + "\\" + file.getName() + "\\depth.tif");
@@ -40,9 +43,54 @@
             System.out.println(newFile.getPath());
             tif.renameTo(newFile);
             file.delete();
+        }*/
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(new Date(2025 - 1900, 3, 12, 0, 0, 0));
+        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
+
+        String oldPath = "D:\\other\\simu\\uwsolver\\20250412\\depth-old";
+        String newPath = "D:\\other\\simu\\uwsolver\\20250412\\depth";
+        for (File file : new File(oldPath).listFiles()) {
+            String fileName = file.getName().replace("2025041200", "").replace(".tif", "");
+            int second = Integer.parseInt(fileName);
+            calendar.set(Calendar.SECOND, 0);
+            calendar.set(Calendar.MINUTE, 0);
+            calendar.set(Calendar.HOUR, 0);
+            calendar.add(Calendar.SECOND, second);
+            String newName = df.format(calendar.getTime());
+            String newFile = newPath + File.separator + newName + ".tif";
+
+            System.out.println(newFile);
+            file.renameTo(new File(newFile));
         }
     }
 
+    @Test
+    public void collectPngToList() {
+        System.out.println("------------------------------------------- start");
+        int size = 1024;
+        String outputPath = "D:\\other\\simu\\out\\20250412\\waters";
+        List<String> list = new ArrayList<>();
+        for (File file : new File(outputPath).listFiles()) {
+            if (!file.exists() || file.isFile()) continue;
+
+            File pngFile = new File(file.getPath() + File.separator + size + "_" + size + ".png");
+            if (!pngFile.exists() || pngFile.isDirectory()) continue;
+
+            list.add("file '" + pngFile.getPath().replace("\\", "/") + "'");
+            System.out.println(list.get(list.size() - 1));
+        }
+
+        Path path = Paths.get(outputPath + File.separator + "list.txt");
+        try {
+            Files.write(path, list, StandardCharsets.UTF_8);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        System.out.println("------------------------------------------- end");
+    }
+
     //@Test
     public void readZarr() throws Exception {
         GdalHelper.init("D:\\soft\\release-1928-x64-dev\\release-1928-x64\\bin");

--
Gitblit v1.9.3