From eaf2eddc15c08bc073c953630b727f6497dfee3a Mon Sep 17 00:00:00 2001
From: 张洋洋 <10611411+yang-yang-z@user.noreply.gitee.com>
Date: 星期二, 18 二月 2025 09:53:46 +0800
Subject: [PATCH] [add]tif裁剪

---
 src/main/java/com/se/simu/controller/SimuController.java |  156 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 98 insertions(+), 58 deletions(-)

diff --git a/src/main/java/com/se/simu/controller/SimuController.java b/src/main/java/com/se/simu/controller/SimuController.java
index c1282d6..d58c7a1 100644
--- a/src/main/java/com/se/simu/controller/SimuController.java
+++ b/src/main/java/com/se/simu/controller/SimuController.java
@@ -244,10 +244,6 @@
                         Double minY = jsonObject.getDouble("minX");
                         Double maxY = jsonObject.getDouble("maxX");
                         // 3 鍒ゆ柇鑼冨洿鍊兼槸鍚︿负绌�
-                        // vo.setMinx(jsonObject.getDouble("minX"));
-                        // vo.setMaxx(jsonObject.getDouble("maxX"));
-                        // vo.setMiny(jsonObject.getDouble("minY"));
-                        // vo.setMaxy(jsonObject.getDouble("maxY"));
                         vo.setMinx(jsonObject.getDouble("minY"));
                         vo.setMaxx(jsonObject.getDouble("maxY"));
                         vo.setMiny(jsonObject.getDouble("minX"));
@@ -340,6 +336,15 @@
                     return fail("闃叉睕鑼冨洿涓嶈兘涓虹┖", false);
                 }
             }
+            if (StringUtils.isEmpty(vo.getSemUrl())){
+                return fail("sem鏂囦欢鐢熸垚璺緞涓嶈兘涓虹┖锛�", false);
+            }
+            List<GridDto> dtos = new ArrayList<>();
+            dtos.add(new GridDto(vo.getMiny(), vo.getMinx()));
+            dtos.add(new GridDto(vo.getMaxy(), vo.getMinx()));
+            dtos.add(new GridDto(vo.getMaxy(), vo.getMaxx()));
+            dtos.add(new GridDto(vo.getMiny(), vo.getMaxx()));
+            createSem(tableName, dtos, vo.getSemUrl());
             // 寮�濮嬫ā鎷熻绠�
             boolean flag = simuFilesService.createByfiles(vo);
             return success(flag, flag ? "鎴愬姛" : "澶辫触");
@@ -348,9 +353,36 @@
         }
     }
 
+    public R<Boolean> createSem(String tableName, List<GridDto> dtos, String semUrl) throws Exception {
+        boolean ends = semUrl.endsWith("\\");
+        if (!ends) {
+            semUrl = semUrl + "\\";
+        }
+        File file = new File(semUrl);
+        if (!file.exists()) {
+            file.mkdirs();
+        }
+        //闄嶉洦鏂囦欢鐢熸垚
+        saveZarr(tableName,semUrl);
+        String token = EntityLibraryUtils.login();
+        //绠$偣鐢熸垚
+        pointTosem(dtos, token,semUrl);
+        //绠$嚎鐢熸垚
+        lineToSem(dtos, token,semUrl);
+        //鍦板舰鐢熸垚
+        terrainToSem(dtos,semUrl);
+        //鑼冨洿鐢熸垚
+        gridToCityJson(dtos,semUrl);
+        //娌虫祦鐢熸垚
+        riverToSem(semUrl);
+        //鍦熷湴鍒╃敤鐢熸垚
+        landuseToSem(semUrl);
+        return success(true);
+    }
+
     @ApiOperation(value = "tarr鏂囦欢缁勮")
     @GetMapping(value = "/saveZarr", produces = "application/json; charset=UTF-8")
