wuww
2025-05-06 378a66a369b27ba35dc1d4d1cbddd90b626d7046
src/main/java/com/se/nsl/service/TestService.java
@@ -6,6 +6,7 @@
import com.se.nsl.domain.dto.*;
import com.se.nsl.domain.po.DataPo;
import com.se.nsl.domain.po.PondingPo;
import com.se.nsl.domain.po.SimuData;
import com.se.nsl.domain.vo.BuildingDepthVo;
import com.se.nsl.helper.ComHelper;
import com.se.nsl.helper.GdalHelper;
@@ -45,9 +46,26 @@
    @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");
    public void test(SimuData data) throws Exception {
        String basePath = config.getInPath() + File.separator + data.getInPath() + File.separator;
        ResultDto dto = new ResultDto(
                data.getInPath(),
                basePath + config.getTerrainFile(),
                basePath + config.getBuildingFile(),
                basePath + config.getWaterPath(),
                basePath + config.getFlowPath(),
                config.getInPath(),
                config.getOutPath(),
                data.getEpsg());
        LayerDto layer = new LayerDto(config.getVer(), data.getEpsg(), config.getSizes());
        process(dto, layer);
    }
    public void test(DataPo data) throws Exception {
        String basePath = config.getInPath() + File.separator + data.getInPath() + File.separator;
@@ -89,8 +107,8 @@
            if (null == ds || 0 == ds.getRasterCount()) return;
            setTerrainInfo(ds, layer);
            createTerrainPng(dto, ds, layer);
            setWaterInfo(dto, layer);
            createTerrainPng(dto, ds, layer);
        } finally {
            if (null != ds) ds.delete();
        }
@@ -238,8 +256,8 @@
            }
        });*/
        int c = files.size();
        int step = c <= 1 ? 1 : c / 10;
        int c = files.size(), step = files.size() / 10;
        if (step < 1) step = 1;
        for (int i = 0; i < c; i += step) {
            Dataset ds = null;
            try {
@@ -254,7 +272,7 @@
            }
        }
        layer.getExtension().setMaxHeight(layer.getExtension().getMaxHeight() + layer.getWaters().getMaxHeight());
        layer.getExtension().setMaxHeight(layer.getExtension().getMaxHeight() + layer.getWaters().getMaxHeight() + 1);
        layer.getExtension().setMaxHeight(ComHelper.getMaxVal(layer.getExtension().getMaxHeight(), 1000000));
        layer.getExtension().setMinHeight(ComHelper.getMaxVal(layer.getExtension().getMinHeight(), 1000000));
        layer.getExtension().setDiffer();
@@ -270,7 +288,7 @@
                createWaterPng(dto, ds, layer, layer.getWaters().getData().get(i));
                //if (config.getCopyTif()) copyWaterTif(dto, ds, layer.getWaters().getData().get(i));
                createVectors(dto, ds, layer, layer.getWaters().getData().get(i));
                ///createVectors(dto, ds, layer, layer.getWaters().getData().get(i));
            } finally {
                if (null != ds) ds.delete();
            }
@@ -285,7 +303,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 +321,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 +331,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.001 || 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];
@@ -324,6 +343,7 @@
                        g = b = 255;
                    } else {
                        int val = (int) ((buffer[offset] + ts[offset] - minHeight) / differ * 65535);
                        //int val = (int) (buffer[offset] / differ * 65535);
                        g = val / 256;
                        b = val % 256;
                    }
@@ -336,6 +356,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) {
@@ -540,7 +620,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 && fy == 0)) 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;
@@ -561,8 +641,10 @@
        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");
        String path = dto.getOutPath().replace(config.getOutPath() + File.separator, "");
        layer.setWaterUrl("/hls/w" + path + ".m3u8");
        layer.setFlowUrl("/hls/f" + path + ".m3u8");
        String json = JSON.toJSONString(layer);
        // String json = JSONUtil.toJsonPrettyStr(layer);