From 0890b7861feae74bdcfd1851e577db6b9f31d484 Mon Sep 17 00:00:00 2001
From: xingjinshuang <xingjs@qq.com>
Date: 星期四, 20 二月 2025 14:40:39 +0800
Subject: [PATCH] @xingjs@20250220@添加处理sww相关接口类

---
 src/main/java/com/se/simu/service/WaterService.java |   70 +++++++++++++++++-----------------
 1 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/src/main/java/com/se/simu/service/WaterService.java b/src/main/java/com/se/simu/service/WaterService.java
index b20879e..46c7c96 100644
--- a/src/main/java/com/se/simu/service/WaterService.java
+++ b/src/main/java/com/se/simu/service/WaterService.java
@@ -4,6 +4,7 @@
 import cn.hutool.json.JSONUtil;
 import com.se.simu.config.PropertiesConfig;
 import com.se.simu.domain.po.DataPo;
+import com.se.simu.domain.po.PondingPo;
 import com.se.simu.domain.po.SimuPo;
 import com.se.simu.domain.vo.*;
 import com.se.simu.helper.GdalHelper;
@@ -20,17 +21,9 @@
 import javax.annotation.Resource;
 import java.io.File;
 import java.io.FileInputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
 
-/**
- * 鍐呮稘鏈嶅姟绫�
- *
- * @author WWW
- * @date   2024-07-16
- */
 @Slf4j
 @Service
 @SuppressWarnings("ALL")
@@ -38,9 +31,6 @@
     @Resource
     PropertiesConfig config;
 
-    /**
-     * 鑾峰彇鍏冩暟鎹俊鎭�
-     */
     public byte[] getson(String serviceName, String json) {
         try {
             String filePath = config.getOutPath() + File.separator + serviceName + File.separator + json;
@@ -63,30 +53,18 @@
         }
     }
 
-    /**
-     * 鑾峰彇鍦板舰楂樺害鍥�
-     */
     public String getTerraMap(String serviceName, Integer width, Integer height) {
         return config.getOutPath() + File.separator + serviceName + File.separator + "terrain" + File.separator + width + "_" + height + ".png";
     }
 
-    /**
-     * 鑾峰彇姘撮潰楂樺害鍥�
-     */
     public String getWaterMap(String serviceName, Integer width, Integer height, Long timestamp) {
         return config.getOutPath() + File.separator + serviceName + File.separator + "waters" + File.separator + timestamp + File.separator + width + "_" + height + ".png";
     }
 
-    /**
-     * 鑾峰彇姘存祦鍚戞祦閫熷浘
-     */
     public String getFlowMap(String serviceName, Integer width, Integer height, Long timestamp) {
         return config.getOutPath() + File.separator + serviceName + File.separator + "flows" + File.separator + timestamp + File.separator + width + "_" + height + ".png";
     }
 
-    /**
-     * 鏍规嵁鍧愭爣鏌ヨ绉按娣卞害:gdalconst.GA_Update
-     */
     public Double getWaterHeight(SimuPo simu, double x, double y, Long timestamp) {
         String filePath = config.getOutPath() + File.separator + simu.getServiceName() + File.separator + "waters"
                 + File.separator + timestamp + File.separator + "water.tif";
@@ -128,16 +106,7 @@
         return data.getSpatialReference();
     }
 
-    /**
-     * 灏嗗湴鍥惧潗鏍囪浆鎹负鏍呮牸鍍忕礌鍧愭爣
-     *
-     * @param gt 浠垮皠鍙樻崲鍙傛暟
-     * @param x  妯潗鏍�
-     * @param y  绾靛潗鏍�
-     * @return 鍍忕礌鍧愭爣
-     */
     public int[] coordinates2ColRow(double[] gt, double x, double y) {
-        // 鍚戜笅鍙栨暣,濡傛灉鍚戜笂鍙栨暣浼氬鑷磋绠楃粨鏋滃亸澶э紝浠庤�屽湪鍚庨潰璇诲彇鍒伴偦杩戝儚鍏冪殑鏁版嵁
         //Double col = Math.floor(((y - gt[3]) * gt[1] - (x - gt[0]) * gt[4]) / (gt[5] * gt[1] - gt[2] * gt[4]));
         Double col = Math.floor((y * gt[1] - x * gt[4] + gt[0] * gt[4] - gt[3] * gt[1]) / (gt[5] * gt[1] - gt[2] * gt[4]));
         Double row = Math.floor((x - gt[0] - col * gt[2]) / gt[1]);
@@ -150,6 +119,40 @@
     }
 
     public Double getWaterArea(SimuPo simu, double x, double y, Long timestamp) {
+        List<PondingPo> list = readWaterJson(simu.getServiceName(), timestamp);
+        if (CollectionUtils.isEmpty(list)) return null;
+
+        //DataPo data = JSONUtil.toBean(simu.getData(), DataPo.class);
+        //SpatialReference sr = GdalHelper.createSpatialReference(data.getEpsg());
+
+        Geometry p = new Geometry(ogr.wkbPoint);
+        p.AddPoint_2D(x, y);
+        p.AssignSpatialReference(GdalHelper.SR4326);
+
+        for (PondingPo po : list) {
+            if (StringHelper.isEmpty(po.getPolygon())) continue;
+
+            Geometry polygon = Geometry.CreateFromWkt(po.getPolygon());
+            polygon.AssignSpatialReference(GdalHelper.SR4326);
+            if (polygon.Contains(p)) {
+                return po.getArea();
+            }
+        }
+
+        return null;
+    }
+
+    private List<PondingPo> readWaterJson(String serviceName, Long timestamp) {
+        String filePath = config.getOutPath() + File.separator + serviceName + File.separator + "waters" + File.separator + timestamp + File.separator + "water.json";
+        String json = getText(filePath);
+        if (StringHelper.isEmpty(json)) {
+            return null;
+        }
+
+        return JSONUtil.toList(json, PondingPo.class);
+    }
+
+    public Double getWaterArea2(SimuPo simu, double x, double y, Long timestamp) {
         String filePath = config.getOutPath() + File.separator + simu.getServiceName() + File.separator + "waters"
                 + File.separator + timestamp + File.separator + "water.geojson";
         if (!FileUtil.exist(filePath)) return null;
@@ -192,9 +195,6 @@
         }
     }
 
-    /**
-     * 鏍规嵁seid鏌ヨ寤虹瓚鐗╂秹姘存繁搴�
-     */
     public List<BuildingDepthVo> getBuildingDepthBySeid(String serviceName, String seid) {
         List<BuildingDepthVo> list = readBuildingJson(serviceName);
         if (CollectionUtils.isEmpty(list)) return null;

--
Gitblit v1.9.3