-    public R<String> saveZarr(@RequestParam("name") String tableName) throws Exception {
+    public R<String> saveZarr(@RequestParam("name") String tableName,String semUrl) throws Exception {
         List<String> list = CsvToSQLiteUtils.getNameList(tableName);
         String path = outPath + "\\";
         String rainfall = "rainfall\\";
@@ -407,21 +439,13 @@
         FileWriter fileWriter = new FileWriter(path + tableName + "\\闄嶉洦閲�.json");
         fileWriter.write(jsonObject.toJSONString());
         fileWriter.close();
-        String filePatn = inPath + "\\tongzhou\\";
-        File file = new File(filePatn);
-        if (!file.exists()) {
-            file.mkdirs();
-        }
-        SemUtils.cityJsonToSem(path + tableName + "\\闄嶉洦閲�.json", filePatn + "raingage.sem");
-        return success(filePatn + "raingage.sem");
+        SemUtils.cityJsonToSem(path + tableName + "\\闄嶉洦閲�.json", semUrl + "raingage.sem");
+        return success(semUrl + "raingage.sem");
     }
 
-    @ApiOperation(value = "绠$偣杞瑂em")
-    @PostMapping(value = "/pointTosem", produces = "application/json; charset=UTF-8")
-    public R<String> pointTosem(@RequestBody List<GridDto> dtos) throws Exception {
+    public R<String> pointTosem(List<GridDto> dtos, String token,String semUrl) throws Exception {
         String path = outPath + "\\point\\";
         String publicKey = EntityLibraryUtils.getPublicKey();
-        String token = EntityLibraryUtils.login();
         JSONArray jsonArrayList = EntityLibraryUtils.getPointInfo(dtos, token);
         JSONObject jsonObject = getModule("pointmodule.json");
         for (int s = 0; s < jsonArrayList.size(); s++) {
@@ -484,14 +508,10 @@
         FileWriter fileWriter = new FileWriter(pointPath);
         fileWriter.write(jsonObject.toJSONString());
         fileWriter.close();
-        String filePatn = inPath + "\\tongzhou\\";
-        File file = new File(filePatn);
-        if (!file.exists()) {
-            file.mkdirs();
-        }
-        SemUtils.cityJsonToSem(pointPath, filePatn + "node.sem");
-        return success(filePatn + "node.sem");
+        SemUtils.cityJsonToSem(pointPath, semUrl + "node.sem");
+        return success(semUrl + "node.sem");
     }
+
     @ApiOperation(value = "绠$偣杞琧ityjson")
     @GetMapping(value = "/pointToCityJson", produces = "application/json; charset=UTF-8")
     public R<String> pointToCityJson(@RequestParam("shpPath") String shpPath) throws Exception {
@@ -541,12 +561,9 @@
         return success(filePatn + "node.sem");
     }
 
-    @ApiOperation(value = "绠$嚎sem鐢熸垚")
-    @PostMapping(value = "/lineToSem", produces = "application/json; charset=UTF-8")
-    public R<String> lineToSem(@RequestBody List<GridDto> dtos) throws Exception {
+    public R<String> lineToSem(List<GridDto> dtos, String token,String semUrl) throws Exception {
         String path = outPath + "\\line\\";
         String publicKey = EntityLibraryUtils.getPublicKey();
-        String token = EntityLibraryUtils.login();
         JSONArray jsonArrayList = EntityLibraryUtils.getLineInfo(dtos, token);
         if (jsonArrayList.size() == 0) {
             return fail("璇ュ尯鍩熶笉瀛樺湪绠$嚎锛�");
@@ -635,13 +652,8 @@
         FileWriter fileWriter = new FileWriter(pointPath);
         fileWriter.write(jsonObject.toJSONString());
         fileWriter.close();
-        String filePatn = inPath + "\\tongzhou\\";
-        File file = new File(filePatn);
-        if (!file.exists()) {
-            file.mkdirs();
-        }
-        SemUtils.cityJsonToSem(pointPath, filePatn + "link.sem");
-        return success(filePatn + "link.sem");
+        SemUtils.cityJsonToSem(pointPath, semUrl + "link.sem");
+        return success(semUrl + "link.sem");
     }
 
     @ApiOperation(value = "绠$嚎杞琧ityjson")
@@ -697,6 +709,49 @@
         return success(filePatn + "link.sem");
     }
 
+    @ApiOperation(value = "鍦板舰杞瑂em")
+    @PostMapping(value = "/terrainToSem", produces = "application/json; charset=UTF-8")
+    public R<String> terrainToSem(@RequestBody List<GridDto> dtos,String semUrl) throws Exception {
+        long times = System.currentTimeMillis();
+        String path = outPath + "\\terrain\\" + times + "\\";
+        File dirFile = new File(path + "appearance");
+        if (!dirFile.exists()) {
+            dirFile.mkdirs();
+        }
+        double minx = 180.0;
+        double maxx = 0.0;
+        double miny = 180.0;
+        double maxy = 0.0;
+        for (GridDto dto : dtos
+        ) {
+            if (dto.getLon() > maxx) {
+                maxx = dto.getLon();
+            }
+            if (dto.getLon() < minx) {
+                minx = dto.getLon();
+            }
+            if (dto.getLat() > maxy) {
+                maxy = dto.getLat();
+            }
+            if (dto.getLat() < miny) {
+                miny = dto.getLat();
+            }
+        }
+        JSONArray min = ProjectionToGeographicUtil.get4548Point(minx, miny);
+        JSONArray max = ProjectionToGeographicUtil.get4548Point(maxx, maxy);
+        String tifPath = path + "terrain.tif";
+        TiffClipper.cropTiffByLatLon(config.getTifPath(), tifPath, min.getDouble(0), min.getDouble(1), max.getDouble(0), max.getDouble(1));
+        String pngPath = path + "appearance\\terrain.png";
+        TiffToRGBUtil.tifToPng(tifPath, pngPath);
+        JSONObject jsonObject = getModule("terrainmodule.json");
+        jsonObject.put("vertices", TiffCoordinateExtractorUtil.getCoordinate(tifPath));
+        FileWriter fileWriter = new FileWriter(path + "terrain.json");
+        fileWriter.write(jsonObject.toJSONString());
+        fileWriter.close();
+        SemUtils.cityJsonToSem(path + "terrain.json", semUrl + "terrain.sem");
+        return success(semUrl + "terrain.sem");
+    }
+
     @ApiOperation(value = "鍦板舰杞琧ityjson")
     @GetMapping(value = "/terrainToCityJson", produces = "application/json; charset=UTF-8")
     public R<String> terrainToCityJson(@RequestParam("tifPath") String tifPath) throws Exception {
@@ -724,7 +779,7 @@
 
     @ApiOperation(value = "grid杞琧ityjson")
     @PostMapping(value = "/gridToCityJson", produces = "application/json; charset=UTF-8")
-    public R<String> gridToCityJson(@RequestBody List<GridDto> dtos) throws Exception {
+    public R<String> gridToCityJson(@RequestBody List<GridDto> dtos,String semUrl) throws Exception {
         long times = System.currentTimeMillis();
         String path = outPath + "\\grid\\" + times + "\\";
         File dirFile = new File(path);
@@ -745,18 +800,13 @@
         FileWriter fileWriter = new FileWriter(path + "grid.json");
         fileWriter.write(jsonObject.toJSONString());
         fileWriter.close();
-        String filePatn = inPath + "\\tongzhou\\";
-        File file = new File(filePatn);
-        if (!file.exists()) {
-            file.mkdirs();
-        }
-        SemUtils.cityJsonToSem(path + "grid.json", filePatn + "grid.sem");
-        return success(filePatn + "grid.sem");
+        SemUtils.cityJsonToSem(path + "grid.json", semUrl + "grid.sem");
+        return success(semUrl + "grid.sem");
     }
 
     @ApiOperation(value = "river杞瑂em")
     @GetMapping(value = "/riverToSem", produces = "application/json; charset=UTF-8")
-    public R<String> riverToSem() throws Exception {
+    public R<String> riverToSem(String semUrl) throws Exception {
         long times = System.currentTimeMillis();
         String path = outPath + "\\river\\" + times + "\\";
         File dirFile = new File(path);
@@ -767,18 +817,13 @@
         FileWriter fileWriter = new FileWriter(path + "river.json");
         fileWriter.write(jsonObject.toJSONString());
         fileWriter.close();
-        String filePatn = inPath + "\\tongzhou\\";
-        File file = new File(filePatn);
-        if (!file.exists()) {
-            file.mkdirs();
-        }
-        SemUtils.cityJsonToSem(path + "river.json", filePatn + "river.sem");
-        return success(filePatn + "river.sem");
+        SemUtils.cityJsonToSem(path + "river.json", semUrl + "river.sem");
+        return success(semUrl + "river.sem");
     }
 
     @ApiOperation(value = "landuse杞瑂em")
     @GetMapping(value = "/landuseToSem", produces = "application/json; charset=UTF-8")
-    public R<String> landuseToSem() throws Exception {
+    public R<String> landuseToSem(String semUrl) throws Exception {
         long times = System.currentTimeMillis();
         String path = outPath + "\\landuse\\" + times + "\\";
         File dirFile = new File(path);
@@ -789,13 +834,8 @@
         FileWriter fileWriter = new FileWriter(path + "landuse.json");
         fileWriter.write(jsonObject.toJSONString());
         fileWriter.close();
-        String filePatn = inPath + "\\tongzhou\\";
-        File file = new File(filePatn);
-        if (!file.exists()) {
-            file.mkdirs();
-        }
-        SemUtils.cityJsonToSem(path + "landuse.json", filePatn + "landuse.sem");
-        return success(filePatn + "landuse.sem");
+        SemUtils.cityJsonToSem(path + "landuse.json", semUrl + "landuse.sem");
+        return success(semUrl + "landuse.sem");
     }
 
     public JSONObject getModule(String moduleName) {

--
Gitblit v1.9.3