| | |
| | | |
| | | public final static double MAX_X_OFFSET = 0; |
| | | |
| | | private final static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
| | | public final static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
| | | |
| | | public void process(DataPo data) throws Exception { |
| | | String basePath = config.getInPath() + File.separator + data.getInPath() + File.separator; |
| | |
| | | process(dto, layer); |
| | | } |
| | | |
| | | private void process(ResultDto dto, LayerDto layer) throws Exception { |
| | | public void process(ResultDto dto, LayerDto layer) throws Exception { |
| | | try { |
| | | copeTerrain(dto, layer); |
| | | copeBuilding(dto, layer); |
| | |
| | | } |
| | | } |
| | | |
| | | private void copeTerrain(ResultDto dto, LayerDto layer) { |
| | | public void copeTerrain(ResultDto dto, LayerDto layer) { |
| | | Dataset ds = null; |
| | | try { |
| | | ds = gdal.Open(dto.getTerrainFile(), gdalconst.GA_ReadOnly); |
| | |
| | | } |
| | | } |
| | | |
| | | private void setTerrainInfo(Dataset ds, LayerDto layer) { |
| | | public void setTerrainInfo(Dataset ds, LayerDto layer) { |
| | | Geometry minPoint = GdalHelper.getMinPoint(ds); |
| | | Geometry maxPoint = GdalHelper.getMaxPoint(ds); |
| | | double minx = ComHelper.getMinVal(minPoint.GetX(0), 10000000); |
| | |
| | | layer.setExtension(new ExtensionDto(minx, miny, maxx, maxy, mm[0], mm[1])); |
| | | } |
| | | |
| | | private void createTerrainPng(ResultDto dto, Dataset ds, LayerDto layer) { |
| | | public 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"; |
| | | 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"; |
| | |
| | | } |
| | | } |
| | | |
| | | private void Terrain2Png(LayerDto layer, String tif, String png, int width, int height) { |
| | | public void Terrain2Png(LayerDto layer, String tif, String png, int width, int height) { |
| | | Dataset ds = null; |
| | | try { |
| | | ds = gdal.Open(tif, gdalconst.GA_ReadOnly); |
| | |
| | | } |
| | | } |
| | | |
| | | private void copeBuilding(ResultDto dto, LayerDto layer) { |
| | | public void copeBuilding(ResultDto dto, LayerDto layer) { |
| | | Driver driver = null; |
| | | DataSource dataSource = null; |
| | | Layer shpLayer = null; |
| | |
| | | } |
| | | } |
| | | |
| | | private void setWaterInfo(ResultDto dto, LayerDto layer) { |
| | | public void setWaterInfo(ResultDto dto, LayerDto layer) { |
| | | List<String> files = getFiles(dto.getWaterPath(), ".tif"); |
| | | layer.getWaters().setFiles(files); |
| | | if (null == files || files.size() == 0) return; |
| | |
| | | setWaterHeight(layer, files); |
| | | } |
| | | |
| | | private List<BuildingDepthVo> copeWater(ResultDto dto, LayerDto layer) { |
| | | public List<BuildingDepthVo> copeWater(ResultDto dto, LayerDto layer) { |
| | | List<String> files = layer.getWaters().getFiles(); |
| | | if (files.size() == 0 || files.size() != layer.getWaters().getData().size()) return null; |
| | | |
| | |
| | | return processBuilding(dto, files, layer); |
| | | } |
| | | |
| | | private List<String> getFiles(String path, String suffix) { |
| | | public List<String> getFiles(String path, String suffix) { |
| | | List<String> files = new ArrayList<>(); |
| | | ComHelper.getFiles(files, new File(path), suffix); |
| | | files.sort((a, b) -> a.compareToIgnoreCase(b)); |
| | |
| | | return files; |
| | | } |
| | | |
| | | private void setWaterData(LayerDto layer, List<String> files) { |
| | | public void setWaterData(LayerDto layer, List<String> files) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(new Date()); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | |
| | | layer.getDuration().setEnd(layer.getWaters().getData().get(layer.getWaters().getData().size() - 1)); |
| | | } |
| | | |
| | | private void setWaterHeight(LayerDto layer, List<String> files) { |
| | | public void setWaterHeight(LayerDto layer, List<String> files) { |
| | | files.parallelStream().forEach(file -> { |
| | | Dataset ds = null; |
| | | try { |
| | |
| | | layer.getExtension().setDiffer(); |
| | | } |
| | | |
| | | private void processWaters(ResultDto dto, List<String> files, LayerDto layer) { |
| | | public void processWaters(ResultDto dto, List<String> files, LayerDto layer) { |
| | | for (int i = 0, c = files.size(); i < c; i++) { |
| | | Dataset ds = null; |
| | | try { |
| | |
| | | } |
| | | } |
| | | |
| | | private void createWaterPng(ResultDto dto, Dataset ds, LayerDto layer, long ticks) { |
| | | public 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 = 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"; |
| | |
| | | } |
| | | } |
| | | |
| | | private void water2Png(ResultDto dto, LayerDto layer, String tif, String png, int width, int height) { |
| | | public 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); |
| | |
| | | } |
| | | } |
| | | |
| | | private List<BuildingDepthVo> processBuilding(ResultDto dto, List<String> files, LayerDto layer) { |
| | | public List<BuildingDepthVo> processBuilding(ResultDto dto, List<String> files, LayerDto layer) { |
| | | List<BuildingDepthVo> list = new CopyOnWriteArrayList<>(); |
| | | for (int i = 0, c = files.size(); i < c; i++) { |
| | | Dataset ds = null; |
| | |
| | | return list; |
| | | } |
| | | |
| | | private void copeBuildingDepth(ResultDto dto, Dataset ds, long ticks, List<BuildingDepthVo> list) { |
| | | public void copeBuildingDepth(ResultDto dto, Dataset ds, long ticks, List<BuildingDepthVo> list) { |
| | | double[] transform = ds.GetGeoTransform(); |
| | | int xSize = ds.getRasterXSize(), ySize = ds.getRasterYSize(); |
| | | double minX = transform[0], pixelWidth = transform[1], maxY = transform[3], pixelHeight = Math.abs(transform[5]); |
| | |
| | | } |
| | | } |
| | | |
| | | private Double getValue(Dataset ds, BuildingDto building, int xSize, int ySize, double minX, double maxY, double pixelWidth, double pixelHeight) { |
| | | public Double getValue(Dataset ds, BuildingDto building, int xSize, int ySize, double minX, double maxY, double pixelWidth, double pixelHeight) { |
| | | double[] env = new double[4]; |
| | | building.getGeom().GetEnvelope(env); |
| | | |
| | |
| | | return ComHelper.isValid(val) ? val : null; |
| | | } |
| | | |
| | | private void copyWaterTif(ResultDto dto, Dataset ds, long ticks) { |
| | | public 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 void createVectors(ResultDto dto, Dataset ds, LayerDto layer, Long ticks) { |
| | | public void createVectors(ResultDto dto, Dataset ds, LayerDto layer, Long ticks) { |
| | | String filePath = dto.getOutPath() + File.separator + "waters" + File.separator + ticks + File.separator + "polygonize.geojson"; |
| | | ShpHelper.polygonize2Geojson(ds, filePath); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private List<Geometry> getGeometries(String filePath) { |
| | | public List<Geometry> getGeometries(String filePath) { |
| | | if (!FileUtil.exist(filePath)) return null; |
| | | |
| | | Driver driver = null; |
| | |
| | | } |
| | | } |
| | | |
| | | private List<PondingPo> copePonding(ResultDto dto, Dataset ds, LayerDto layer, List<Geometry> geometries) { |
| | | public List<PondingPo> copePonding(ResultDto dto, Dataset ds, LayerDto layer, List<Geometry> geometries) { |
| | | double[] transform = ds.GetGeoTransform(); |
| | | int xSize = ds.getRasterXSize(), ySize = ds.getRasterYSize(); |
| | | |
| | |
| | | return list; |
| | | } |
| | | |
| | | private PointDto getValues(Dataset ds, Geometry g, double[] transform, int xSize, int ySize) { |
| | | public PointDto getValues(Dataset ds, Geometry g, double[] transform, int xSize, int ySize) { |
| | | double[] env = new double[4]; |
| | | g.GetEnvelope(env); |
| | | |
| | |
| | | return new PointDto(g.Centroid().GetX(), g.Centroid().GetY(), ComHelper.isValid(val) ? val : 0.0); |
| | | } |
| | | |
| | | private void copeFlow(ResultDto dto, LayerDto layer) { |
| | | public void copeFlow(ResultDto dto, LayerDto layer) { |
| | | List<String> files = getFiles(dto.getFlowPath(), ".tif"); |
| | | if (null == files || files.size() != layer.getWaters().getData().size()) return; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private void createFlowPng(ResultDto dto, Dataset ds, LayerDto layer, long ticks) { |
| | | public void createFlowPng(ResultDto dto, Dataset ds, 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 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"; |
| | |
| | | } |
| | | } |
| | | |
| | | private void vxyTif2Png(LayerDto layer, String tif, String png, int width, int height) { |
| | | public void vxyTif2Png(LayerDto layer, String tif, String png, int width, int height) { |
| | | Dataset ds = null; |
| | | try { |
| | | ds = gdal.Open(tif, gdalconst.GA_ReadOnly); |
| | |
| | | } |
| | | } |
| | | |
| | | private void createFlowPng(float[] vxBuffer, float[] vyBuffer, String png, int width, int height) { |
| | | public void createFlowPng(float[] vxBuffer, float[] vyBuffer, String png, int width, int height) { |
| | | BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); |
| | | for (int x = 0; x < width; x++) { |
| | | for (int y = 0; y < height; y++) { |
| | |
| | | ComHelper.savePng(image, png); |
| | | } |
| | | |
| | | private void copeLayerJson(ResultDto dto, LayerDto layer) throws IOException { |
| | | public void copeLayerJson(ResultDto dto, LayerDto layer) throws IOException { |
| | | layer.getWaters().setFiles(null); |
| | | layer.getTerrain().setEpsg(null); |
| | | layer.getExtension().setDiffer(null); |
| | |
| | | ComHelper.writeJson(filePath, json); |
| | | } |
| | | |
| | | private void copeBuildingDepthJson(ResultDto dto, List<BuildingDepthVo> list) throws IOException { |
| | | public void copeBuildingDepthJson(ResultDto dto, List<BuildingDepthVo> list) throws IOException { |
| | | if (CollectionUtils.isEmpty(list)) return; |
| | | |
| | | String json = JSON.toJSONString(list); |