dcb
2025-06-19 68372fd1905515c5c8dbb9e3b158241994439e06
src/main/java/com/se/nsl/service/ResultService.java
@@ -40,7 +40,7 @@
    public final static double MAX_X_OFFSET = 0;
    private final static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    public final static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    public void process(DataPo data) throws Exception {
        String basePath = config.getInPath() + File.separator + data.getInPath() + File.separator;
@@ -57,7 +57,7 @@
        process(dto, layer);
    }
    private void process(ResultDto dto, LayerDto layer) throws Exception {
    public void process(ResultDto dto, LayerDto layer) throws Exception {
        try {
            copeTerrain(dto, layer);
            copeBuilding(dto, layer);
@@ -74,7 +74,7 @@
        }
    }
    private void copeTerrain(ResultDto dto, LayerDto layer) {
    public void copeTerrain(ResultDto dto, LayerDto layer) {
        Dataset ds = null;
        try {
            ds = gdal.Open(dto.getTerrainFile(), gdalconst.GA_ReadOnly);
@@ -88,7 +88,7 @@
        }
    }
    private void setTerrainInfo(Dataset ds, LayerDto layer) {
    public void setTerrainInfo(Dataset ds, LayerDto layer) {
        Geometry minPoint = GdalHelper.getMinPoint(ds);
        Geometry maxPoint = GdalHelper.getMaxPoint(ds);
        double minx = ComHelper.getMinVal(minPoint.GetX(0), 10000000);
@@ -104,14 +104,14 @@
        layer.setExtension(new ExtensionDto(minx, miny, maxx, maxy, mm[0], mm[1]));
    }
    private void createTerrainPng(ResultDto dto, Dataset ds, LayerDto layer) {
    public void createTerrainPng(ResultDto dto, Dataset ds, LayerDto layer) {
        String terrainPath = dto.getOutPath() + File.separator + "terrain";
        File f = new File(terrainPath);
        if (!f.exists() || !f.isDirectory()) f.mkdirs();
        for (int[] sizes : layer.getTerrain().getSize()) {
            String tif = dto.getTemp() + File.separator + "terrain_" + sizes[0] + "_" + sizes[1] + ".tif";
            ComHelper.Resample(ds, tif, sizes[0], sizes[1], layer);
            ComHelper.cutAndResample(ds, tif, sizes[0], sizes[1], layer, false);
            if (!new File(tif).exists()) continue;
            String png = terrainPath + File.separator + sizes[0] + "_" + sizes[1] + ".png";
@@ -119,7 +119,7 @@
        }
    }
    private void Terrain2Png(LayerDto layer, String tif, String png, int width, int height) {
    public void Terrain2Png(LayerDto layer, String tif, String png, int width, int height) {
        Dataset ds = null;
        try {
            ds = gdal.Open(tif, gdalconst.GA_ReadOnly);
@@ -158,7 +158,7 @@
        }
    }
    private void copeBuilding(ResultDto dto, LayerDto layer) {
    public void copeBuilding(ResultDto dto, LayerDto layer) {
        Driver driver = null;
        DataSource dataSource = null;
        Layer shpLayer = null;
@@ -187,7 +187,7 @@
        }
    }
    private void setWaterInfo(ResultDto dto, LayerDto layer) {
    public void setWaterInfo(ResultDto dto, LayerDto layer) {
        List<String> files = getFiles(dto.getWaterPath(), ".tif");
        layer.getWaters().setFiles(files);
        if (null == files || files.size() == 0) return;
@@ -196,7 +196,7 @@
        setWaterHeight(layer, files);
    }
    private List<BuildingDepthVo> copeWater(ResultDto dto, LayerDto layer) {
    public List<BuildingDepthVo> copeWater(ResultDto dto, LayerDto layer) {
        List<String> files = layer.getWaters().getFiles();
        if (files.size() == 0 || files.size() != layer.getWaters().getData().size()) return null;
@@ -205,7 +205,7 @@
        return processBuilding(dto, files, layer);
    }
    private List<String> getFiles(String path, String suffix) {
    public List<String> getFiles(String path, String suffix) {
        List<String> files = new ArrayList<>();
        ComHelper.getFiles(files, new File(path), suffix);
        files.sort((a, b) -> a.compareToIgnoreCase(b));
@@ -213,7 +213,7 @@
        return files;
    }
    private void setWaterData(LayerDto layer, List<String> files) {
    public void setWaterData(LayerDto layer, List<String> files) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.MILLISECOND, 0);
@@ -240,7 +240,7 @@
        layer.getDuration().setEnd(layer.getWaters().getData().get(layer.getWaters().getData().size() - 1));
    }
    private void setWaterHeight(LayerDto layer, List<String> files) {
    public void setWaterHeight(LayerDto layer, List<String> files) {
        files.parallelStream().forEach(file -> {
            Dataset ds = null;
            try {
@@ -265,7 +265,7 @@
        layer.getExtension().setDiffer();
    }
    private void processWaters(ResultDto dto, List<String> files, LayerDto layer) {
    public void processWaters(ResultDto dto, List<String> files, LayerDto layer) {
        for (int i = 0, c = files.size(); i < c; i++) {
            Dataset ds = null;
            try {
@@ -282,7 +282,7 @@
        }
    }
    private void createWaterPng(ResultDto dto, Dataset ds, LayerDto layer, long ticks) {
    public void createWaterPng(ResultDto dto, Dataset ds, LayerDto layer, long ticks) {
        String waterPath = dto.getOutPath() + File.separator + "waters" + File.separator + ticks;
        File dir = new File(waterPath);
        if (!dir.exists() || !dir.isDirectory()) dir.mkdirs();
@@ -290,7 +290,7 @@
        for (int[] sizes : layer.getTerrain().getSize()) {
            String fileName = ComHelper.getNameWithExt(ds.GetDescription()) + "_" + sizes[0] + "_" + sizes[1];
            String tif = dto.getTemp() + File.separator + fileName + ".tif";
            ComHelper.Resample(ds, tif, sizes[0], sizes[1], layer);
            ComHelper.cutAndResample(ds, tif, sizes[0], sizes[1], layer, false);
            if (!new File(tif).exists()) continue;
            String png = waterPath + File.separator + sizes[0] + "_" + sizes[1] + ".png";
@@ -298,7 +298,7 @@
        }
    }
    private void water2Png(ResultDto dto, LayerDto layer, String tif, String png, int width, int height) {
    public void water2Png(ResultDto dto, LayerDto layer, String tif, String png, int width, int height) {
        Dataset ds = null;
        try {
            ds = gdal.Open(tif, gdalconst.GA_ReadOnly);
@@ -343,7 +343,7 @@
        }
    }
    private List<BuildingDepthVo> processBuilding(ResultDto dto, List<String> files, LayerDto layer) {
    public List<BuildingDepthVo> processBuilding(ResultDto dto, List<String> files, LayerDto layer) {
        List<BuildingDepthVo> list = new CopyOnWriteArrayList<>();
        for (int i = 0, c = files.size(); i < c; i++) {
            Dataset ds = null;
@@ -361,7 +361,7 @@
        return list;
    }
    private void copeBuildingDepth(ResultDto dto, Dataset ds, long ticks, List<BuildingDepthVo> list) {
    public void copeBuildingDepth(ResultDto dto, Dataset ds, long ticks, List<BuildingDepthVo> list) {
        double[] transform = ds.GetGeoTransform();
        int xSize = ds.getRasterXSize(), ySize = ds.getRasterYSize();
        double minX = transform[0], pixelWidth = transform[1], maxY = transform[3], pixelHeight = Math.abs(transform[5]);
@@ -372,7 +372,7 @@
        }
    }
    private Double getValue(Dataset ds, BuildingDto building, int xSize, int ySize, double minX, double maxY, double pixelWidth, double pixelHeight) {
    public Double getValue(Dataset ds, BuildingDto building, int xSize, int ySize, double minX, double maxY, double pixelWidth, double pixelHeight) {
        double[] env = new double[4];
        building.getGeom().GetEnvelope(env);
@@ -396,13 +396,13 @@
        return ComHelper.isValid(val) ? val : null;
    }
    private void copyWaterTif(ResultDto dto, Dataset ds, long ticks) {
    public void copyWaterTif(ResultDto dto, Dataset ds, long ticks) {
        String source = ds.GetDescription();
        String target = dto.getOutPath() + File.separator + "waters" + File.separator + ticks + File.separator + "water.tif";
        FileUtil.copyFile(source, target);
    }
    private void createVectors(ResultDto dto, Dataset ds, LayerDto layer, Long ticks) {
    public void createVectors(ResultDto dto, Dataset ds, LayerDto layer, Long ticks) {
        String filePath = dto.getOutPath() + File.separator + "waters" + File.separator + ticks + File.separator + "polygonize.geojson";
        ShpHelper.polygonize2Geojson(ds, filePath);
@@ -420,7 +420,7 @@
        }
    }
    private List<Geometry> getGeometries(String filePath) {
    public List<Geometry> getGeometries(String filePath) {
        if (!FileUtil.exist(filePath)) return null;
        Driver driver = null;
@@ -451,7 +451,7 @@
        }
    }
    private List<PondingPo> copePonding(ResultDto dto, Dataset ds, LayerDto layer, List<Geometry> geometries) {
    public List<PondingPo> copePonding(ResultDto dto, Dataset ds, LayerDto layer, List<Geometry> geometries) {
        double[] transform = ds.GetGeoTransform();
        int xSize = ds.getRasterXSize(), ySize = ds.getRasterYSize();
@@ -470,7 +470,7 @@
        return list;
    }
    private PointDto getValues(Dataset ds, Geometry g, double[] transform, int xSize, int ySize) {
    public PointDto getValues(Dataset ds, Geometry g, double[] transform, int xSize, int ySize) {
        double[] env = new double[4];
        g.GetEnvelope(env);
@@ -494,7 +494,7 @@
        return new PointDto(g.Centroid().GetX(), g.Centroid().GetY(), ComHelper.isValid(val) ? val : 0.0);
    }
    private void copeFlow(ResultDto dto, LayerDto layer) {
    public void copeFlow(ResultDto dto, LayerDto layer) {
        List<String> files = getFiles(dto.getFlowPath(), ".tif");
        if (null == files || files.size() != layer.getWaters().getData().size()) return;
@@ -512,7 +512,7 @@
        }
    }
    private void createFlowPng(ResultDto dto, Dataset ds, LayerDto layer, long ticks) {
    public void createFlowPng(ResultDto dto, Dataset ds, LayerDto layer, long ticks) {
        String flowPath = dto.getOutPath() + File.separator + "flows" + File.separator + ticks;
        File dir = new File(flowPath);
        if (!dir.exists() || !dir.isDirectory()) dir.mkdirs();
@@ -520,7 +520,7 @@
        for (int[] sizes : layer.getTerrain().getSize()) {
            String name = ComHelper.getNameWithExt(ds.GetDescription()) + "_" + sizes[0] + "_" + sizes[1];
            String tif = dto.getTemp() + File.separator + name + ".tif";
            ComHelper.Resample(ds, tif, sizes[0], sizes[1], layer);
            ComHelper.cutAndResample(ds, tif, sizes[0], sizes[1], layer, false);
            if (!new File(tif).exists()) continue;
            String png = flowPath + File.separator + sizes[0] + "_" + sizes[1] + ".png";
@@ -528,7 +528,7 @@
        }
    }
    private void vxyTif2Png(LayerDto layer, String tif, String png, int width, int height) {
    public void vxyTif2Png(LayerDto layer, String tif, String png, int width, int height) {
        Dataset ds = null;
        try {
            ds = gdal.Open(tif, gdalconst.GA_ReadOnly);
@@ -544,7 +544,7 @@
        }
    }
    private void createFlowPng(float[] vxBuffer, float[] vyBuffer, String png, int width, int height) {
    public void createFlowPng(float[] vxBuffer, float[] vyBuffer, String png, int width, int height) {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
@@ -568,7 +568,7 @@
        ComHelper.savePng(image, png);
    }
    private void copeLayerJson(ResultDto dto, LayerDto layer) throws IOException {
    public void copeLayerJson(ResultDto dto, LayerDto layer) throws IOException {
        layer.getWaters().setFiles(null);
        layer.getTerrain().setEpsg(null);
        layer.getExtension().setDiffer(null);
@@ -604,7 +604,7 @@
        ComHelper.writeJson(filePath, json);
    }
    private void copeBuildingDepthJson(ResultDto dto, List<BuildingDepthVo> list) throws IOException {
    public void copeBuildingDepthJson(ResultDto dto, List<BuildingDepthVo> list) throws IOException {
        if (CollectionUtils.isEmpty(list)) return;
        String json = JSON.toJSONString(list);