1
13693261870
2024-11-16 fadc4c7a796d7d8c40239a951cb00d80cdab778f
1
已添加1个文件
已修改3个文件
106 ■■■■■ 文件已修改
src/main/java/com/se/simu/domain/dto/TerrainDto.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/domain/dto/XYO.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/ResultService.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/domain/dto/TerrainDto.java
@@ -15,9 +15,13 @@
    @JSONField(serialize = false)
    private Map<String, float[]> vals;
    @JSONField(serialize = false)
    private Map<String, List<XYO>> xyo;
    public TerrainDto() {
        vals = new HashMap<>();
        size = new ArrayList<>();
        xyo = new HashMap<>();
    }
    public TerrainDto(List<Integer> sizes) {
@@ -25,6 +29,14 @@
        for (Integer i : sizes) {
            size.add(new int[]{i, i});
            /*List<XYO> list = new ArrayList<>();
            for (int x = 0; x < i; x++) {
                for (int y = 0; y < i; y++) {
                    list.add(new XYO(x, y, i));
                }
            }
            xyo.put(i + "_" + i, list);*/
        }
    }
@@ -51,4 +63,12 @@
    public void setVals(Map<String, float[]> vals) {
        this.vals = vals;
    }
    public Map<String, List<XYO>> getXyo() {
        return xyo;
    }
    public void setXyo(Map<String, List<XYO>> xyo) {
        this.xyo = xyo;
    }
}
src/main/java/com/se/simu/domain/dto/XYO.java
对比新文件
@@ -0,0 +1,43 @@
package com.se.simu.domain.dto;
@SuppressWarnings("ALL")
public class XYO {
    private int x;
    private int y;
    private int offset;
    public XYO() {
    }
    public XYO(int x, int y, int width) {
        this.x = x;
        this.y = y;
        this.offset = x + y * width;
    }
    public int getX() {
        return x;
    }
    public void setX(int x) {
        this.x = x;
    }
    public int getY() {
        return y;
    }
    public void setY(int y) {
        this.y = y;
    }
    public int getOffset() {
        return offset;
    }
    public void setOffset(int offset) {
        this.offset = offset;
    }
}
src/main/java/com/se/simu/service/ResultService.java
@@ -374,6 +374,46 @@
        return file.substring(file.lastIndexOf(File.separator) + 1, file.lastIndexOf("."));
    }
    private void water2Png2(ResultDto dto, LayerDto layer, String tif, String png, int width, int height) {
        Dataset ds = null;
        try {
            ds = gdal.Open(tif, gdalconst.GA_ReadOnly);
            if (null == ds || 0 == ds.getRasterCount()) return;
            Band band = ds.GetRasterBand(1);
            float[] buffer = new float[width * height];
            band.ReadRaster(0, 0, width, height, buffer);
            BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            double differ = layer.getExtension().getDiffer(), maxHeight = layer.getExtension().getMaxHeight(), minHeight = layer.getExtension().getMinHeight();
            float[] ts = layer.getTerrain().getVals().get(width + "_" + height);
            /*layer.getTerrain().getXyo().get(width + "_" + height).stream().forEach(xyo -> {
            });*/
            for (XYO xyo : layer.getTerrain().getXyo().get(width + "_" + height)) {
                float depth = buffer[xyo.getOffset()] + ts[xyo.getOffset()];
                if (Float.isNaN(depth) || depth < minHeight) continue;
                int r = 0, g, b;
                if (depth > maxHeight) {
                    g = b = 255;
                } else {
                    int val = (int) ((depth - minHeight) / differ * 65535);
                    g = val / 256;
                    b = val % 256;
                }
                Color color = new Color(r, g, b, 127);
                image.setRGB(xyo.getX(), xyo.getY(), color.getRGB());
            }
            savePng(image, png);
        } finally {
            if (null != ds) ds.delete();
        }
    }
    private void water2Png(ResultDto dto, LayerDto layer, String tif, String png, int width, int height) {
        Dataset ds = null;
        try {
src/main/resources/application.yml
@@ -131,6 +131,7 @@
  # 杈撳嚭鏂囦欢
  terrainFile: DEM.tif
  buildingFile: buildings_inside.shp
  buildingKey: seid
  # buildingKey: seid
  buildingKey: KJSFBM
  waterPath: depth
  flowPath: velocity