wuww
2025-04-30 1cae540cd2b99803808d31a3a5dd35e3216f19c7
插值处理-四邻域
已添加1个文件
已修改7个文件
219 ■■■■■ 文件已修改
data/ai.backup 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/nsl/controller/TestController.java 51 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/nsl/domain/po/Rainfall.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/nsl/domain/po/SimuData.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/nsl/helper/ComHelper.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/nsl/helper/GdalHelper.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/nsl/service/TestService.java 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-dev.yml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data/ai.backup
Binary files differ
src/main/java/com/se/nsl/controller/TestController.java
@@ -175,24 +175,34 @@
    @ApiOperation(value = "04.testPngList <")
    @GetMapping("/testPngList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query", example = "D:\\other\\simu\\out\\chicago\\waters"),
            @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query", example = "D:\\other\\simu\\out\\fs24cubic"),
            @ApiImplicitParam(name = "size", value = "尺寸", dataType = "Integer", paramType = "query", example = "1024")
    })
    public R<Object> testPngList(String path, Integer size) {
        try {
            if (null == size) size = (Integer) 1024;
            String newPath = config.getOutPath() + File.separator + path + File.separator + "waters";
            String pngPath = config.getOutPath() + File.separator + path + File.separator + "png";
            if (!new File(pngPath).exists()) new File(pngPath).mkdirs();
            int i = 1;
            List<String> list = new ArrayList<>();
            for (File file : new File(path).listFiles()) {
            for (File file : new File(newPath).listFiles()) {
                if (!file.exists() || file.isFile()) continue;
                File pngFile = new File(file.getPath() + File.separator + size + "_" + size + ".png");
                if (!pngFile.exists() || pngFile.isDirectory()) continue;
                list.add("file '" + pngFile.getPath().replace("\\", "/") + "'");
                String pngName = i + ".png"; // String.format("f%06d", i)
                Files.copy(pngFile.toPath(), Paths.get(pngPath + File.separator + pngName), StandardCopyOption.REPLACE_EXISTING);
                list.add("file '" + pngName + "'");
                System.out.println(list.get(list.size() - 1));
                i++;
            }
            Path outPath = Paths.get(path + File.separator + "list.txt");
            Path outPath = Paths.get(pngPath + File.separator + "list.txt");
            try {
                Files.write(outPath, list, StandardCharsets.UTF_8);
            } catch (IOException e) {
@@ -232,7 +242,7 @@
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tifPath", value = "Tif路径", dataType = "String", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago"),
            @ApiImplicitParam(name = "inPath", value = "输入路径", dataType = "String", paramType = "query", example = "20250425"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "Integer", paramType = "query", example = "2025-04-25 00:00:00"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "Integer", paramType = "query", example = "2025-04-29 00:00:00"),
            @ApiImplicitParam(name = "epsg", value = "坐标系ID", dataType = "Integer", paramType = "query", example = "4548")
    })
    public R<Object> testCreateNsl(String tifPath, String inPath, String startTime, Integer epsg) {
@@ -242,7 +252,7 @@
            data.setStartTime(StringHelper.YMDHMS_FORMAT.parse(startTime));
            data.setEpsg(epsg);
            procTifs(tifPath, data.getStartTime());
            procTifs(tifPath, inPath, data.getStartTime());
            testService.test(data);
            return success("ok");
@@ -251,13 +261,15 @@
        }
    }
    private void procTifs(String tifPath, Date startTime) {
    private void procTifs(String tifPath, String inPath, Date startTime) {
        if (StringUtils.isEmpty(tifPath)) return;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(startTime.getYear() - 1900, startTime.getMonth() - 1, startTime.getDay(), 0, 0, 0));
        //calendar.setTime(new Date(startTime.getYear() - 1900, startTime.getMonth() - 1, startTime.getDay(), 0, 0, 0));
        calendar.setTime(startTime);
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        String newPath = config.getInPath() + File.separator + "depth";
        String newPath = config.getInPath() + File.separator + inPath + File.separator + "depth";
        if (!new File(newPath).exists()) new File(newPath).mkdirs();
        for (File file : new File(tifPath).listFiles()) {
            if (!file.exists() || !file.isDirectory()) continue;
@@ -275,6 +287,27 @@
        }
    }
    @ApiOperation(value = "11.renametifs <")
    @GetMapping("/renametifs")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "path", value = "路径", dataType = "String", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago\\depth"),
            @ApiImplicitParam(name = "prefix", value = "前缀", dataType = "Integer", paramType = "query", example = "01250302"),
            @ApiImplicitParam(name = "newPrefix", value = "新前缀", dataType = "Integer", paramType = "query", example = "20250429")
    })
    public R<Object> renametifs(String path, String prefix, String newPrefix) {
        try {
            File[] files = new File(path).listFiles();
            for (File file : files) {
                String newName = file.getPath().replace(prefix, newPrefix);
                file.renameTo(new File(newName));
            }
            return success("ok");
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
    @ApiOperation(value = "10.当前时间 *")
    @GetMapping("/getTime")
    public Object getTime() {
src/main/java/com/se/nsl/domain/po/Rainfall.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,54 @@
package com.se.nsl.domain.po;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
@SuppressWarnings("ALL")
public class Rainfall {
    @ApiModelProperty("时间(yyyy-MM-dd HH:mm:ss)")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date time;
    @ApiModelProperty("雨强(mm/h)")
    private Double intensity;
    @ApiModelProperty("累计雨量(mm)")
    private Double total;
    public Rainfall() {
    }
    public Rainfall(Date time, Double intensity, Double total) {
        this.time = time;
        this.intensity = intensity;
        this.total = total;
    }
    public Date getTime() {
        return time;
    }
    public void setTime(Date time) {
        this.time = time;
    }
    public Double getIntensity() {
        return intensity;
    }
    public void setIntensity(Double intensity) {
        this.intensity = intensity;
    }
    public Double getTotal() {
        return total;
    }
    public void setTotal(Double total) {
        this.total = total;
    }
}
src/main/java/com/se/nsl/domain/po/SimuData.java
@@ -65,6 +65,9 @@
    @ApiModelProperty("雨量计列表")
    private List<RainGauge> gauges;
    @ApiModelProperty("降雨列表")
    private List<Rainfall> rainfalls;
    public SimuData() {
        gauges = new ArrayList<>();
    }
src/main/java/com/se/nsl/helper/ComHelper.java
@@ -61,7 +61,33 @@
        //vector.add("-te_srs");
        //vector.add("EPSG:" + 4326);
        vector.add("-r");
        vector.add("bilinear");
        vector.add("bilinear"); // åŒçº¿æ€§æ’值
        vector.add("-of");
        vector.add("GTiff");
        WarpOptions warpOptions = new WarpOptions(vector);
        Dataset destDs = gdal.Warp(dest, new Dataset[]{ds}, warpOptions);
        destDs.delete();
    }
    public static void Resample2(Dataset ds, String dest, int width, int height, LayerDto layer) {
        Vector<String> vector = new Vector<>();
        //vector.add("-s_srs");
        //vector.add("EPSG:" + 4548);
        //vector.add("-t_srs");
        //vector.add("EPSG:" + 4326);
        vector.add("-ts");
        vector.add("" + width);
        vector.add("" + height);
        //vector.add("-te");
        //vector.add("" + layer.getExtension().getMinx());
        //vector.add("" + layer.getExtension().getMiny());
        //vector.add("" + layer.getExtension().getMaxx());
        //vector.add("" + layer.getExtension().getMaxy());
        //vector.add("-te_srs");
        //vector.add("EPSG:" + 4326);
        vector.add("-r");
        vector.add("average");
        vector.add("-of");
        vector.add("GTiff");
        WarpOptions warpOptions = new WarpOptions(vector);
src/main/java/com/se/nsl/helper/GdalHelper.java
@@ -35,7 +35,7 @@
                gdal.SetConfigOption("GDAL_HOME", gdalPath);
                gdal.SetConfigOption("GDAL_DATA", gdalPath + File.separator + "gdal-data");
                gdal.SetConfigOption("PROJ_LIB", gdalPath + File.separator + "projlib"); // /proj7/share
                gdal.SetConfigOption("GDAL_DRIVER_PATH", gdalPath + File.separator + "gdalplugins");
                //gdal.SetConfigOption("GDAL_DRIVER_PATH", gdalPath + File.separator + "gdalplugins");
                String path = System.getenv("PATH");
                if (!path.contains(gdalPath)) {
@@ -48,8 +48,8 @@
        gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
        gdal.SetConfigOption("SHAPE_ENCODING", "");
        gdal.SetConfigOption("PGEO_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s");
        gdal.SetConfigOption("MDB_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s");
        //gdal.SetConfigOption("PGEO_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s");
        //gdal.SetConfigOption("MDB_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s");
        gdal.AllRegister();
        ogr.RegisterAll();
src/main/java/com/se/nsl/service/TestService.java
@@ -45,6 +45,8 @@
    @Resource
    ResultService resultService;
    public final static double MIN_VAL = 0.00001;
    public final static double MAX_X_OFFSET = 0;
    public final static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm");
@@ -285,7 +287,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.Resample2(ds, tif, sizes[0], sizes[1], layer);
            if (!new File(tif).exists()) continue;
            String png = waterPath + File.separator + sizes[0] + "_" + sizes[1] + ".png";
@@ -303,6 +305,7 @@
            float[] buffer = new float[width * height];
            band.ReadRaster(0, 0, width, height, buffer);
            double[] transform = ds.GetGeoTransform();
            buffer = interpolateGrid(buffer, width);
            BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            //double differ = layer.getWaters().getMaxHeight() - layer.getWaters().getMinHeight(), minHeight = layer.getWaters().getMinHeight();
@@ -312,7 +315,7 @@
                for (int y = 0; y < height; y++) {
                    int offset = x + y * width;
                    //if (Float.isNaN(buffer[offset]) || buffer[offset] < -999 || buffer[offset] < minHeight) continue;
                    if (Float.isNaN(buffer[offset]) || buffer[offset] <= 0.00001 || Float.isNaN(ts[offset])) continue;
                    if (Float.isNaN(buffer[offset]) || buffer[offset] < MIN_VAL || Float.isNaN(ts[offset])) continue;
                    //double X = transform[0] + x * transform[1] + y * transform[2];
                    //double Y = transform[3] + x * transform[4] + y * transform[5];
@@ -337,6 +340,66 @@
        } finally {
            if (null != ds) ds.delete();
        }
    }
    /**
     * æ’值处理-四邻域
     */
    public float[] interpolateGrid(float[] buffer, int size) {
        float[] tempBuffer = new float[size * size];
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                int index = i * size + j;
                float current = buffer[index];
                if (current == 0) {
                    float sum = 0;
                    int count = 0;
                    // æ£€æŸ¥ä¸Šé‚»
                    if (i > 0) {
                        float neighbor = buffer[(i - 1) * size + j];
                        if (neighbor > MIN_VAL) {
                            sum += neighbor;
                            count++;
                        }
                    }
                    // æ£€æŸ¥ä¸‹é‚»
                    if (i < size - 1) {
                        float neighbor = buffer[(i + 1) * size + j];
                        if (neighbor > MIN_VAL) {
                            sum += neighbor;
                            count++;
                        }
                    }
                    // æ£€æŸ¥å·¦é‚»
                    if (j > 0) {
                        float neighbor = buffer[i * size + (j - 1)];
                        if (neighbor > MIN_VAL) {
                            sum += neighbor;
                            count++;
                        }
                    }
                    // æ£€æŸ¥å³é‚»
                    if (j < size - 1) {
                        float neighbor = buffer[i * size + (j + 1)];
                        if (neighbor > MIN_VAL) {
                            sum += neighbor;
                            count++;
                        }
                    }
                    // è®¡ç®—新值
                    if (count > 0) {
                        tempBuffer[index] = (sum / count) * 0.5f;
                    } else {
                        tempBuffer[index] = 0;
                    }
                } else {
                    tempBuffer[index] = current;
                }
            }
        }
        // å°†ä¸´æ—¶æ•°ç»„复制回原数组
        //System.arraycopy(tempBuffer, 0, buffer, 0, tempBuffer.length);
        return tempBuffer;
    }
    public List<BuildingDepthVo> processBuilding(ResultDto dto, List<String> files, LayerDto layer) {
@@ -541,7 +604,7 @@
                int offset = x + y * width;
                float fx = ComHelper.getFloatValue(vxBuffer[offset]);
                float fy = ComHelper.getFloatValue(vyBuffer[offset]);
                if (Float.isNaN(fx) && Float.isNaN(fy) || (fx == 0.00001 && fy == 0.00001)) continue;
                if (Float.isNaN(fx) && Float.isNaN(fy) || (fx < MIN_VAL && fy < MIN_VAL)) continue;
                fx = Float.isNaN(fx) ? 0 : fx;
                fy = Float.isNaN(fy) ? 0 : fy;
@@ -562,8 +625,8 @@
        layer.getWaters().setFiles(null);
        layer.getTerrain().setEpsg(null);
        layer.getExtension().setDiffer(null);
        layer.setWaterUrl("/hls/w" + config.getOutPath() + ".m3u8");
        layer.setFlowUrl("//hls/f" + config.getOutPath() + ".m3u8");
        layer.setWaterUrl("/hls/w" + dto.getOutPath() + ".m3u8");
        layer.setFlowUrl("/hls/f" + dto.getOutPath() + ".m3u8");
        String json = JSON.toJSONString(layer);
        // String json = JSONUtil.toJsonPrettyStr(layer);
src/main/resources/application-dev.yml
@@ -141,8 +141,8 @@
  flowUnits: CMS
  solverBat: D:\other\simu\uwsolver\run_solver.bat
  sww2tifBat: D:\other\simu\uwsolver\sww2tif.bat
  #sizes: 64,128,256,512,1024,2048
  sizes: 1024,2048,4096
  #sizes: 64,128,256,512,1024,2048,4096
  sizes: 1024
  # è¾“出文件
  terrainFile: DEM.tif
  buildingFile: buildings_inside.shp