张洋洋
2025-01-10 a28eb2cb2abdd3f27075ca8468cf1a2bbf7de3cf
src/main/java/com/se/simu/controller/SimuController.java
@@ -8,13 +8,12 @@
import com.se.simu.domain.dto.GeLayer;
import com.se.simu.domain.po.DataPo;
import com.se.simu.domain.po.SimuPo;
import com.se.simu.domain.vo.CreateFilesSimuVo;
import com.se.simu.domain.vo.CreateSimuVo;
import com.se.simu.domain.vo.R;
import com.se.simu.domain.vo.SimuVo;
import com.se.simu.domain.vo.*;
import com.se.simu.service.*;
import com.se.simu.utils.CsvToSQLiteUtils;
import com.se.simu.utils.ShpToolUtils;
import com.se.simu.utils.ZarrUtils;
import com.se.simu.utils.ZipUtils;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@@ -22,11 +21,9 @@
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.*;
@Api(tags = "仿真管理")
@Slf4j
@@ -213,35 +210,40 @@
        String floodFile = vo.getFloodFile();
        log.info("范围文件地址:{}", floodFile);
        try {
            // 判断地址不为空
            if (StringUtils.isEmpty(floodFile)) {
                return fail("范围文件地址不能为空", false);
            } else {
                // 获取文件的后缀名
                String fileName = floodFile.substring(floodFile.lastIndexOf("."));
                // 判断后缀名是否为.shp
                if (!fileName.equalsIgnoreCase(".shp")) {
                    return fail("范围文件格式不正确", false);
            // 判断是否绘制区域
            if (!StringUtils.isEmpty(vo.getMaxx().toString()) && !Objects.isNull(vo.getMaxx())) {
                rangeVerify(vo.getMinx(), vo.getMaxx(), vo.getMiny(), vo.getMaxy());
                log.info("绘制区域范围验证通过!");
            } else
                // 判断地址不为空
                if (StringUtils.isEmpty(floodFile)) {
                    return fail("范围文件地址不能为空", false);
                } else {
                    // 1 读取shp文件,获取范围值
                    JSONObject jsonObject = ShpToolUtils.readShp(floodFile);
                    // 2 获取jsonObject中的范围值
                    Double minX = jsonObject.getDouble("minY");
                    Double maxX = jsonObject.getDouble("maxY");
                    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"));
                    vo.setMaxy(jsonObject.getDouble("maxX"));
                    rangeVerify(minX,maxX, minY, maxY);
                    // 获取文件的后缀名
                    String fileName = floodFile.substring(floodFile.lastIndexOf("."));
                    // 判断后缀名是否为.shp
                    if (!fileName.equalsIgnoreCase(".shp")) {
                        return fail("范围文件格式不正确", false);
                    } else {
                        // 1 读取shp文件,获取范围值
                        JSONObject jsonObject = ShpToolUtils.readShp(floodFile);
                        // 2 获取jsonObject中的范围值
                        Double minX = jsonObject.getDouble("minY");
                        Double maxX = jsonObject.getDouble("maxY");
                        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"));
                        vo.setMaxy(jsonObject.getDouble("maxX"));
                        rangeVerify(minX, maxX, minY, maxY);
                    }
                }
            }
            // todo: 解析范围文件 根据不同的的格式文件进行不同的解析,获取需要计算的范围值
            //  上传格式:.shp/.tiff/.img/.geojson
            //  重新给vo赋值
@@ -251,7 +253,7 @@
                return fail("解析范围文件失败!选择范围不能为空,请重新选择文件!", false);
            }
        }
        JSONArray jsonArray = new JSONArray();
        String stationFile = vo.getStationFile();
        log.info("站点文件shp地址:{}", stationFile);
        try {
@@ -260,7 +262,7 @@
                return fail("站点文件shp地址不能为空", false);
            }
            // 1 读取shp文件,获取站点坐标值
            JSONArray jsonArray = ShpToolUtils.readShpGetLocal(stationFile);
            jsonArray = ShpToolUtils.readShpGetLocal(stationFile);
            System.out.println("jsonArray = " + jsonArray);
        } catch (Exception e) {
            log.error("解析站点文件shp失败");
@@ -268,15 +270,16 @@
        String stationRainFile = vo.getStationRainFile();
        log.info("站点雨量CSV文件地址:{}", floodFile);
        JSONArray array = new JSONArray();
        // 创建表名 时间戳
        String tableName = "station_rain_" + System.currentTimeMillis();
        try {
            // 判断地址不为空
            if (StringUtils.isEmpty(stationRainFile)) {
                return fail("站点雨量CSV文件地址不能为空", false);
            }
            // 创建表名 时间戳
            String tableName = "station_rain_" + System.currentTimeMillis();
            // 1 读取CSV 文件
            CsvToSQLiteUtils.readCsvSaveLocal(stationRainFile, tableName);
            array = CsvToSQLiteUtils.readCsvSaveLocal(stationRainFile, tableName);
            // 获取仿真时间 duration
            Integer duration = CsvToSQLiteUtils.getDuration(tableName);
            log.info("仿真时间 duration = {}", duration);
@@ -326,6 +329,10 @@
                    return fail("防汛范围不能为空", false);
                }
            }
            //todo 组装cityjson
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("shp", jsonArray);
            jsonObject.put("csv", array);
            // 开始模拟计算
            boolean flag = simuFilesService.createByfiles(vo);
            return success(flag, flag ? "成功" : "失败");
@@ -334,5 +341,27 @@
        }
    }
    @ApiOperation(value = "tarr文件组装")
    @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\\";
        for (String src : list
        ) {
            File directories = new File(basePath);
            if (!directories.exists()) {
                directories.mkdirs();
                System.out.println("Directories created successfully.");
            } else {
                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数据生成=====================");
        }
        return success(true);
    }
}