11
13693261870
2024-10-08 e9c5d9484336770c3fb8076a82dbbd85c363ddd2
11
已修改2个文件
74 ■■■■ 文件已修改
src/main/java/com/se/simu/domain/dto/LayerDto.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/ResultService.java 62 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/domain/dto/LayerDto.java
@@ -1,5 +1,7 @@
package com.se.simu.domain.dto;
import java.util.List;
/**
 * 图层实体类
 *
@@ -18,14 +20,14 @@
    private WaterDto waters;
    public LayerDto() {
        this.duration = new DurationDto();
        this.terrain = new TerrainDto();
        this.waters = new WaterDto();
    }
    public LayerDto(String ver) {
        this();
    public LayerDto(String ver, int epsg, List<Integer> sizes) {
        this.version = ver;
        this.waters = new WaterDto();
        this.duration = new DurationDto();
        this.terrain = new TerrainDto(sizes);
        this.terrain.setEpsg(epsg + "");
    }
    public String getVersion() {
src/main/java/com/se/simu/service/ResultService.java
@@ -55,7 +55,7 @@
    public void process(ResultDto dto) throws Exception {
        try {
            LayerDto layer = new LayerDto(config.getVer());
            LayerDto layer = new LayerDto(config.getVer(), 4528, config.getSizes());
            copeTerrain(dto, layer);
            copeBuilding(dto, layer);
@@ -127,14 +127,11 @@
    private static void Resample(Dataset ds, String dest, int width, int height, LayerDto layer) {
        Vector<String> vector = new Vector<>();
        //vector.add("-s_srs");
        //vector.add("EPSG:" + 4326);
        vector.add("-t_srs");
        vector.add("EPSG:" + 4326);
        vector.add("-r");
        vector.add("bilinear");
        vector.add("-of");
        vector.add("GTiff");
        vector.add("-ts");
        vector.add("" + width);
        vector.add("" + height);
        vector.add("-te");
        vector.add("" + layer.getExtension().getMinx());
        vector.add("" + layer.getExtension().getMiny());
@@ -142,6 +139,10 @@
        vector.add("" + layer.getExtension().getMaxy());
        vector.add("-te_srs");
        vector.add("EPSG:" + 4326);
        vector.add("-r");
        vector.add("bilinear");
        vector.add("-of");
        vector.add("GTiff");
        WarpOptions warpOptions = new WarpOptions(vector);
        Dataset destDs = gdal.Warp(dest, new Dataset[]{ds}, warpOptions);
@@ -159,12 +160,7 @@
            //band.ReadRaster(0, 0, width, height, buffer, width, height, 0, 0);
            band.ReadRaster(0, 0, width, height, buffer);
            BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            Graphics2D graphic = image.createGraphics();
            Color transparent = new Color(0, 0, 0, 0);
            graphic.setColor(transparent);
            graphic.clearRect(0, 0, width, height);
            BufferedImage image = createImage(width, height);
            double differ = layer.getExtension().getMaxHeight() - layer.getExtension().getMinHeight(), minHeight = layer.getExtension().getMinHeight();
            for (int x = 0; x < width; x++) {
                for (int y = 0; y < height; y++) {
@@ -181,15 +177,25 @@
                    }
                    Color color = new Color(r, g, b, 127);
                    //image.setRGB(x, y, color.getRGB());
                    graphic.drawImage(image, x, y, 1, 1, color, null);
                    //graphic.drawImage(image, x, y, 1, 1, color, null);
                    image.setRGB(x, y, color.getRGB());
                }
            }
            graphic.dispose();
            savePng(image, png);
        } finally {
            if (null != ds) ds.delete();
        }
    }
    private static BufferedImage createImage(int width, int height) {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D graphic = image.createGraphics();
        Color transparent = new Color(0, 0, 0, 0);
        graphic.setColor(transparent);
        graphic.clearRect(0, 0, width, height);
        graphic.dispose();
        return image;
    }
    private static void savePng(BufferedImage image, String png) {
@@ -298,7 +304,7 @@
    }
    private static void setWaterHeight(LayerDto layer, List<String> files) {
        files.parallelStream().forEach(file->{
        files.parallelStream().forEach(file -> {
            Dataset ds = null;
            try {
                ds = gdal.Open(file, gdalconst.GA_ReadOnly);
@@ -361,12 +367,7 @@
            band.ReadRaster(0, 0, width, height, buffer);
            float[] building = dto.getBuildings().get(width + "_" + height);
            BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            Graphics2D graphic = image.createGraphics();
            Color transparent = new Color(0, 0, 0, 0);
            graphic.setColor(transparent);
            graphic.clearRect(0, 0, width, height);
            BufferedImage image = createImage(width, height);
            double differ = layer.getExtension().getMaxHeight() - layer.getExtension().getMinHeight(), minHeight = layer.getExtension().getMinHeight();
            for (int x = 0; x < width; x++) {
                for (int y = 0; y < height; y++) {
@@ -384,11 +385,9 @@
                    }
                    Color color = new Color(r, g, b, 127);
                    //image.setRGB(x, y, color.getRGB());
                    graphic.drawImage(image, x, y, 1, 1, color, null);
                    image.setRGB(x, y, color.getRGB());
                }
            }
            graphic.dispose();
            savePng(image, png);
        } finally {
            if (null != ds) ds.delete();
@@ -461,12 +460,7 @@
    }
    private static void createFlowPng(float[] vxBuffer, float[] vyBuffer, String png, int width, int height) {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D graphic = image.createGraphics();
        Color transparent = new Color(0, 0, 0, 0);
        graphic.setColor(transparent);
        graphic.clearRect(0, 0, width, height);
        BufferedImage image = createImage(width, height);
        // 用 R通道表示,流向为归一化的二维向量(x,y),G通道表示为 x *255 , B通道表示为 y * 255
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
@@ -484,11 +478,9 @@
                int b = (int) ((fy / dr * 0.5 + 0.5) * 255);
                Color color = new Color(getSafeValue(r), getSafeValue(g), getSafeValue(b), 127);
                //image.setRGB(x, y, color.getRGB());
                graphic.drawImage(image, x, y, 1, 1, color, null);
                image.setRGB(x, y, color.getRGB());
            }
        }
        graphic.dispose();
        savePng(image, png);
    }