1
13693261870
2024-11-16 fadc4c7a796d7d8c40239a951cb00d80cdab778f
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 {