张洋洋
2025-01-10 f851dbe9fba3ff30605039b0cb1f69892e3483d0
[add]转化zarr文件
已添加1个文件
已修改3个文件
已删除1个文件
206 ■■■■■ 文件已修改
pom.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/controller/SimuController.java 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/utils/CsvToSQLiteUtils.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/cityjson.json 132 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/rainfallmodule.json 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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>
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+"的zarr数据生成=====================");
            ZarrUtils.saveZarrRainfall(basePath + src, stationRainVos);
            ZarrUtils.saveZarrTime(basePath + src, stationRainVos);
            ZipUtils.toZarr(basePath + src, basePath + src + ".zip");
            System.out.println(src + "的zarr数据生成=====================");
            //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;
    }
}
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();
src/main/resources/cityjson.json
ÎļþÒÑɾ³ý
src/main/resources/rainfallmodule.json
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1 @@
{"type":"CityJSON","version":"1.0","Dynamizers":[],"CityObjects":{},"vertices":[]}