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文件

---
 /dev/null                                                |  132 ---------------------------------
 src/main/resources/rainfallmodule.json                   |    1 
 src/main/java/com/se/simu/utils/CsvToSQLiteUtils.java    |    2 
 pom.xml                                                  |    1 
 src/main/java/com/se/simu/controller/SimuController.java |   70 +++++++++++++++-
 5 files changed, 66 insertions(+), 140 deletions(-)

diff --git a/pom.xml b/pom.xml
index abb5d58..a5430dd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -282,6 +282,7 @@
                     <include>win32-x86-64/blosc.dll</include>
                     <include>**/*.yml</include>
                     <include>**/*.xml</include>
+                    <include>**/*.json</include>
                 </includes>
                 <filtering>false</filtering>
             </resource>
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;
+    }
+
 }
diff --git a/src/main/java/com/se/simu/utils/CsvToSQLiteUtils.java b/src/main/java/com/se/simu/utils/CsvToSQLiteUtils.java
index 94c8c5e..46d9e63 100644
--- a/src/main/java/com/se/simu/utils/CsvToSQLiteUtils.java
+++ b/src/main/java/com/se/simu/utils/CsvToSQLiteUtils.java
@@ -345,7 +345,7 @@
         try (Connection conn = DriverManager.getConnection("jdbc:sqlite:rainfall.db")) {
             if (conn != null) {
                 // 2. 鎵цSQL鏌ヨ
-                String queryDataSql = "SELECT * FROM " + tableName + " WHERE station_name='" + name + "' ORDER BY datetime asc";
+                String queryDataSql = "SELECT * FROM " + tableName + " WHERE station_name='" + name + "' ORDER BY id asc";
                 // 3. 澶勭悊鏌ヨ缁撴灉
                 try (PreparedStatement pstmt = conn.prepareStatement(queryDataSql)) {
                     ResultSet rs = pstmt.executeQuery();
diff --git a/src/main/resources/cityjson.json b/src/main/resources/cityjson.json
deleted file mode 100644
index 7b2915e..0000000
--- a/src/main/resources/cityjson.json
+++ /dev/null
@@ -1,132 +0,0 @@
-{
-  "type": "CityJSON_Extension",
-  "name": "PipeLine",
-  "uri": "http://www.smartearth.cn/extension.schema. PipeLine.json",
-  "version": "1.0.0",
-  "description": "Extension for PipeLine model",
-  "extraCityObjects": {
-    "+PipeLine": {
-      "allOf": [
-        {
-          "$ref": "../cityobjects.schema.json#/_AbstractCityObject"
-        },
-        {
-          "properties": {
-            "type": {
-              "enum": [
-                "+PipeLine"
-              ]
-            },
-            "topLevel": {
-              "type": "boolean"
-            },
-            "attributes": {
-              "type": "object",
-              "properties": {
-                "function": {
-                  "type": "string"
-                },
-                "bs": {
-                  "type": "object",
-                  "description": "鏍囪瘑",
-                  "properties": {
-                    "qqwybs": {
-                      "type": "string",
-                      "description": "鍏ㄧ悆鍞竴缂栫爜"
-                    },
-                    "hydm": {
-                      "type": "string",
-                      "description": "琛屼笟浠g爜"
-                    },
-                    "fldm": {
-                      "type": "string",
-                      "description": "鍒嗙被浠g爜"
-                    },
-                    "mc": {
-                      "type": "string",
-                      "description": "鍚嶇О"
-                    }
-                  }
-                },
-                "zt": {
-                  "type": "object",
-                  "description": "鐘舵��",
-                  "properties": {
-                    "ztgb": {
-                      "type": "string",
-                      "description": "鐘舵�佹敼鍙�"
-                    }
-                  }
-                },
-                "sk": {
-                  "type": "object",
-                  "description": "鏃剁┖",
-                  "properties": {
-                    "cssj": {
-                      "type": "string",
-                      "description": "浜х敓鏃堕棿"
-                    },
-                    "gxsj": {
-                      "type": "string",
-                      "description": "鏇存柊鏃堕棿"
-                    },
-                    "xwsj": {
-                      "type": "string",
-                      "description": "娑堜骸鏃堕棿"
-                    }
-                  }
-                },
-                "ssxzq": {
-                  "type": "string",
-                  "description": "鎵�灞炶鏀垮尯鍩�"
-                }
-              }
-            },
-            "children": {
-              "type": "array",
-              "items": {
-                "type": "string"
-              }
-            },
-            "geometry": {
-              "type": "array",
-              "items": {
-                "oneOf": [
-                  {
-                    "$ref": "geomprimitives.schema.json#/MultiPoint"
-                  },
-                  {
-                    "$ref": "geomprimitives.schema.json#/MultiLineString"
-                  },
-                  {
-                    "$ref": "geomprimitives.schema.json#/MultiSurface"
-                  },
-                  {
-                    "$ref": "geomprimitives.schema.json#/CompositeSurface"
-                  },
-                  {
-                    "$ref": "geomprimitives.schema.json#/Solid"
-                  },
-                  {
-                    "$ref": "geomprimitives.schema.json#/CompositeSolid"
-                  },
-                  {
-                    "$ref": "geomprimitives.schema.json#/MultiSolid"
-                  },
-                  {
-                    "$ref": "geomtemplates.schema.json#/GeometryInstance"
-                  }
-                ]
-              }
-            }
-          },
-          "required": [
-            "type",
-            "topLevel",
-            "geometry"
-          ]
-        }
-      ]
-    }
-  }
-}
\ No newline at end of file
diff --git a/src/main/resources/rainfallmodule.json b/src/main/resources/rainfallmodule.json
new file mode 100644
index 0000000..f3b7363
--- /dev/null
+++ b/src/main/resources/rainfallmodule.json
@@ -0,0 +1 @@
+{"type":"CityJSON","version":"1.0","Dynamizers":[],"CityObjects":{},"vertices":[]}
\ No newline at end of file

--
Gitblit v1.9.3