| | |
| | | @ApiOperation(value = "04.testPngList <") |
| | | @GetMapping("/testPngList") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "path", value = "è·¯å¾", dataType = "String", paramType = "query", example = "D:\\other\\simu\\out\\chicago\\waters"), |
| | | @ApiImplicitParam(name = "path", value = "è·¯å¾", dataType = "String", paramType = "query", example = "D:\\other\\simu\\out\\fs24cubic"), |
| | | @ApiImplicitParam(name = "size", value = "尺寸", dataType = "Integer", paramType = "query", example = "1024") |
| | | }) |
| | | public R<Object> testPngList(String path, Integer size) { |
| | | try { |
| | | if (null == size) size = (Integer) 1024; |
| | | |
| | | String newPath = config.getOutPath() + File.separator + path + File.separator + "waters"; |
| | | String pngPath = config.getOutPath() + File.separator + path + File.separator + "png"; |
| | | if (!new File(pngPath).exists()) new File(pngPath).mkdirs(); |
| | | |
| | | int i = 1; |
| | | List<String> list = new ArrayList<>(); |
| | | for (File file : new File(path).listFiles()) { |
| | | for (File file : new File(newPath).listFiles()) { |
| | | if (!file.exists() || file.isFile()) continue; |
| | | |
| | | File pngFile = new File(file.getPath() + File.separator + size + "_" + size + ".png"); |
| | | if (!pngFile.exists() || pngFile.isDirectory()) continue; |
| | | |
| | | list.add("file '" + pngFile.getPath().replace("\\", "/") + "'"); |
| | | String pngName = i + ".png"; // String.format("f%06d", i) |
| | | Files.copy(pngFile.toPath(), Paths.get(pngPath + File.separator + pngName), StandardCopyOption.REPLACE_EXISTING); |
| | | |
| | | list.add("file '" + pngName + "'"); |
| | | System.out.println(list.get(list.size() - 1)); |
| | | i++; |
| | | } |
| | | |
| | | Path outPath = Paths.get(path + File.separator + "list.txt"); |
| | | Path outPath = Paths.get(pngPath + File.separator + "list.txt"); |
| | | try { |
| | | Files.write(outPath, list, StandardCharsets.UTF_8); |
| | | } catch (IOException e) { |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "tifPath", value = "Tifè·¯å¾", dataType = "String", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago"), |
| | | @ApiImplicitParam(name = "inPath", value = "è¾å
¥è·¯å¾", dataType = "String", paramType = "query", example = "20250425"), |
| | | @ApiImplicitParam(name = "startTime", value = "å¼å§æ¶é´", dataType = "Integer", paramType = "query", example = "2025-04-25 00:00:00"), |
| | | @ApiImplicitParam(name = "startTime", value = "å¼å§æ¶é´", dataType = "Integer", paramType = "query", example = "2025-04-29 00:00:00"), |
| | | @ApiImplicitParam(name = "epsg", value = "åæ ç³»ID", dataType = "Integer", paramType = "query", example = "4548") |
| | | }) |
| | | public R<Object> testCreateNsl(String tifPath, String inPath, String startTime, Integer epsg) { |
| | |
| | | data.setStartTime(StringHelper.YMDHMS_FORMAT.parse(startTime)); |
| | | data.setEpsg(epsg); |
| | | |
| | | procTifs(tifPath, data.getStartTime()); |
| | | procTifs(tifPath, inPath, data.getStartTime()); |
| | | testService.test(data); |
| | | |
| | | return success("ok"); |
| | |
| | | } |
| | | } |
| | | |
| | | private void procTifs(String tifPath, Date startTime) { |
| | | private void procTifs(String tifPath, String inPath, Date startTime) { |
| | | if (StringUtils.isEmpty(tifPath)) return; |
| | | |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(new Date(startTime.getYear() - 1900, startTime.getMonth() - 1, startTime.getDay(), 0, 0, 0)); |
| | | //calendar.setTime(new Date(startTime.getYear() - 1900, startTime.getMonth() - 1, startTime.getDay(), 0, 0, 0)); |
| | | calendar.setTime(startTime); |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | String newPath = config.getInPath() + File.separator + "depth"; |
| | | String newPath = config.getInPath() + File.separator + inPath + File.separator + "depth"; |
| | | if (!new File(newPath).exists()) new File(newPath).mkdirs(); |
| | | |
| | | for (File file : new File(tifPath).listFiles()) { |
| | | if (!file.exists() || !file.isDirectory()) continue; |
| | |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "11.renametifs <") |
| | | @GetMapping("/renametifs") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "path", value = "è·¯å¾", dataType = "String", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago\\depth"), |
| | | @ApiImplicitParam(name = "prefix", value = "åç¼", dataType = "Integer", paramType = "query", example = "01250302"), |
| | | @ApiImplicitParam(name = "newPrefix", value = "æ°åç¼", dataType = "Integer", paramType = "query", example = "20250429") |
| | | }) |
| | | public R<Object> renametifs(String path, String prefix, String newPrefix) { |
| | | try { |
| | | File[] files = new File(path).listFiles(); |
| | | for (File file : files) { |
| | | String newName = file.getPath().replace(prefix, newPrefix); |
| | | file.renameTo(new File(newName)); |
| | | } |
| | | |
| | | return success("ok"); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "10.å½åæ¶é´ *") |
| | | @GetMapping("/getTime") |
| | | public Object getTime() { |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.se.nsl.domain.po; |
| | | |
| | | import com.alibaba.fastjson.annotation.JSONField; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | |
| | | import java.util.Date; |
| | | |
| | | @SuppressWarnings("ALL") |
| | | public class Rainfall { |
| | | @ApiModelProperty("æ¶é´(yyyy-MM-dd HH:mm:ss)") |
| | | @JSONField(format = "yyyy-MM-dd HH:mm:ss") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date time; |
| | | |
| | | @ApiModelProperty("é¨å¼º(mm/h)") |
| | | private Double intensity; |
| | | |
| | | @ApiModelProperty("累计é¨é(mm)") |
| | | private Double total; |
| | | |
| | | public Rainfall() { |
| | | } |
| | | |
| | | public Rainfall(Date time, Double intensity, Double total) { |
| | | this.time = time; |
| | | this.intensity = intensity; |
| | | this.total = total; |
| | | } |
| | | |
| | | public Date getTime() { |
| | | return time; |
| | | } |
| | | |
| | | public void setTime(Date time) { |
| | | this.time = time; |
| | | } |
| | | |
| | | public Double getIntensity() { |
| | | return intensity; |
| | | } |
| | | |
| | | public void setIntensity(Double intensity) { |
| | | this.intensity = intensity; |
| | | } |
| | | |
| | | public Double getTotal() { |
| | | return total; |
| | | } |
| | | |
| | | public void setTotal(Double total) { |
| | | this.total = total; |
| | | } |
| | | } |
| | |
| | | @ApiModelProperty("é¨é计å表") |
| | | private List<RainGauge> gauges; |
| | | |
| | | @ApiModelProperty("éé¨å表") |
| | | private List<Rainfall> rainfalls; |
| | | |
| | | public SimuData() { |
| | | gauges = new ArrayList<>(); |
| | | } |
| | |
| | | //vector.add("-te_srs"); |
| | | //vector.add("EPSG:" + 4326); |
| | | vector.add("-r"); |
| | | vector.add("bilinear"); |
| | | 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(); |
| | | } |
| | | |
| | | public static void Resample2(Dataset ds, String dest, int width, int height, LayerDto layer) { |
| | | Vector<String> vector = new Vector<>(); |
| | | //vector.add("-s_srs"); |
| | | //vector.add("EPSG:" + 4548); |
| | | //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("average"); |
| | | vector.add("-of"); |
| | | vector.add("GTiff"); |
| | | WarpOptions warpOptions = new WarpOptions(vector); |
| | |
| | | gdal.SetConfigOption("GDAL_HOME", gdalPath); |
| | | gdal.SetConfigOption("GDAL_DATA", gdalPath + File.separator + "gdal-data"); |
| | | gdal.SetConfigOption("PROJ_LIB", gdalPath + File.separator + "projlib"); // /proj7/share |
| | | gdal.SetConfigOption("GDAL_DRIVER_PATH", gdalPath + File.separator + "gdalplugins"); |
| | | //gdal.SetConfigOption("GDAL_DRIVER_PATH", gdalPath + File.separator + "gdalplugins"); |
| | | |
| | | String path = System.getenv("PATH"); |
| | | if (!path.contains(gdalPath)) { |
| | |
| | | |
| | | gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); |
| | | gdal.SetConfigOption("SHAPE_ENCODING", ""); |
| | | gdal.SetConfigOption("PGEO_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s"); |
| | | gdal.SetConfigOption("MDB_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s"); |
| | | //gdal.SetConfigOption("PGEO_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s"); |
| | | //gdal.SetConfigOption("MDB_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s"); |
| | | |
| | | gdal.AllRegister(); |
| | | ogr.RegisterAll(); |
| | |
| | | @Resource |
| | | ResultService resultService; |
| | | |
| | | public final static double MIN_VAL = 0.00001; |
| | | |
| | | public final static double MAX_X_OFFSET = 0; |
| | | |
| | | public final static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
| | |
| | | for (int[] sizes : layer.getTerrain().getSize()) { |
| | | String fileName = ComHelper.getNameWithExt(ds.GetDescription()) + "_" + sizes[0] + "_" + sizes[1]; |
| | | String tif = dto.getTemp() + File.separator + fileName + ".tif"; |
| | | ComHelper.Resample(ds, tif, sizes[0], sizes[1], layer); |
| | | ComHelper.Resample2(ds, tif, sizes[0], sizes[1], layer); |
| | | if (!new File(tif).exists()) continue; |
| | | |
| | | String png = waterPath + File.separator + sizes[0] + "_" + sizes[1] + ".png"; |
| | |
| | | float[] buffer = new float[width * height]; |
| | | band.ReadRaster(0, 0, width, height, buffer); |
| | | double[] transform = ds.GetGeoTransform(); |
| | | buffer = interpolateGrid(buffer, width); |
| | | |
| | | BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); |
| | | //double differ = layer.getWaters().getMaxHeight() - layer.getWaters().getMinHeight(), minHeight = layer.getWaters().getMinHeight(); |
| | |
| | | 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] <= 0.00001 || Float.isNaN(ts[offset])) continue; |
| | | if (Float.isNaN(buffer[offset]) || buffer[offset] < MIN_VAL || Float.isNaN(ts[offset])) continue; |
| | | |
| | | //double X = transform[0] + x * transform[1] + y * transform[2]; |
| | | //double Y = transform[3] + x * transform[4] + y * transform[5]; |
| | |
| | | } finally { |
| | | if (null != ds) ds.delete(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æå¼å¤ç-åé»å |
| | | */ |
| | | public float[] interpolateGrid(float[] buffer, int size) { |
| | | float[] tempBuffer = new float[size * size]; |
| | | for (int i = 0; i < size; i++) { |
| | | for (int j = 0; j < size; j++) { |
| | | int index = i * size + j; |
| | | float current = buffer[index]; |
| | | if (current == 0) { |
| | | float sum = 0; |
| | | int count = 0; |
| | | // æ£æ¥ä¸é» |
| | | if (i > 0) { |
| | | float neighbor = buffer[(i - 1) * size + j]; |
| | | if (neighbor > MIN_VAL) { |
| | | sum += neighbor; |
| | | count++; |
| | | } |
| | | } |
| | | // æ£æ¥ä¸é» |
| | | if (i < size - 1) { |
| | | float neighbor = buffer[(i + 1) * size + j]; |
| | | if (neighbor > MIN_VAL) { |
| | | sum += neighbor; |
| | | count++; |
| | | } |
| | | } |
| | | // æ£æ¥å·¦é» |
| | | if (j > 0) { |
| | | float neighbor = buffer[i * size + (j - 1)]; |
| | | if (neighbor > MIN_VAL) { |
| | | sum += neighbor; |
| | | count++; |
| | | } |
| | | } |
| | | // æ£æ¥å³é» |
| | | if (j < size - 1) { |
| | | float neighbor = buffer[i * size + (j + 1)]; |
| | | if (neighbor > MIN_VAL) { |
| | | sum += neighbor; |
| | | count++; |
| | | } |
| | | } |
| | | // è®¡ç®æ°å¼ |
| | | if (count > 0) { |
| | | tempBuffer[index] = (sum / count) * 0.5f; |
| | | } else { |
| | | tempBuffer[index] = 0; |
| | | } |
| | | } else { |
| | | tempBuffer[index] = current; |
| | | } |
| | | } |
| | | } |
| | | // å°ä¸´æ¶æ°ç»å¤å¶ååæ°ç» |
| | | //System.arraycopy(tempBuffer, 0, buffer, 0, tempBuffer.length); |
| | | return tempBuffer; |
| | | } |
| | | |
| | | public List<BuildingDepthVo> processBuilding(ResultDto dto, List<String> files, LayerDto layer) { |
| | |
| | | int offset = x + y * width; |
| | | float fx = ComHelper.getFloatValue(vxBuffer[offset]); |
| | | float fy = ComHelper.getFloatValue(vyBuffer[offset]); |
| | | if (Float.isNaN(fx) && Float.isNaN(fy) || (fx == 0.00001 && fy == 0.00001)) continue; |
| | | if (Float.isNaN(fx) && Float.isNaN(fy) || (fx < MIN_VAL && fy < MIN_VAL)) continue; |
| | | |
| | | fx = Float.isNaN(fx) ? 0 : fx; |
| | | fy = Float.isNaN(fy) ? 0 : fy; |
| | |
| | | layer.getWaters().setFiles(null); |
| | | layer.getTerrain().setEpsg(null); |
| | | layer.getExtension().setDiffer(null); |
| | | layer.setWaterUrl("/hls/w" + config.getOutPath() + ".m3u8"); |
| | | layer.setFlowUrl("//hls/f" + config.getOutPath() + ".m3u8"); |
| | | layer.setWaterUrl("/hls/w" + dto.getOutPath() + ".m3u8"); |
| | | layer.setFlowUrl("/hls/f" + dto.getOutPath() + ".m3u8"); |
| | | |
| | | String json = JSON.toJSONString(layer); |
| | | // String json = JSONUtil.toJsonPrettyStr(layer); |
| | |
| | | flowUnits: CMS |
| | | solverBat: D:\other\simu\uwsolver\run_solver.bat |
| | | sww2tifBat: D:\other\simu\uwsolver\sww2tif.bat |
| | | #sizes: 64,128,256,512,1024,2048 |
| | | sizes: 1024,2048,4096 |
| | | #sizes: 64,128,256,512,1024,2048,4096 |
| | | sizes: 1024 |
| | | # è¾åºæä»¶ |
| | | terrainFile: DEM.tif |
| | | buildingFile: buildings_inside.shp |