| | |
| | | |
| | | private String keyDitch; |
| | | |
| | | private Double saveFilter; |
| | | |
| | | public String getVer() { |
| | | return ver; |
| | | } |
| | |
| | | public void setKeyDitch(String keyDitch) { |
| | | this.keyDitch = keyDitch; |
| | | } |
| | | |
| | | public Double getSaveFilter() { |
| | | return saveFilter; |
| | | } |
| | | |
| | | public void setSaveFilter(Double saveFilter) { |
| | | this.saveFilter = saveFilter; |
| | | } |
| | | } |
| | |
| | | if (lat > 90 || lat < -90) { |
| | | return clientError("纬度范围应该在-90到90"); |
| | | } |
| | | if (time == null) { |
| | | return clientError("时间戳不能为空"); |
| | | } |
| | | if (serviceName == null || serviceName.trim().isEmpty()) { |
| | | return clientError("服务名不能为空"); |
| | | } |
| | | SimuResult result = simuService.queryByPosition(lon, lat, time, serviceName); |
| | | if (result == null) { |
| | | return notFound("未查找到相关数据"); |
| | | if (time != null) { |
| | | SimuResult result = simuService.queryByPosition(lon, lat, time, serviceName); |
| | | if (result == null) { |
| | | return notFound("未查找到相关数据"); |
| | | } |
| | | return success(result, 1); |
| | | } else { |
| | | List<SimuResult> simuResults = simuService.queryByPosition(lon, lat, serviceName); |
| | | if (simuResults.isEmpty()) { |
| | | return notFound("未查找到相关数据"); |
| | | } |
| | | return success(simuResults, simuResults.size()); |
| | | } |
| | | return success(result); |
| | | } |
| | | |
| | | @ApiOperation(value = "realTime") |
| | |
| | | public ResultVo() { |
| | | this.save_variables = new ArrayList<>(Arrays.asList("depth", "xmomentum", "ymomentum")); |
| | | this.save_start = 0; |
| | | this.save_filter = 0.005D; |
| | | this.save_filter = 0.015D; |
| | | } |
| | | |
| | | public ResultVo(String saveName, int frames, int saveInterval, |
| | |
| | | |
| | | private double depth; |
| | | private double velocity; |
| | | private long time; |
| | | |
| | | public double getDepth() { |
| | | return depth; |
| | |
| | | public void setVelocity(double velocity) { |
| | | this.velocity = velocity; |
| | | } |
| | | |
| | | public long getTime() { |
| | | return time; |
| | | } |
| | | |
| | | public void setTime(long time) { |
| | | this.time = time; |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | public static void Resample(Dataset ds, String dest, int width, int height, LayerDto layer) { |
| | | public static void cutAndResample(Dataset ds, String dest, int width, int height, |
| | | LayerDto layer, boolean resample) { |
| | | Vector<String> vector = new Vector<>(); |
| | | //vector.add("-s_srs"); |
| | | //vector.add("EPSG:" + 4548); |
| | |
| | | //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"); |
| | | if (resample) { |
| | | 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(); |
| | | } |
| | | |
| | | public static void Resample(Dataset ds, Integer targetEpsg, String dest, Double destNoData, String wkt, Integer width, Integer height) { |
| | | public static void cutAndResample(Dataset ds, Integer targetEpsg, String dest, Double destNoData, String wkt, Integer width, Integer height) { |
| | | Vector<String> vector = new Vector<>(); |
| | | if (targetEpsg != null) { |
| | | //vector.add("-s_srs"); |
| | |
| | | if (null != destDs) destDs.delete(); |
| | | } |
| | | |
| | | public static void Resample2(Dataset ds, String dest, int width, int height, LayerDto layer) { |
| | | public static void coordinateTransformAndResample(Dataset ds, String dest, int width, int height, |
| | | LayerDto layer, boolean resample) { |
| | | Vector<String> vector = new Vector<>(); |
| | | vector.add("-s_srs"); |
| | | vector.add("EPSG:" + 4548); |
| | |
| | | //vector.add("" + layer.getExtension().getMaxy()); |
| | | //vector.add("-te_srs"); |
| | | //vector.add("EPSG:" + 4326); |
| | | vector.add("-r"); |
| | | if (resample) { |
| | | vector.add("-r"); |
| | | // vector.add("average"); |
| | | vector.add("cubic"); |
| | | vector.add("-of"); |
| | | vector.add("GTiff"); |
| | | vector.add("cubic"); |
| | | vector.add("-of"); |
| | | vector.add("GTiff"); |
| | | } |
| | | WarpOptions warpOptions = new WarpOptions(vector); |
| | | |
| | | Dataset destDs = gdal.Warp(dest, new Dataset[]{ds}, warpOptions); |
| | |
| | | String terrainFile = inPath + File.separator + config.getTerrainFile(); |
| | | |
| | | Dataset dsDem = gdal.Open(terrainTif, gdalconstConstants.GA_ReadOnly); |
| | | ComHelper.Resample(dsDem, null, terrainFile, null, wkt, null, null); |
| | | ComHelper.cutAndResample(dsDem, null, terrainFile, null, wkt, null, null); |
| | | dsDem.delete(); |
| | | |
| | | String landuseFile = inPath + File.separator + config.getLanduseFile(); |
| | | |
| | | Dataset dsLanduse = gdal.Open(landuseTif, gdalconstConstants.GA_ReadOnly); |
| | | ComHelper.Resample(dsLanduse, null, landuseFile, null, wkt, null, null); |
| | | ComHelper.cutAndResample(dsLanduse, null, landuseFile, null, wkt, null, null); |
| | | dsLanduse.delete(); |
| | | |
| | | if (stationTif != null) { |
| | | String stationFile = inPath + File.separator + "Station.tif"; |
| | | Dataset dsStation = gdal.Open(stationTif, gdalconstConstants.GA_ReadOnly); |
| | | ComHelper.Resample(dsStation, null, stationFile, null, wkt, null, null); |
| | | ComHelper.cutAndResample(dsStation, null, stationFile, null, wkt, null, null); |
| | | dsStation.delete(); |
| | | } |
| | | } |
| | |
| | | String startTime = TimeFormatUtil.formatDate(data.getStartTime()); |
| | | ConfigVo vo = new ConfigVo(terrainFile, landuseFile, terrainFile, rainfallFile, |
| | | saveName, duration, saveFrames, saveMode, startTime); |
| | | vo.getResult().setSave_filter(config.getSaveFilter()); |
| | | String configFile = config.getInPath() + File.separator + data.getInPath() + File.separator + data.getInPath() + ".json"; |
| | | // ComHelper.writeJson(configFile, JSON.toJSONString(vo)); |
| | | mapper.writeValue(new File(configFile), vo); |
| | |
| | | |
| | | for (int[] sizes : layer.getTerrain().getSize()) { |
| | | String tif = dto.getTemp() + File.separator + "terrain_" + sizes[0] + "_" + sizes[1] + ".tif"; |
| | | ComHelper.Resample(ds, tif, sizes[0], sizes[1], layer); |
| | | ComHelper.cutAndResample(ds, tif, sizes[0], sizes[1], layer, false); |
| | | if (!new File(tif).exists()) continue; |
| | | |
| | | String png = terrainPath + File.separator + sizes[0] + "_" + sizes[1] + ".png"; |
| | |
| | | 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.cutAndResample(ds, tif, sizes[0], sizes[1], layer, false); |
| | | if (!new File(tif).exists()) continue; |
| | | |
| | | String png = waterPath + File.separator + sizes[0] + "_" + sizes[1] + ".png"; |
| | |
| | | for (int[] sizes : layer.getTerrain().getSize()) { |
| | | String name = ComHelper.getNameWithExt(ds.GetDescription()) + "_" + sizes[0] + "_" + sizes[1]; |
| | | String tif = dto.getTemp() + File.separator + name + ".tif"; |
| | | ComHelper.Resample(ds, tif, sizes[0], sizes[1], layer); |
| | | ComHelper.cutAndResample(ds, tif, sizes[0], sizes[1], layer, false); |
| | | if (!new File(tif).exists()) continue; |
| | | |
| | | String png = flowPath + File.separator + sizes[0] + "_" + sizes[1] + ".png"; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.time.Instant; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | |
| | | @SuppressWarnings("ALL") |
| | | public class SimuService { |
| | | public static final String TIF_EXTSION = ".tif"; |
| | | public static final String YYYY_MM_DD_HHMMSS = "yyyyMMddHHmmss"; |
| | | @Resource |
| | | SimuMapper simuMapper; |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | public List<SimuResult> queryByPosition(double lon, double lat, String serviceName) { |
| | | //transform coordiante from 4326 to 4548 |
| | | double[] xy = CoordinateTransformer.transform(4326, 4548, lon, lat); |
| | | // System.out.println(String.format("转换前的坐标:x:%s,y:%s", lon, lat)); |
| | | // System.out.println(String.format("转换后的坐标:x:%s,y:%s", xy[0], xy[1])); |
| | | //read from zarr |
| | | // return queryByZarr(xy, time, serviceName); |
| | | |
| | | //read from tif file |
| | | return queryByTif(xy, serviceName); |
| | | |
| | | } |
| | | |
| | | private SimuResult queryByZarr(double[] xy, long time, String serviceName) { |
| | | double x = xy[0]; |
| | | double y = xy[1]; |
| | |
| | | SimuResult result = new SimuResult(); |
| | | result.setDepth(depth); |
| | | result.setVelocity(velocity); |
| | | result.setTime(time); |
| | | return result; |
| | | } |
| | | |
| | | private List<SimuResult> queryByTif(double[] xy, String serviceName) { |
| | | double x = xy[0]; |
| | | double y = xy[1]; |
| | | List<SimuResult> res = new ArrayList<>(); |
| | | File inPath = new File(config.getInPath()); |
| | | Path depthPath = Paths.get(inPath.getAbsolutePath(), serviceName, "depth"); |
| | | File depthDir = depthPath.toFile(); |
| | | File[] files = depthDir.listFiles(); |
| | | for (File tifFile : files) { |
| | | ColumnRow cr = getColumnRow(tifFile, x, y); |
| | | if (cr == null) continue; |
| | | float depth = readPixelValue(cr.dataset, cr.col, cr.row, 1); |
| | | float velocity = calcVelocity(cr.dataset, cr.col, cr.row); |
| | | SimuResult result = new SimuResult(); |
| | | result.setDepth(depth); |
| | | result.setVelocity(velocity); |
| | | String time = tifFile.getName().replace(".tif", ""); |
| | | result.setTime(TimeFormatUtil.toMillis(time, YYYY_MM_DD_HHMMSS)); |
| | | res.add(result); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | private static ColumnRow getColumnRow(File tifFile, double x, double y) { |
| | |
| | | } |
| | | |
| | | private String formatTime(long time) { |
| | | // Instant instant = Instant.ofEpochMilli(time); |
| | | // LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); |
| | | // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); |
| | | // return localDateTime.format(formatter); |
| | | return TimeFormatUtil.formatTime(time, "yyyyMMddHHmmss"); |
| | | return TimeFormatUtil.formatTime(time, YYYY_MM_DD_HHMMSS); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | for (int[] sizes : layer.getTerrain().getSize()) { |
| | | String tif = dto.getTemp() + File.separator + "terrain_" + sizes[0] + "_" + sizes[1] + ".tif"; |
| | | ComHelper.Resample(ds, tif, sizes[0], sizes[1], layer); |
| | | ComHelper.cutAndResample(ds, tif, sizes[0], sizes[1], layer, true); |
| | | if (!new File(tif).exists()) continue; |
| | | |
| | | String png = terrainPath + File.separator + sizes[0] + "_" + sizes[1] + ".png"; |
| | |
| | | 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.Resample2(ds, tif, sizes[0], sizes[1], layer); |
| | | ComHelper.coordinateTransformAndResample(ds, tif, sizes[0], sizes[1], layer, true); |
| | | if (!new File(tif).exists()) continue; |
| | | |
| | | String png = waterPath + File.separator + sizes[0] + "_" + sizes[1] + ".png"; |
| | |
| | | for (int[] sizes : layer.getTerrain().getSize()) { |
| | | String name = ComHelper.getNameWithExt(ds.GetDescription()) + "_" + sizes[0] + "_" + sizes[1]; |
| | | String tif = dto.getTemp() + File.separator + name + ".tif"; |
| | | // ComHelper.Resample(ds, tif, sizes[0], sizes[1], layer); |
| | | if (!new File(tif).exists()) continue; |
| | | |
| | | String png = flowPath + File.separator + sizes[0] + "_" + sizes[1] + ".png"; |
| | |
| | | # saveFrames: 3 |
| | | #生成帧数的间隔时间,单位是分钟,设置为5表示每隔5分钟生成一帧 |
| | | saveFrameInterval: 20 |
| | | saveFilter: 0.015 |
| | | # 土地利用:1-Cropland,2-Forest,3-Shrub,4-Grassland,5-Water,6-Snow/Ice,7-Barren,8-Impervious,9-Wetland |
| | | landuse: 2 |
| | | #sizes: 64,128,256,512,1024,2048,4096 |