From 8bbb8a2caf8720d74fb2aca31abdc6ef3ab9d13c Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 07 十一月 2024 16:01:15 +0800 Subject: [PATCH] 修改数据处理逻辑(大) --- /dev/null | 531 ------------------------------------------------ src/main/java/com/se/simu/domain/dto/ExtensionDto.java | 14 - src/main/java/com/se/simu/service/ResultService.java | 16 src/main/java/com/se/simu/domain/dto/WaterDto.java | 33 +++ src/main/java/com/se/simu/controller/TestController.java | 7 src/main/java/com/se/simu/service/SimuService.java | 3 src/main/java/com/se/simu/service/UwService.java | 4 src/main/java/com/se/simu/service/WaterService.java | 25 -- src/main/java/com/se/simu/domain/dto/TerrainDto.java | 27 -- 9 files changed, 52 insertions(+), 608 deletions(-) diff --git a/src/main/java/com/se/simu/controller/TestController.java b/src/main/java/com/se/simu/controller/TestController.java index ed92dff..1b7ab7c 100644 --- a/src/main/java/com/se/simu/controller/TestController.java +++ b/src/main/java/com/se/simu/controller/TestController.java @@ -69,15 +69,16 @@ @ApiOperation(value = "testResuslt *") @ApiImplicitParams({ - @ApiImplicitParam(name = "path", value = "璺緞", dataType = "String", paramType = "query", example = "20241010095328") + @ApiImplicitParam(name = "path", value = "璺緞", dataType = "String", paramType = "query", example = "20241010095328"), + @ApiImplicitParam(name = "time", value = "鏃堕棿", dataType = "String", paramType = "query", example = "2024-11-07 09:23:42") }) @GetMapping("/testResuslt") - public R<Object> testResuslt(String path) { + public R<Object> testResuslt(String path,String time) { try { DataPo data = new DataPo(); data.setEpsg(4548); data.setInPath(path); - data.setStartTime(StringHelper.YMDHMS_FORMAT.parse("2024-09-30 00:00:00")); + data.setStartTime(StringHelper.YMDHMS_FORMAT.parse(time)); resultService.process(data); diff --git a/src/main/java/com/se/simu/domain/dto/ExtensionDto.java b/src/main/java/com/se/simu/domain/dto/ExtensionDto.java index e1bd6a0..3daa647 100644 --- a/src/main/java/com/se/simu/domain/dto/ExtensionDto.java +++ b/src/main/java/com/se/simu/domain/dto/ExtensionDto.java @@ -19,7 +19,8 @@ private double maxHeight; - public ExtensionDto(){} + public ExtensionDto() { + } public ExtensionDto(double minx, double miny, double maxx, double maxy) { this.minx = minx; @@ -35,17 +36,6 @@ this.maxy = maxy; this.minHeight = minHeight; this.maxHeight = maxHeight; - } - - public void setHeight(double minHeight, double maxHeight) { - synchronized (this) { - if (this.minHeight > minHeight) { - this.minHeight = minHeight; - } - if (this.maxHeight < maxHeight) { - this.maxHeight = maxHeight; - } - } } public double getMinx() { diff --git a/src/main/java/com/se/simu/domain/dto/TerrainDto.java b/src/main/java/com/se/simu/domain/dto/TerrainDto.java index 0b095b5..92814ff 100644 --- a/src/main/java/com/se/simu/domain/dto/TerrainDto.java +++ b/src/main/java/com/se/simu/domain/dto/TerrainDto.java @@ -18,12 +18,6 @@ @JSONField(serialize = false) private String epsg; - @JSONField(serialize = false) - private Double minHeight; - - @JSONField(serialize = false) - private Double maxHeight; - public TerrainDto() { } @@ -32,11 +26,6 @@ for (Integer i : sizes) { size.add(new int[]{i, i}); } - } - - public void setHeight(Double minHeight, Double maxHeight) { - this.minHeight = minHeight; - this.maxHeight = maxHeight; } public List<int[]> getSize() { @@ -53,21 +42,5 @@ public void setEpsg(String epsg) { this.epsg = epsg; - } - - public double getMinHeight() { - return minHeight; - } - - public void setMinHeight(double minHeight) { - this.minHeight = minHeight; - } - - public double getMaxHeight() { - return maxHeight; - } - - public void setMaxHeight(double maxHeight) { - this.maxHeight = maxHeight; } } diff --git a/src/main/java/com/se/simu/domain/dto/WaterDto.java b/src/main/java/com/se/simu/domain/dto/WaterDto.java index 43ec4b8..901ea89 100644 --- a/src/main/java/com/se/simu/domain/dto/WaterDto.java +++ b/src/main/java/com/se/simu/domain/dto/WaterDto.java @@ -15,11 +15,28 @@ @JSONField(serialize = false) private List<String> files; + @JSONField(serialize = false) + private Double minHeight; + + @JSONField(serialize = false) + private Double maxHeight; + private List<Long> data; public WaterDto() { this.files = new ArrayList<>(); this.data = new ArrayList<>(); + } + + public void setHeight(double minHeight, double maxHeight) { + synchronized (this) { + if (this.minHeight > minHeight) { + this.minHeight = minHeight; + } + if (this.maxHeight < maxHeight) { + this.maxHeight = maxHeight; + } + } } public List<String> getFiles() { @@ -37,4 +54,20 @@ public void setData(List<Long> data) { this.data = data; } + + public Double getMinHeight() { + return minHeight; + } + + public void setMinHeight(Double minHeight) { + this.minHeight = minHeight; + } + + public Double getMaxHeight() { + return maxHeight; + } + + public void setMaxHeight(Double maxHeight) { + this.maxHeight = maxHeight; + } } diff --git a/src/main/java/com/se/simu/domain/vo/Duration.java b/src/main/java/com/se/simu/domain/vo/Duration.java deleted file mode 100644 index d380cdc..0000000 --- a/src/main/java/com/se/simu/domain/vo/Duration.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.se.simu.domain.vo; - -/** - * 鎸佺画鏃堕棿瀹炰綋绫� - * - * @author WWW - * @date 2024-07-18 - */ -public class Duration { - long start; - - long end; - - public Duration() { - } - - public Duration(long start, long end) { - this.start = start; - this.end = end; - } - - public long getStart() { - return start; - } - - public void setStart(long start) { - this.start = start; - } - - public long getEnd() { - return end; - } - - public void setEnd(long end) { - this.end = end; - } -} diff --git a/src/main/java/com/se/simu/domain/vo/Extension.java b/src/main/java/com/se/simu/domain/vo/Extension.java deleted file mode 100644 index c34225a..0000000 --- a/src/main/java/com/se/simu/domain/vo/Extension.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.se.simu.domain.vo; - -/** - * 鎸佺画鏃堕棿瀹炰綋绫� - * - * @author WWW - * @date 2024-07-18 - */ -public class Extension { - double minx; - - double miny; - - double maxx; - - double maxy; - - double minHeight; - - double maxHeight; - - public Extension() { - } - - public Extension(double minx, double miny, double maxx, double maxy) { - this.minx = minx; - this.miny = miny; - this.maxx = maxx; - this.maxy = maxy; - } - - public Extension(double minHeight, double maxHeight) { - this.minHeight = minHeight; - this.maxHeight = maxHeight; - } - - public Extension(double minx, double miny, double maxx, double maxy, double minHeight, double maxHeight) { - this.minx = minx; - this.miny = miny; - this.maxx = maxx; - this.maxy = maxy; - this.minHeight = minHeight; - this.maxHeight = maxHeight; - } - - public double getMinx() { - return minx; - } - - public void setMinx(double minx) { - this.minx = minx; - } - - public double getMiny() { - return miny; - } - - public void setMiny(double miny) { - this.miny = miny; - } - - public double getMaxx() { - return maxx; - } - - public void setMaxx(double maxx) { - this.maxx = maxx; - } - - public double getMaxy() { - return maxy; - } - - public void setMaxy(double maxy) { - this.maxy = maxy; - } - - public double getMinHeight() { - return minHeight; - } - - public void setMinHeight(double minHeight) { - this.minHeight = minHeight; - } - - public double getMaxHeight() { - return maxHeight; - } - - public void setMaxHeight(double maxHeight) { - this.maxHeight = maxHeight; - } -} diff --git a/src/main/java/com/se/simu/domain/vo/Layer.java b/src/main/java/com/se/simu/domain/vo/Layer.java deleted file mode 100644 index e7be027..0000000 --- a/src/main/java/com/se/simu/domain/vo/Layer.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.se.simu.domain.vo; - -import com.se.simu.domain.vo.Duration; -import com.se.simu.domain.vo.Extension; -import com.se.simu.domain.vo.Terrain; -import com.se.simu.domain.vo.Water; - -/** - * 鍥惧眰瀹炰綋绫� - * - * @author WWW - * @date 2024-07-16 - */ -public class Layer { - String version; - - Duration duration; - - Extension extension; - - Terrain terrain; - - Water waters; - - public Layer() { - } - - public Layer(String version, Duration duration, Extension extension, Terrain terrain, Water waters) { - this.version = version; - this.duration = duration; - this.extension = extension; - this.terrain = terrain; - this.waters = waters; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public Duration getDuration() { - return duration; - } - - public void setDuration(Duration duration) { - this.duration = duration; - } - - public Extension getExtension() { - return extension; - } - - public void setExtension(Extension extension) { - this.extension = extension; - } - - public Terrain getTerrain() { - return terrain; - } - - public void setTerrain(Terrain terrain) { - this.terrain = terrain; - } - - public Water getWaters() { - return waters; - } - - public void setWaters(Water waters) { - this.waters = waters; - } -} diff --git a/src/main/java/com/se/simu/domain/vo/Terrain.java b/src/main/java/com/se/simu/domain/vo/Terrain.java deleted file mode 100644 index 1df5e36..0000000 --- a/src/main/java/com/se/simu/domain/vo/Terrain.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.se.simu.domain.vo; - -import java.util.List; - -/** - * 鍦板舰瀹炰綋绫� - * - * @author WWW - * @date 2024-07-18 - */ -public class Terrain { - /** - * 灏哄锛�64*64 ... 2048*2048 - */ - List<Integer[]> size; - - public Terrain() { - } - - public Terrain(List<Integer[]> size) { - this.size = size; - } - - public List<Integer[]> getSize() { - return size; - } - - public void setSize(List<Integer[]> size) { - this.size = size; - } -} diff --git a/src/main/java/com/se/simu/domain/vo/Water.java b/src/main/java/com/se/simu/domain/vo/Water.java deleted file mode 100644 index 08c6500..0000000 --- a/src/main/java/com/se/simu/domain/vo/Water.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.se.simu.domain.vo; - -import java.util.List; - -/** - * 姘撮潰瀹炰綋绫� - * - * @author WWW - * @date 2024-07-18 - */ -public class Water { - List<Long> data; - - public Water() { - } - - public Water(List<Long> data) { - this.data = data; - } - - public List<Long> getData() { - return data; - } - - public void setData(List<Long> data) { - this.data = data; - } -} diff --git a/src/main/java/com/se/simu/service/Result2Service.java b/src/main/java/com/se/simu/service/Result2Service.java deleted file mode 100644 index e32ae71..0000000 --- a/src/main/java/com/se/simu/service/Result2Service.java +++ /dev/null @@ -1,531 +0,0 @@ -package com.se.simu.service; - -import cn.hutool.core.io.FileUtil; -import com.alibaba.fastjson.JSON; -import com.se.simu.config.PropertiesConfig; -import com.se.simu.domain.dto.ExtensionDto; -import com.se.simu.domain.dto.LayerDto; -import com.se.simu.domain.dto.ResultDto; -import com.se.simu.domain.po.DataPo; -import com.se.simu.helper.GdalHelper; -import lombok.extern.slf4j.Slf4j; -import org.gdal.gdal.Band; -import org.gdal.gdal.Dataset; -import org.gdal.gdal.WarpOptions; -import org.gdal.gdal.gdal; -import org.gdal.gdalconst.gdalconst; -import org.gdal.ogr.Geometry; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import javax.imageio.ImageIO; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.List; -import java.util.*; - -/** - * 澶勭悊缁撴灉鏈嶅姟绫� - * - * @author WWW - * @date 2024-09-29 - */ -@Slf4j -@Service -@SuppressWarnings("ALL") -public class Result2Service { - @Resource - PropertiesConfig config; - - public final static double MAX_X_OFFSET = 0.002; - - public String testResuslt() throws Exception { - ResultDto dto = new ResultDto( - "202409", - "D:\\simu\\input\\tongzhou-local-mesh2-terrain.tif", - "D:\\simu\\input\\tongzhou-local-mesh2-buildings.tif", - "D:\\simu\\input\\waters", - "D:\\simu\\input\\flows", - "D:\\simu\\out", - 4548); - LayerDto layer = new LayerDto(config.getVer(), 4528, config.getSizes()); - process(dto, layer); - - return "OK"; - } - - public void process(DataPo 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.getOutPath(), - data.getEpsg()); - LayerDto layer = new LayerDto(config.getVer(), data.getEpsg(), config.getSizes()); - process(dto, layer); - } - - private void process(ResultDto dto, LayerDto layer) throws Exception { - try { - copeTerrain(dto, layer); - copeBuilding(dto, layer); - copeWater(dto, layer); - copeFlow(dto, layer); - copeLayerJson(dto, layer); - } finally { - File dir = new File(dto.getTemp()); - if (dir.exists()) { - FileUtil.del(dir); - } - } - } - - /** - * 鍦板舰 - */ - private void copeTerrain(ResultDto dto, LayerDto layer) { - Dataset ds = null; - try { - ds = gdal.Open(dto.getTerrainFile(), gdalconst.GA_ReadOnly); - if (null == ds || 0 == ds.getRasterCount() || null == ds.GetSpatialRef()) return; - - setTerrainInfo(ds, layer); - setWaterInfo(dto, layer); - createTerrainPng(dto, ds, layer); - } finally { - if (null != ds) ds.delete(); - } - } - - private void setTerrainInfo(Dataset ds, LayerDto layer) { - Geometry minPoint = GdalHelper.getMinPoint(ds); - Geometry maxPoint = GdalHelper.getMaxPoint(ds); - double minx = getMinVal(minPoint.GetX(0), 10000000); - double miny = getMinVal(minPoint.GetY(0), 10000000); - double maxx = getMaxVal(maxPoint.GetX(0) + MAX_X_OFFSET, 10000000); - double maxy = getMaxVal(maxPoint.GetY(0), 10000000); - layer.setExtension(new ExtensionDto(minx, miny, maxx, maxy, Double.MAX_VALUE, Double.MIN_VALUE)); - - Band band = ds.GetRasterBand(1); - double[] mm = new double[2]; - band.ComputeRasterMinMax(mm, 0); - layer.getTerrain().setHeight(getMinVal(mm[0], 1000), getMaxVal(mm[1], 1000)); - } - - private static double getMinVal(double val, double radix) { - return ((long) Math.floor(val * radix)) / radix; - } - - private static double getMaxVal(double val, double radix) { - return ((long) Math.ceil(val * radix)) / radix; - } - - private void createTerrainPng(ResultDto dto, Dataset ds, LayerDto layer) { - String terrainPath = dto.getOutPath() + File.separator + "terrain"; - File f = new File(terrainPath); - if (!f.exists() || !f.isDirectory()) f.mkdirs(); - - for (int[] sizes : layer.getTerrain().getSize()) { - String tif = dto.getTemp() + File.separator + "terrain_" + sizes[0] + "_" + sizes[1] + ".tif"; - Resample(ds, tif, sizes[0], sizes[1], layer); - if (!new File(tif).exists()) continue; - - String png = terrainPath + File.separator + sizes[0] + "_" + sizes[1] + ".png"; - Terrain2Png(layer, tif, png, sizes[0], sizes[1]); - } - } - - private static void Resample(Dataset ds, String dest, int width, int height, LayerDto layer) { - Vector<String> vector = new Vector<>(); - 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("bilinear"); - vector.add("-of"); - vector.add("GTiff"); - WarpOptions warpOptions = new WarpOptions(vector); - - Dataset destDs = gdal.Warp(dest, new Dataset[]{ds}, warpOptions); - destDs.delete(); - } - - private static void Terrain2Png(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, width, height, 0, 0); - band.ReadRaster(0, 0, width, height, buffer); - - BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - 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++) { - int offset = x + y * width; - if (Float.isNaN(buffer[offset]) || buffer[offset] < -999 || buffer[offset] < minHeight) continue; - - int r = 0, g, b; - if (buffer[offset] - layer.getExtension().getMaxHeight() > 0) { - g = b = 255; - } else { - int val = (int) ((buffer[offset] - minHeight) / differ * 65535); - g = val / 256; - b = val % 256; - } - - Color color = new Color(r, g, b, 127); - //graphic.drawImage(image, x, y, 1, 1, color, null); - image.setRGB(x, y, color.getRGB()); - } - } - 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) { - try { - ImageIO.write(image, "png", new File(png)); - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - } - } - - /** - * 寤虹瓚 - */ - private void copeBuilding(ResultDto dto, LayerDto layer) { - Dataset ds = null; - try { - ds = gdal.Open(dto.getBuildingFile(), gdalconst.GA_ReadOnly); - if (null == ds || 0 == ds.getRasterCount()) return; - - for (int[] sizes : layer.getTerrain().getSize()) { - String tif = dto.getTemp() + File.separator + "building_" + sizes[0] + "_" + sizes[1] + ".tif"; - Resample(ds, tif, sizes[0], sizes[1], layer); - if (!new File(tif).exists()) continue; - - Dataset dataset = gdal.Open(tif, gdalconst.GA_ReadOnly); - if (null == dataset || 0 == dataset.getRasterCount()) return; - - float[] buffer = new float[sizes[0] * sizes[1]]; - //dataset.GetRasterBand(1).ReadRaster(0, 0, sizes[0], sizes[1], buffer, sizes[0], sizes[1], 0, 0); - dataset.GetRasterBand(1).ReadRaster(0, 0, sizes[0], sizes[1], buffer); - dto.getBuildings().put(sizes[0] + "_" + sizes[1], buffer); - - dataset.delete(); - } - } finally { - if (null != ds) ds.delete(); - } - } - - /** - * 姘撮潰 - */ - private void setWaterInfo(ResultDto dto, LayerDto layer) { - List<String> files = getFiles(dto.getWaterPath(), ".tif"); - layer.getWaters().setFiles(files); - if (null == files || files.size() == 0) return; - - setWaterData(layer, files); - setWaterHeight(layer, files); - } - - private void copeWater(ResultDto dto, LayerDto layer) { - List<String> files = layer.getWaters().getFiles(); - if (files.size() == 0 || files.size() != layer.getWaters().getData().size()) return; - - processWaters(dto, files, layer); - } - - private static List<String> getFiles(String path, String suffix) { - List<String> files = new ArrayList<>(); - getFiles(files, new File(path), suffix); - files.sort((a, b) -> a.compareToIgnoreCase(b)); - - return files; - } - - private static void getFiles(List<String> files, File file, String suffix) { - if (!file.exists()) return; - - if (file.isDirectory()) { - File[] fileList = file.listFiles(); - for (File f : fileList) { - if (f.isDirectory()) { - getFiles(files, f, suffix); - } else { - if (f.getName().toLowerCase().endsWith(suffix)) { - files.add(f.getPath()); - } - } - } - } else { - if (file.getName().toLowerCase().endsWith(suffix)) { - files.add(file.getPath()); - } - } - } - - private static void setWaterData(LayerDto layer, List<String> files) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - calendar.set(Calendar.MILLISECOND, 0); - - for (String file : files) { - String fileName = getNameWithExt(file); - int hour = Integer.parseInt(fileName.substring(0, 2)); - int minute = Integer.parseInt(fileName.substring(2, 4)); - int second = Integer.parseInt(fileName.substring(4, 6)); - - calendar.set(Calendar.HOUR_OF_DAY, hour); - calendar.set(Calendar.MINUTE, minute); - calendar.set(Calendar.SECOND, second); - - layer.getWaters().getData().add(calendar.getTime().getTime()); - } - layer.getDuration().setStart(layer.getWaters().getData().get(0)); - layer.getDuration().setEnd(layer.getWaters().getData().get(layer.getWaters().getData().size() - 1)); - } - - private static void setWaterHeight(LayerDto layer, List<String> files) { - files.parallelStream().forEach(file -> { - Dataset ds = null; - try { - ds = gdal.Open(file, gdalconst.GA_ReadOnly); - if (null == ds || 0 == ds.getRasterCount() || null == ds.GetSpatialRef()) return; - - double[] mm = new double[2]; - ds.GetRasterBand(1).ComputeRasterMinMax(mm, 0); - layer.getExtension().setHeight(mm[0], mm[1]); - } finally { - if (null != ds) ds.delete(); - } - }); - layer.getExtension().setMinHeight(getMinVal(layer.getExtension().getMinHeight() - 1, 1000)); - layer.getExtension().setMaxHeight(getMaxVal(layer.getExtension().getMaxHeight() + 1, 1000)); - } - - private static void processWaters(ResultDto dto, List<String> files, LayerDto layer) { - for (int i = 0, c = files.size(); i < c; i++) { - Dataset ds = null; - try { - ds = gdal.Open(files.get(i), gdalconst.GA_ReadOnly); - if (null == ds || 0 == ds.getRasterCount() || null == ds.GetSpatialRef()) return; - - createWaterPng(dto, ds, layer, layer.getWaters().getData().get(i)); - } finally { - if (null != ds) ds.delete(); - } - } - } - - private static void createWaterPng(ResultDto dto, Dataset ds, LayerDto layer, long ticks) { - String waterPath = dto.getOutPath() + File.separator + "waters" + File.separator + ticks; - File dir = new File(waterPath); - if (!dir.exists() || !dir.isDirectory()) dir.mkdirs(); - - for (int[] sizes : layer.getTerrain().getSize()) { - String fileName = getNameWithExt(ds.GetDescription()) + "_" + sizes[0] + "_" + sizes[1]; - String tif = dto.getTemp() + File.separator + fileName + ".tif"; - Resample(ds, tif, sizes[0], sizes[1], layer); - if (!new File(tif).exists()) continue; - - String png = waterPath + File.separator + sizes[0] + "_" + sizes[1] + ".png"; - water2Png(dto, layer, tif, png, sizes[0], sizes[1]); - } - } - - private static String getNameWithExt(String file) { - return file.substring(file.lastIndexOf(File.separator) + 1, file.lastIndexOf(".")); - } - - private static void water2Png(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, width, height, 0, 0); - band.ReadRaster(0, 0, width, height, buffer); - float[] building = dto.getBuildings().get(width + "_" + height); - - BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - 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++) { - int offset = x + y * width; - if (Float.isNaN(buffer[offset]) || buffer[offset] < -999 || buffer[offset] < minHeight) continue; - if (!Float.isNaN(building[offset]) && building[offset] > -999) continue; - - int r = 0, g, b; - if (buffer[offset] - layer.getExtension().getMaxHeight() > 0) { - g = b = 255; - } else { - int val = (int) ((buffer[offset] - minHeight) / differ * 65535); - g = val / 256; - b = val % 256; - } - - Color color = new Color(r, g, b, 127); - image.setRGB(x, y, color.getRGB()); - } - } - savePng(image, png); - } finally { - if (null != ds) ds.delete(); - } - } - - private void copeFlow(ResultDto dto, LayerDto layer) { - List<String> vxFiles = new ArrayList<>(); - List<String> vyFiles = new ArrayList<>(); - List<String> files = getFiles(dto.getFlowPath(), ".tif"); - for (String file : files) { - if (file.contains(File.separator + "vx")) vxFiles.add(file); - if (file.contains(File.separator + "vy")) vyFiles.add(file); - } - if (null == vxFiles || null == vyFiles || vxFiles.size() != vyFiles.size() || vxFiles.size() != layer.getWaters().getData().size()) - return; - - for (int i = 0, c = vxFiles.size(); i < c; i++) { - Dataset vxDs = null, vyDs = null; - try { - vxDs = gdal.Open(vxFiles.get(i), gdalconst.GA_ReadOnly); - vyDs = gdal.Open(vyFiles.get(i), gdalconst.GA_ReadOnly); - if (null == vxDs || 0 == vxDs.getRasterCount() || null == vxDs.GetSpatialRef() || null == vyDs || 0 == vyDs.getRasterCount() || null == vyDs.GetSpatialRef()) - return; - - createFlowPng(dto, vxDs, vyDs, layer, layer.getWaters().getData().get(i)); - } finally { - if (null != vxDs) vxDs.delete(); - if (null != vyDs) vyDs.delete(); - } - } - } - - private static void createFlowPng(ResultDto dto, Dataset vxDs, Dataset vyDs, LayerDto layer, long ticks) { - String flowPath = dto.getOutPath() + File.separator + "flows" + File.separator + ticks; - File dir = new File(flowPath); - if (!dir.exists() || !dir.isDirectory()) dir.mkdirs(); - - for (int[] sizes : layer.getTerrain().getSize()) { - String vxName = getNameWithExt(vxDs.GetDescription()) + "_" + sizes[0] + "_" + sizes[1]; - String vxTif = dto.getTemp() + File.separator + vxName + ".tif"; - Resample(vxDs, vxTif, sizes[0], sizes[1], layer); - - String vyName = getNameWithExt(vyDs.GetDescription()) + "_" + sizes[0] + "_" + sizes[1]; - String vyTif = dto.getTemp() + File.separator + vyName + ".tif"; - Resample(vyDs, vyTif, sizes[0], sizes[1], layer); - if (!new File(vxTif).exists() || !new File(vyTif).exists()) continue; - - String png = flowPath + File.separator + sizes[0] + "_" + sizes[1] + ".png"; - vxyTif2Png(layer, vxTif, vyTif, png, sizes[0], sizes[1]); - } - } - - private static void vxyTif2Png(LayerDto layer, String vxTif, String vyTif, String png, int width, int height) { - Dataset vxDs = null, vyDs = null; - try { - vxDs = gdal.Open(vxTif, gdalconst.GA_ReadOnly); - vyDs = gdal.Open(vyTif, gdalconst.GA_ReadOnly); - if (null == vxDs || 0 == vxDs.getRasterCount() || null == vyDs || 0 == vyDs.getRasterCount()) return; - - float[] vxBuffer = new float[width * height], vyBuffer = new float[width * height]; - vxDs.GetRasterBand(1).ReadRaster(0, 0, width, height, vxBuffer); - vyDs.GetRasterBand(1).ReadRaster(0, 0, width, height, vyBuffer); - - createFlowPng(vxBuffer, vyBuffer, png, width, height); - } finally { - if (null != vxDs) vxDs.delete(); - if (null != vyDs) vyDs.delete(); - } - } - - private static void createFlowPng(float[] vxBuffer, float[] vyBuffer, String png, int width, int height) { - BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - // 鐢� R閫氶亾琛ㄧず锛屾祦鍚戜负褰掍竴鍖栫殑浜岀淮鍚戦噺锛坸,y锛夛紝G閫氶亾琛ㄧず涓� x *255 , B閫氶亾琛ㄧず涓� y * 255 - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - int offset = x + y * width; - float fx = getFloatValue(vxBuffer[offset]); - float fy = getFloatValue(vyBuffer[offset]); - if (Float.isNaN(fx) && Float.isNaN(fy) || (fx == 0 && fy == 0)) continue; - - fx = Float.isNaN(fx) ? 0 : fx; - fy = Float.isNaN(fy) ? 0 : fy; - double dr = Math.sqrt(Math.pow(fx, 2) + Math.pow(fy, 2)); - - int r = (int) (dr / 4 * 255); - int g = (int) ((fx / dr * 0.5 + 0.5) * 255); - 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()); - } - } - savePng(image, png); - } - - private static float getFloatValue(float val) { - return (Float.isNaN(val) || val < -999) ? Float.NaN : val; - } - - private static int getSafeValue(int val) { - if (val < 0) return 0; - if (val > 255) return 255; - - return val; - } - - /** - * 鍏冩暟鎹� - */ - private void copeLayerJson(ResultDto dto, LayerDto layer) throws IOException { - layer.getWaters().setFiles(null); - //String json = JSONUtil.toJsonPrettyStr(layer); - String json = JSON.toJSONString(layer); - String filePath = dto.getOutPath() + File.separator + "layer.json"; - - FileWriter fw = new FileWriter(filePath); - BufferedWriter bw = new BufferedWriter(fw); - bw.write(json); - bw.close(); - fw.close(); - } -} diff --git a/src/main/java/com/se/simu/service/ResultService.java b/src/main/java/com/se/simu/service/ResultService.java index d94bb82..d91b569 100644 --- a/src/main/java/com/se/simu/service/ResultService.java +++ b/src/main/java/com/se/simu/service/ResultService.java @@ -106,12 +106,13 @@ double miny = getMinVal(minPoint.GetY(0), 10000000); double maxx = getMaxVal(maxPoint.GetX(0) + MAX_X_OFFSET, 10000000); double maxy = getMaxVal(maxPoint.GetY(0), 10000000); - layer.setExtension(new ExtensionDto(minx, miny, maxx, maxy, Double.MAX_VALUE, Double.MIN_VALUE)); + //layer.setExtension(new ExtensionDto(minx, miny, maxx, maxy, Double.MAX_VALUE, Double.MIN_VALUE)); Band band = ds.GetRasterBand(1); double[] mm = new double[2]; band.ComputeRasterMinMax(mm, 0); - layer.getTerrain().setHeight(getMinVal(mm[0], 1000), getMaxVal(mm[1], 1000)); + //layer.getTerrain().setHeight(getMinVal(mm[0], 1000), getMaxVal(mm[1], 1000)); + layer.setExtension(new ExtensionDto(minx, miny, maxx, maxy, getMinVal(mm[0] - 1, 1000), getMaxVal(mm[1] + 1, 1000))); } private static double getMinVal(double val, double radix) { @@ -138,7 +139,7 @@ } /** - * 閲嶉噰鏍� + * 閲嶉噰鏍�: https://blog.51cto.com/u_16099346/6691820 */ private static void Resample(Dataset ds, String dest, int width, int height, LayerDto layer) { Vector<String> vector = new Vector<>(); @@ -341,13 +342,16 @@ double[] mm = new double[2]; ds.GetRasterBand(1).ComputeRasterMinMax(mm, 0); - layer.getExtension().setHeight(mm[0], mm[1]); + //layer.getExtension().setHeight(mm[0], mm[1]); + layer.getWaters().setHeight(mm[0], mm[1]); } finally { if (null != ds) ds.delete(); } }); - layer.getExtension().setMinHeight(getMinVal(layer.getExtension().getMinHeight() - 1, 1000)); - layer.getExtension().setMaxHeight(getMaxVal(layer.getExtension().getMaxHeight() + 1, 1000)); + //layer.getExtension().setMinHeight(getMinVal(layer.getExtension().getMinHeight() - 1, 1000)); + //layer.getExtension().setMaxHeight(getMaxVal(layer.getExtension().getMaxHeight() + 1, 1000)); + layer.getWaters().setMinHeight(getMinVal(layer.getWaters().getMinHeight() - 1, 1000)); + layer.getWaters().setMaxHeight(getMaxVal(layer.getWaters().getMaxHeight() + 1, 1000)); } private static void processWaters(ResultDto dto, List<String> files, LayerDto layer) { diff --git a/src/main/java/com/se/simu/service/SimuService.java b/src/main/java/com/se/simu/service/SimuService.java index 0206c2c..2f0edef 100644 --- a/src/main/java/com/se/simu/service/SimuService.java +++ b/src/main/java/com/se/simu/service/SimuService.java @@ -20,7 +20,6 @@ import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; import javax.annotation.Resource; import java.io.File; @@ -80,7 +79,7 @@ if (null != vo.getNum()) { wrapper.eq("num", vo.getNum()); } - if (!StringUtils.isEmpty(vo.getName())) { + if (!StringHelper.isEmpty(vo.getName())) { wrapper.like("lower(name)", vo.getName().trim().toLowerCase()); } if (!CollUtil.isEmpty(vo.getStatus())) { diff --git a/src/main/java/com/se/simu/service/UwService.java b/src/main/java/com/se/simu/service/UwService.java index ae0b607..fd477b5 100644 --- a/src/main/java/com/se/simu/service/UwService.java +++ b/src/main/java/com/se/simu/service/UwService.java @@ -6,7 +6,6 @@ import com.se.simu.domain.po.DataPo; import com.se.simu.helper.StringHelper; import com.se.simu.helper.WebHelper; -import com.sun.xml.internal.messaging.saaj.util.TeeInputStream; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import com.se.simu.Rainfall; @@ -140,8 +139,9 @@ } /** - * 鎵ц鍛戒护琛�,骞剁瓑寰呭懡浠ゆ墽琛屽畬姣� + * 鎵ц鍛戒护琛�,骞剁瓑寰呭懡浠ゆ墽琛屽畬姣� * + * https://www.cnblogs.com/stars-one/p/16482964.html * @param cmd 鍛戒护,window璁板緱瑕佷娇鐢╟md /c寮�澶�,濡俢md /c ipconfig * @throws IOException * @throws InterruptedException diff --git a/src/main/java/com/se/simu/service/WaterService.java b/src/main/java/com/se/simu/service/WaterService.java index c610533..b20879e 100644 --- a/src/main/java/com/se/simu/service/WaterService.java +++ b/src/main/java/com/se/simu/service/WaterService.java @@ -6,7 +6,6 @@ import com.se.simu.domain.po.DataPo; import com.se.simu.domain.po.SimuPo; import com.se.simu.domain.vo.*; -import com.se.simu.domain.vo.Layer; import com.se.simu.helper.GdalHelper; import com.se.simu.helper.StringHelper; import lombok.extern.slf4j.Slf4j; @@ -83,30 +82,6 @@ */ public String getFlowMap(String serviceName, Integer width, Integer height, Long timestamp) { return config.getOutPath() + File.separator + serviceName + File.separator + "flows" + File.separator + timestamp + File.separator + width + "_" + height + ".png"; - } - - /** - * 鑾峰彇鍥惧眰 * - */ - public Layer getLayer(String serviceName) { - Layer layer = new Layer(); - layer.setVersion(config.getVer()); - layer.setDuration(new Duration(1719812810225L, 1719812810225L)); - layer.setExtension(new Extension(2.11062743358, 0.53812160220, 2.11070827834, 0.53819799453, 1.151, 38.83)); - - List<Integer[]> sizes = new ArrayList<>(); - sizes.add(new Integer[]{64, 64}); - sizes.add(new Integer[]{128, 128}); - sizes.add(new Integer[]{256, 256}); - sizes.add(new Integer[]{512, 512}); - sizes.add(new Integer[]{1024, 1024}); - sizes.add(new Integer[]{2048, 2048}); - layer.setTerrain(new Terrain(sizes)); - - List<Long> data = new ArrayList<>(Arrays.asList(1719812812225L, 1719812812225L, 1719812812225L, 1719812812225L, 1719812812225L, 1719812812225L)); - layer.setWaters(new Water(data)); - - return layer; } /** -- Gitblit v1.9.3