| | |
| | | import com.se.simu.domain.po.DataPo; |
| | | import com.se.simu.domain.vo.BuildingDepthVo; |
| | | import com.se.simu.helper.GdalHelper; |
| | | import com.se.simu.helper.ShpHelper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.gdal.gdal.Band; |
| | | import org.gdal.gdal.Dataset; |
| | |
| | | import java.util.List; |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | | |
| | | /** |
| | | * 处理结果服务类 |
| | | * |
| | | * @author WWW |
| | | * @date 2024-09-29 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | @SuppressWarnings("ALL") |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 地形 |
| | | */ |
| | | private void copeTerrain(ResultDto dto, LayerDto layer) { |
| | | Dataset ds = null; |
| | | try { |
| | |
| | | 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) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 重采样 |
| | | */ |
| | | private static void Resample(Dataset ds, String dest, int width, int height, LayerDto layer) { |
| | | Vector<String> vector = new Vector<>(); |
| | | //vector.add("-s_srs"); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 建筑 |
| | | */ |
| | | private void copeBuilding(ResultDto dto, LayerDto layer) { |
| | | Driver driver = null; |
| | | DataSource dataSource = null; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 水面 |
| | | */ |
| | | private void setWaterInfo(ResultDto dto, LayerDto layer) { |
| | | List<String> files = getFiles(dto.getWaterPath(), ".tif"); |
| | | layer.getWaters().setFiles(files); |
| | |
| | | |
| | | 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) { |
| | |
| | | |
| | | createWaterPng(dto, ds, layer, layer.getWaters().getData().get(i)); |
| | | copyWaterTif(dto, ds, layer.getWaters().getData().get(i)); |
| | | createVectorShp(dto, ds, layer, layer.getWaters().getData().get(i)); |
| | | } finally { |
| | | if (null != ds) ds.delete(); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private static void copyWaterTif(ResultDto dto, Dataset ds, long ticks) { |
| | | String source = ds.GetDescription(); |
| | | String target = dto.getOutPath() + File.separator + "waters" + File.separator + ticks + File.separator + "water.tif"; |
| | | FileUtil.copyFile(source, target); |
| | | } |
| | | |
| | | private static String getNameWithExt(String file) { |
| | | return file.substring(file.lastIndexOf(File.separator) + 1, file.lastIndexOf(".")); |
| | | } |
| | |
| | | double[] transform = ds.GetGeoTransform(); |
| | | |
| | | BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); |
| | | double differ = layer.getExtension().getMaxHeight() - layer.getExtension().getMinHeight(), minHeight = layer.getExtension().getMinHeight(); |
| | | double differ = layer.getWaters().getMaxHeight() - layer.getWaters().getMinHeight(), minHeight = layer.getWaters().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(buffer[offset]) || buffer[offset] < -999 || buffer[offset] < minHeight) continue; |
| | | if (Float.isNaN(buffer[offset]) || buffer[offset] <= 0 || buffer[offset] < minHeight) continue; |
| | | |
| | | //double X = transform[0] + x * transform[1] + y * transform[2]; |
| | | //double Y = transform[3] + x * transform[4] + y * transform[5]; |
| | |
| | | //if (null != building) continue; |
| | | |
| | | int r = 0, g, b; |
| | | if (buffer[offset] - layer.getExtension().getMaxHeight() > 0) { |
| | | if (buffer[offset] - layer.getWaters().getMaxHeight() > 0) { |
| | | g = b = 255; |
| | | } else { |
| | | int val = (int) ((buffer[offset] - minHeight) / differ * 65535); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 是否相交 |
| | | * https://blog.csdn.net/flyingshineangel/article/details/135423025 |
| | | */ |
| | | private static BuildingDto intersects(ResultDto dto, double x, double y) { |
| | | Geometry p = new Geometry(ogr.wkbPoint); |
| | | p.AddPoint_2D(x, y); |
| | |
| | | return !Double.isNaN(val) && val > Integer.MIN_VALUE; |
| | | } |
| | | |
| | | private static void copyWaterTif(ResultDto dto, Dataset ds, long ticks) { |
| | | String source = ds.GetDescription(); |
| | | String target = dto.getOutPath() + File.separator + "waters" + File.separator + ticks + File.separator + "water.tif"; |
| | | FileUtil.copyFile(source, target); |
| | | } |
| | | |
| | | private static void createVectorShp(ResultDto dto, Dataset ds, LayerDto layer, Long ticks) { |
| | | String filePath = dto.getOutPath() + File.separator + "waters" + File.separator + ticks + File.separator + "water.geojson"; |
| | | ShpHelper.polygonize2Geojson(ds, filePath); |
| | | } |
| | | |
| | | private void copeFlow(ResultDto dto, LayerDto layer) { |
| | | List<String> files = getFiles(dto.getFlowPath(), ".tif"); |
| | | if (null == files || files.size() != layer.getWaters().getData().size()) return; |
| | |
| | | |
| | | 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通道表示,流向为归一化的二维向量(x,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; |
| | |
| | | return val; |
| | | } |
| | | |
| | | /** |
| | | * 元数据 |
| | | */ |
| | | private void copeLayerJson(ResultDto dto, LayerDto layer) throws IOException { |
| | | layer.getWaters().setFiles(null); |
| | | layer.getTerrain().setEpsg(null); |
| | |
| | | writeJson(filePath, json); |
| | | } |
| | | |
| | | /** |
| | | * 处理降水曲线文件曲线图 |
| | | */ |
| | | public void copeRainFallJson(ResultDto dto, LayerDto layer) throws IOException, ParseException { |
| | | String rainGageFilePath = config.getInPath() + File.separator + dto.getServiceName() + File.separator + "RainGage.dat"; |
| | | String filePath = dto.getOutPath() + File.separator + "rainfall.json"; |