From a407ee106fc819275ac6ce1e5d128b3e12cfdcf1 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 17 十月 2024 10:47:37 +0800
Subject: [PATCH] 1

---
 src/main/java/com/se/simu/service/ResultService.java |   68 ++++++++++++++-------------------
 1 files changed, 29 insertions(+), 39 deletions(-)

diff --git a/src/main/java/com/se/simu/service/ResultService.java b/src/main/java/com/se/simu/service/ResultService.java
index 0af1ac7..c423289 100644
--- a/src/main/java/com/se/simu/service/ResultService.java
+++ b/src/main/java/com/se/simu/service/ResultService.java
@@ -292,10 +292,16 @@
 
         for (String file : files) {
             String fileName = getNameWithExt(file);
-            int hour = Integer.parseInt(fileName.substring(0, 2));
-            int minute = Integer.parseInt(fileName.substring(2, 4));
-            int second = Integer.parseInt(fileName.substring(4, 6));
+            int year = Integer.parseInt(fileName.substring(0, 4));
+            int month = Integer.parseInt(fileName.substring(4, 6));
+            int day = Integer.parseInt(fileName.substring(6, 8));
+            int hour = Integer.parseInt(fileName.substring(8, 10));
+            int minute = Integer.parseInt(fileName.substring(10, 12));
+            int second = Integer.parseInt(fileName.substring(12, 14));
 
+            calendar.set(Calendar.YEAR, year);
+            calendar.set(Calendar.MONTH, month);
+            calendar.set(Calendar.DAY_OF_MONTH, day);
             calendar.set(Calendar.HOUR_OF_DAY, hour);
             calendar.set(Calendar.MINUTE, minute);
             calendar.set(Calendar.SECOND, second);
@@ -413,67 +419,51 @@
     }
 
     private void copeFlow(ResultDto dto, LayerDto layer) {
-        List<String> vxFiles = new ArrayList<>();
-        List<String> vyFiles = new ArrayList<>();
         List<String> files = getFiles(dto.getFlowPath(), ".tif");
-        for (String file : files) {
-            if (file.contains(File.separator + "vx")) vxFiles.add(file);
-            if (file.contains(File.separator + "vy")) vyFiles.add(file);
-        }
-        if (null == vxFiles || null == vyFiles || vxFiles.size() != vyFiles.size() || vxFiles.size() != layer.getWaters().getData().size())
-            return;
+        if (null == files || files.size() != layer.getWaters().getData().size()) return;
 
-        for (int i = 0, c = vxFiles.size(); i < c; i++) {
-            Dataset vxDs = null, vyDs = null;
+        for (int i = 0, c = files.size(); i < c; i++) {
+            Dataset ds = null;
             try {
-                vxDs = gdal.Open(vxFiles.get(i), gdalconst.GA_ReadOnly);
-                vyDs = gdal.Open(vyFiles.get(i), gdalconst.GA_ReadOnly);
-                if (null == vxDs || 0 == vxDs.getRasterCount() || null == vxDs.GetSpatialRef() || null == vyDs || 0 == vyDs.getRasterCount() || null == vyDs.GetSpatialRef())
-                    return;
+                ds = gdal.Open(files.get(i), gdalconst.GA_ReadOnly);
+                if (null == ds || 0 == ds.getRasterCount() || null == ds.GetSpatialRef()) return;
 
-                createFlowPng(dto, vxDs, vyDs, layer, layer.getWaters().getData().get(i));
+                createFlowPng(dto, ds, layer, layer.getWaters().getData().get(i));
             } finally {
-                if (null != vxDs) vxDs.delete();
-                if (null != vyDs) vyDs.delete();
+                if (null != ds) ds.delete();
             }
         }
     }
 
-    private static void createFlowPng(ResultDto dto, Dataset vxDs, Dataset vyDs, LayerDto layer, long ticks) {
+    private static void createFlowPng(ResultDto dto, Dataset ds, LayerDto layer, long ticks) {
         String flowPath = dto.getOutPath() + File.separator + "flows" + File.separator + ticks;
         File dir = new File(flowPath);
         if (!dir.exists() || !dir.isDirectory()) dir.mkdirs();
 
         for (int[] sizes : layer.getTerrain().getSize()) {
-            String vxName = getNameWithExt(vxDs.GetDescription()) + "_" + sizes[0] + "_" + sizes[1];
-            String vxTif = dto.getTemp() + File.separator + vxName + ".tif";
-            Resample(vxDs, vxTif, sizes[0], sizes[1], layer);
-
-            String vyName = getNameWithExt(vyDs.GetDescription()) + "_" + sizes[0] + "_" + sizes[1];
-            String vyTif = dto.getTemp() + File.separator + vyName + ".tif";
-            Resample(vyDs, vyTif, sizes[0], sizes[1], layer);
-            if (!new File(vxTif).exists() || !new File(vyTif).exists()) continue;
+            String name = getNameWithExt(ds.GetDescription()) + "_" + sizes[0] + "_" + sizes[1];
+            String tif = dto.getTemp() + File.separator + name + ".tif";
+            Resample(ds, tif, sizes[0], sizes[1], layer);
+            if (!new File(tif).exists()) continue;
 
             String png = flowPath + File.separator + sizes[0] + "_" + sizes[1] + ".png";
-            vxyTif2Png(layer, vxTif, vyTif, png, sizes[0], sizes[1]);
+            vxyTif2Png(layer, tif, png, sizes[0], sizes[1]);
         }
     }
 
-    private static void vxyTif2Png(LayerDto layer, String vxTif, String vyTif, String png, int width, int height) {
-        Dataset vxDs = null, vyDs = null;
+    private static void vxyTif2Png(LayerDto layer, String tif, String png, int width, int height) {
+        Dataset ds = null;
         try {
-            vxDs = gdal.Open(vxTif, gdalconst.GA_ReadOnly);
-            vyDs = gdal.Open(vyTif, gdalconst.GA_ReadOnly);
-            if (null == vxDs || 0 == vxDs.getRasterCount() || null == vyDs || 0 == vyDs.getRasterCount()) return;
+            ds = gdal.Open(tif, gdalconst.GA_ReadOnly);
+            if (null == ds || 0 == ds.getRasterCount()) return;
 
             float[] vxBuffer = new float[width * height], vyBuffer = new float[width * height];
-            vxDs.GetRasterBand(1).ReadRaster(0, 0, width, height, vxBuffer);
-            vyDs.GetRasterBand(1).ReadRaster(0, 0, width, height, vyBuffer);
+            ds.GetRasterBand(1).ReadRaster(0, 0, width, height, vxBuffer);
+            ds.GetRasterBand(2).ReadRaster(0, 0, width, height, vyBuffer);
 
             createFlowPng(vxBuffer, vyBuffer, png, width, height);
         } finally {
-            if (null != vxDs) vxDs.delete();
-            if (null != vyDs) vyDs.delete();
+            if (null != ds) ds.delete();
         }
     }
 

--
Gitblit v1.9.3