| | |
| | | copeTerrain(dto, layer); |
| | | //copeBuilding(dto, layer); |
| | | List<BuildingDepthVo> buildings = copeWater(dto, layer); |
| | | //copeFlow(dto, layer); |
| | | copeFlow(dto, layer); |
| | | copeLayerJson(dto, layer); |
| | | //copeRainFallJson(dto, layer); |
| | | //copeBuildingDepthJson(dto, buildings); |
| | |
| | | } |
| | | |
| | | public void copeFlow(ResultDto dto, LayerDto layer) { |
| | | List<String> files = getFiles(dto.getFlowPath(), ".tif"); |
| | | if (null == files || files.size() != layer.getWaters().getData().size()) return; |
| | | |
| | | List<String> files = layer.getWaters().getFiles(); |
| | | if (null == files || files.isEmpty()) return; |
| | | for (int i = 0, c = files.size(); i < c; i++) { |
| | | Dataset ds = null; |
| | | try { |
| | |
| | | ds = gdal.Open(tif, gdalconstConstants.GA_ReadOnly); |
| | | if (null == ds || 0 == ds.getRasterCount()) return; |
| | | |
| | | float[] depthBuffer = new float[width * height]; |
| | | float[] vxBuffer = new float[width * height]; |
| | | float[] vyBuffer = new float[width * height]; |
| | | |
| | | ds.GetRasterBand(1).ReadRaster(0, 0, width, height, depthBuffer); |
| | | ds.GetRasterBand(2).ReadRaster(0, 0, width, height, vxBuffer); |
| | | ds.GetRasterBand(3).ReadRaster(0, 0, width, height, vyBuffer); |
| | | |
| | | createFlowPng(depthBuffer, vxBuffer, vyBuffer, png, width, height); |
| | | } finally { |
| | | if (null != ds) ds.delete(); |
| | | } |
| | | } |
| | | |
| | | public void createFlowPng(float[] depthBuffer, 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++) { |
| | | int offset = x + y * width; |
| | | float depth = ComHelper.getFloatValue(depthBuffer[offset]); |
| | | float fx = ComHelper.getFloatValue(vxBuffer[offset]); |
| | | float fy = ComHelper.getFloatValue(vyBuffer[offset]); |
| | | if (Float.isNaN(fx) && Float.isNaN(fy) || (fx < MIN_VAL && fy < MIN_VAL)) continue; |
| | | |
| | | if (depth == 0) { |
| | | fx = 0f; |
| | | fy = 0f; |
| | | } else { |
| | | fx = Float.isNaN(fx) ? 0 : fx / depth; |
| | | fy = Float.isNaN(fy) ? 0 : fy / depth; |
| | | } |
| | | double dr = Math.sqrt(Math.pow(fx, 2) + Math.pow(fy, 2)); |
| | | |
| | | int r = (int) (dr / 4 * 255); |
| | | int g = (int) ((fx / dr * 0.5 + 0.5) * 255); |
| | | int b = (int) ((fy / dr * 0.5 + 0.5) * 255); |
| | | |
| | | Color color = new Color(ComHelper.getSafeValue(r), ComHelper.getSafeValue(g), ComHelper.getSafeValue(b), 127); |
| | | image.setRGB(x, y, color.getRGB()); |
| | | } |
| | | } |
| | | ComHelper.savePng(image, png); |
| | | } |
| | | |
| | | /* |
| | | public void vxyTif2Png(LayerDto layer, String tif, String png, int width, int height) { |
| | | Dataset ds = null; |
| | | try { |
| | | ds = gdal.Open(tif, gdalconstConstants.GA_ReadOnly); |
| | | if (null == ds || 0 == ds.getRasterCount()) return; |
| | | |
| | | float[] vxBuffer = new float[width * height], vyBuffer = new float[width * height]; |
| | | ds.GetRasterBand(1).ReadRaster(0, 0, width, height, vxBuffer); |
| | | ds.GetRasterBand(2).ReadRaster(0, 0, width, height, vyBuffer); |
| | | ds.GetRasterBand(2).ReadRaster(0, 0, width, height, vxBuffer); |
| | | ds.GetRasterBand(3).ReadRaster(0, 0, width, height, vyBuffer); |
| | | |
| | | createFlowPng(vxBuffer, vyBuffer, png, width, height); |
| | | } finally { |
| | | if (null != ds) ds.delete(); |
| | | } |
| | | } |
| | | */ |
| | | |
| | | public 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); |
| | | } |
| | | }*/ |
| | | |
| | | public void copeLayerJson(ResultDto dto, LayerDto layer) throws IOException { |
| | | layer.getWaters().setFiles(null); |