| | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | | import java.util.stream.DoubleStream; |
| | | |
| | | /** |
| | | * 处理结果服务类 |
| | |
| | | try { |
| | | copeTerrain(dto, layer); |
| | | copeBuilding(dto, layer); |
| | | copeWater(dto, layer); |
| | | List<BuildingDepthVo> buildings = copeWater(dto, layer); |
| | | copeFlow(dto, layer); |
| | | copeLayerJson(dto, layer); |
| | | copeRainFallJson(dto, layer); |
| | | copeBuildingDepthJson(dto, buildings); |
| | | } finally { |
| | | File dir = new File(dto.getTemp()); |
| | | if (dir.exists()) { |
| | |
| | | setWaterHeight(layer, files); |
| | | } |
| | | |
| | | private void copeWater(ResultDto dto, LayerDto layer) { |
| | | private List<BuildingDepthVo> copeWater(ResultDto dto, LayerDto layer) { |
| | | List<String> files = layer.getWaters().getFiles(); |
| | | if (files.size() == 0 || files.size() != layer.getWaters().getData().size()) return; |
| | | if (files.size() == 0 || files.size() != layer.getWaters().getData().size()) return null; |
| | | |
| | | processWaters(dto, files, layer); |
| | | |
| | | return processBuilding(dto, files, layer); |
| | | } |
| | | |
| | | private static List<String> getFiles(String path, String suffix) { |
| | |
| | | int offset = x + y * width; |
| | | if (Float.isNaN(buffer[offset]) || buffer[offset] < -999 || buffer[offset] < minHeight) continue; |
| | | |
| | | double X = transform[0] + x * transform[1] + y * transform[2]; |
| | | double Y = transform[3] + x * transform[4] + y * transform[5]; |
| | | //double X = transform[0] + x * transform[1] + y * transform[2]; |
| | | //double Y = transform[3] + x * transform[4] + y * transform[5]; |
| | | //BuildingDto building = intersects(dto, X, Y); |
| | | //if (null != building) continue; |
| | | |
| | |
| | | return dto.getBuildingList().parallelStream().filter(b -> b.getGeom().Intersects(p)).findFirst().orElse(null); |
| | | } |
| | | |
| | | private 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; |
| | | try { |
| | | ds = gdal.Open(files.get(i), gdalconst.GA_ReadOnly); |
| | | if (null == ds || 0 == ds.getRasterCount()) continue; |
| | | if (null == ds.GetSpatialRef()) ds.SetSpatialRef(dto.getSpatialReference()); |
| | | |
| | | copeBuildingDepth(dto, ds, layer.getWaters().getData().get(i), list); |
| | | } finally { |
| | | if (null != ds) ds.delete(); |
| | | } |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | private 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]); |
| | | |
| | | for (BuildingDto building : dto.getBuildingList()) { |
| | | Double val = getValue(ds, building, xSize, ySize, minX, maxY, pixelWidth, pixelHeight); |
| | | list.add(new BuildingDepthVo(building.getId(), ticks, null)); |
| | | } |
| | | } |
| | | |
| | | private 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); |
| | | |
| | | int xMinPixel = Math.max((int) Math.floor((env[0] - minX) / pixelWidth), 1); |
| | | int yMinPixel = Math.max((int) Math.floor((maxY - env[3]) / pixelHeight), 1); |
| | | int xMaxPixel = Math.min((int) Math.floor((env[1] - minX) / pixelWidth), xSize); |
| | | int yMaxPixel = Math.min((int) Math.floor((maxY - env[2]) / pixelHeight), ySize); |
| | | if (xMaxPixel < 1 || yMaxPixel < 1 || xMaxPixel - xMinPixel < 0 || yMaxPixel - yMinPixel < 0) { |
| | | return null; |
| | | } |
| | | |
| | | int width = xMaxPixel - xMinPixel; |
| | | int height = yMaxPixel - yMinPixel; |
| | | double[] pixelValues = new double[width * height]; |
| | | ds.GetRasterBand(1).ReadRaster(xMinPixel, yMinPixel, width, height, pixelValues); |
| | | |
| | | Double val = Arrays.stream(pixelValues).max().getAsDouble(); |
| | | |
| | | return isValid(val) ? val : null; |
| | | } |
| | | |
| | | public static boolean isValid(Double val) { |
| | | return !Double.isNaN(val) && val > Integer.MIN_VALUE; |
| | | } |
| | | |
| | | private void copeFlow(ResultDto dto, LayerDto layer) { |
| | | List<String> files = getFiles(dto.getFlowPath(), ".tif"); |
| | | if (null == files || files.size() != layer.getWaters().getData().size()) return; |