From f851dbe9fba3ff30605039b0cb1f69892e3483d0 Mon Sep 17 00:00:00 2001
From: 张洋洋 <10611411+yang-yang-z@user.noreply.gitee.com>
Date: 星期五, 10 一月 2025 17:40:09 +0800
Subject: [PATCH] [add]转化zarr文件

---
 src/main/java/com/se/simu/controller/SimuController.java |   70 +++++++++++++++++++++++++++++++---
 1 files changed, 63 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/se/simu/controller/SimuController.java b/src/main/java/com/se/simu/controller/SimuController.java
index 350bc58..f461d3b 100644
--- a/src/main/java/com/se/simu/controller/SimuController.java
+++ b/src/main/java/com/se/simu/controller/SimuController.java
@@ -3,6 +3,7 @@
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.google.common.io.Resources;
 import com.se.simu.config.PropertiesConfig;
 import com.se.simu.domain.dto.GeDb;
 import com.se.simu.domain.dto.GeLayer;
@@ -18,12 +19,15 @@
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Api(tags = "浠跨湡绠$悊")
 @Slf4j
@@ -345,7 +349,10 @@
     @GetMapping(value = "/testZarr", produces = "application/json; charset=UTF-8")
     public R<Boolean> testZarr(@RequestParam("name") String tableName) throws IOException {
         List<String> list = CsvToSQLiteUtils.getNameList(tableName);
-        String basePath="D:\\鍩庡競鍐呮稘\\sem\\闆ㄩ噺绔欑偣鏁版嵁\\"+tableName+"\\rainfall\\";
+        String path = "D:\\鍩庡競鍐呮稘\\sem\\闆ㄩ噺绔欑偣鏁版嵁\\";
+        String rainfall = "rainfall\\";
+        String basePath = path + tableName + "\\" + rainfall;
+        JSONObject jsonObject = getModule("rainfallmodule.json");
         for (String src : list
         ) {
             File directories = new File(basePath);
@@ -356,12 +363,61 @@
                 System.out.println("Directories already exist.");
             }
             List<StationRainVo> stationRainVos = CsvToSQLiteUtils.getList(tableName, src);
-            ZarrUtils.saveZarrRainfall(basePath+src,stationRainVos);
-            ZarrUtils.saveZarrTime(basePath+src,stationRainVos);
-            ZipUtils.toZarr(basePath+src,basePath+src+".zip");
-            System.out.println(src+"鐨剒arr鏁版嵁鐢熸垚=====================");
+            ZarrUtils.saveZarrRainfall(basePath + src, stationRainVos);
+            ZarrUtils.saveZarrTime(basePath + src, stationRainVos);
+            ZipUtils.toZarr(basePath + src, basePath + src + ".zip");
+            System.out.println(src + "鐨剒arr鏁版嵁鐢熸垚=====================");
+            //json鎷艰
+            String uuid = "UUID_" + UUID.randomUUID().toString();
+            //鎷艰zarr
+            JSONObject dynamizer = new JSONObject();
+            dynamizer.put("url", rainfall.replace("\\","/") + src + ".zarr");
+            dynamizer.put("gmlId", uuid);
+            jsonObject.getJSONArray("Dynamizers").add(dynamizer);
+            //鎷艰鍧愭爣
+            JSONArray vertice = new JSONArray();
+            vertice.add(stationRainVos.get(0).getLongitude());
+            vertice.add(stationRainVos.get(0).getLatitude());
+            vertice.add(0.0);
+            jsonObject.getJSONArray("vertices").add(vertice);
+            //鎷艰鍩虹淇℃伅
+            JSONObject cityObject = new JSONObject();
+            cityObject.put("type", "+Rainfall");
+            JSONObject attribute = new JSONObject();
+            attribute.put("name", src);
+            cityObject.put("attributes", attribute);
+            JSONArray geometry = new JSONArray();
+            JSONObject metry = new JSONObject();
+            metry.put("type", "MultiPoint");
+            metry.put("lod", 0);
+            JSONArray boundarie = new JSONArray();
+            boundarie.add(jsonObject.getJSONArray("vertices").size());
+            metry.put("boundaries", boundarie);
+            geometry.add(metry);
+            cityObject.put("geometry", geometry);
+            jsonObject.getJSONObject("CityObjects").put(uuid, cityObject);
         }
+        File jsonFile = new File(path + tableName + "\\闄嶉洦閲�.json");
+        if (jsonFile.exists()) {
+            jsonFile.createNewFile();
+        }
+        FileWriter fileWriter = new FileWriter(path + tableName + "\\闄嶉洦閲�.json");
+        fileWriter.write(jsonObject.toJSONString());
+        fileWriter.close();
         return success(true);
     }
 
+    public JSONObject getModule(String moduleName) {
+        JSONObject jsonObject = new JSONObject();
+        try {
+            URL resource = Resources.getResource(moduleName);
+            String fileContent = Resources.toString(resource, StandardCharsets.UTF_8);
+            jsonObject = JSONObject.parseObject(fileContent);
+            System.out.println(fileContent);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return jsonObject;
+    }
+
 }

--
Gitblit v1.9.3