| | |
| | | import com.se.nsl.domain.vo.BuildingDepthVo; |
| | | import com.se.nsl.helper.ComHelper; |
| | | import com.se.nsl.helper.GdalHelper; |
| | | import com.se.nsl.utils.TimeFormatUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.gdal.gdal.Band; |
| | | import org.gdal.gdal.Dataset; |
| | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Instant; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | |
| | |
| | | |
| | | public final static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
| | | |
| | | public void test(SimuData data) throws Exception { |
| | | public void test(SimuData data) throws IOException { |
| | | String basePath = config.getInPath() + File.separator + data.getInPath() + File.separator; |
| | | ResultDto dto = new ResultDto( |
| | | data.getInPath(), |
| | |
| | | process(dto, layer); |
| | | } |
| | | |
| | | private void process(ResultDto dto, LayerDto layer) throws Exception { |
| | | private void process(ResultDto dto, LayerDto layer) throws IOException { |
| | | try { |
| | | copeTerrain(dto, layer); |
| | | copeWater(dto, layer); |
| | |
| | | } |
| | | } |
| | | |
| | | public void processRealTime(ResultDto dto, LayerDto layer) throws IOException { |
| | | try { |
| | | copeTerrainRealTime(dto, layer); |
| | | copeWater(dto, layer); |
| | | copeFlow(dto, layer); |
| | | copeLayerJson(dto, layer); |
| | | } finally { |
| | | File dir = new File(dto.getTemp()); |
| | | if (dir.exists()) { |
| | | FileUtil.del(dir); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void copeTerrain(ResultDto dto, LayerDto layer) { |
| | | Dataset ds = null; |
| | | try { |
| | | ds = gdal.Open(dto.getTerrainFile(), gdalconstConstants.GA_ReadOnly); // gdalconst |
| | | if (null == ds || 0 == ds.getRasterCount()) return; |
| | | |
| | | setSizes(ds, layer); |
| | | setTerrainInfo(ds, layer); |
| | | setWaterInfo(dto, layer); |
| | | createTerrainPng(dto, ds, layer); |
| | | } finally { |
| | | if (null != ds) ds.delete(); |
| | | } |
| | | } |
| | | |
| | | private void copeTerrainRealTime(ResultDto dto, LayerDto layer) { |
| | | Dataset ds = null; |
| | | try { |
| | | ds = gdal.Open(dto.getTerrainFile(), gdalconstConstants.GA_ReadOnly); // gdalconst |
| | |
| | | } |
| | | |
| | | public void setWaterData(LayerDto layer, List<String> files) { |
| | | for (String file : files) { |
| | | String fileName = ComHelper.getNameWithExt(file); |
| | | long timestamp = TimeFormatUtil.toMillis(fileName, "yyyyMMddHHmmss"); |
| | | layer.getWaters().getData().add(timestamp); |
| | | } |
| | | layer.getDuration().setStart(layer.getWaters().getData().get(0)); |
| | | layer.getDuration().setEnd(layer.getWaters().getData().get(layer.getWaters().getData().size() - 1)); |
| | | } |
| | | |
| | | /*public void setWaterData(LayerDto layer, List<String> files) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(new Date()); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | |
| | | } |
| | | layer.getDuration().setStart(layer.getWaters().getData().get(0)); |
| | | layer.getDuration().setEnd(layer.getWaters().getData().get(layer.getWaters().getData().size() - 1)); |
| | | } |
| | | }*/ |
| | | |
| | | public void setWaterHeight(LayerDto layer, List<String> files) { |
| | | int c = files.size(), step = files.size() / 10; |
| | |
| | | layer.getExtension().setMaxHeight(ComHelper.getMaxVal(layer.getExtension().getMaxHeight(), 1000000)); |
| | | layer.getExtension().setMinHeight(ComHelper.getMaxVal(layer.getExtension().getMinHeight(), 1000000)); |
| | | layer.getExtension().setDiffer(); |
| | | } |
| | | |
| | | private double[] readTifBbox(Dataset ds) { |
| | | // 1. 获取图像尺寸 |
| | | int width = ds.getRasterXSize(); |
| | | int height = ds.getRasterYSize(); |
| | | |
| | | // 2. 获取GeoTransform参数 |
| | | double[] geoTransform = new double[6]; |
| | | ds.GetGeoTransform(geoTransform); |
| | | |
| | | // 3. 解析GeoTransform参数(经纬度坐标) |
| | | double originLon = geoTransform[0]; // 左上角经度 |
| | | double originLat = geoTransform[3]; // 左上角纬度 |
| | | double pixelWidth = geoTransform[1]; // 经度方向分辨率(度/像素) |
| | | double pixelHeight = geoTransform[5]; // 纬度方向分辨率(度/像素,通常为负) |
| | | |
| | | // 4. 计算四至范围(经纬度) |
| | | double minLon = Math.min(originLon, originLon + width * pixelWidth); |
| | | double maxLon = Math.max(originLon, originLon + width * pixelWidth); |
| | | double minLat = Math.min(originLat, originLat + height * pixelHeight); |
| | | double maxLat = Math.max(originLat, originLat + height * pixelHeight); |
| | | return new double[] {minLon, maxLon, minLat, maxLat}; |
| | | } |
| | | |
| | | public void processWaters(ResultDto dto, List<String> files, LayerDto layer) { |
| | |
| | | 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.Resample(ds, tif, sizes[0], sizes[1], layer); |
| | | if (!new File(tif).exists()) continue; |
| | | |
| | | String png = flowPath + File.separator + sizes[0] + "_" + sizes[1] + ".png"; |
| | |
| | | layer.setFlowUrl("/hls/f" + path + ".m3u8"); |
| | | |
| | | String json = JSON.toJSONString(layer); |
| | | // String json = JSONUtil.toJsonPrettyStr(layer); |
| | | String filePath = dto.getOutPath() + File.separator + "layer.json"; |
| | | // String filePath = dto.getOutPath() + File.separator + "layer.json"; |
| | | String filePath = dto.getOutPath() + File.separator + layer.getName(); |
| | | |
| | | ComHelper.writeJson(filePath, json); |
| | | } |