From dc0601492c12ea8009ab0e47ff25ec0e78f60903 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期六, 02 十一月 2024 08:29:14 +0800 Subject: [PATCH] 添加查询建筑物涉水深度接口 --- src/main/java/com/se/simu/service/ResultService.java | 62 ++++++++++++++++++++----------- 1 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/se/simu/service/ResultService.java b/src/main/java/com/se/simu/service/ResultService.java index f7796cb..40b1634 100644 --- a/src/main/java/com/se/simu/service/ResultService.java +++ b/src/main/java/com/se/simu/service/ResultService.java @@ -8,6 +8,7 @@ import com.se.simu.domain.dto.LayerDto; import com.se.simu.domain.dto.ResultDto; import com.se.simu.domain.po.DataPo; +import com.se.simu.domain.vo.BuildingDepthVo; import com.se.simu.helper.GdalHelper; import lombok.extern.slf4j.Slf4j; import org.gdal.gdal.Band; @@ -17,6 +18,7 @@ import org.gdal.gdalconst.gdalconst; import org.gdal.ogr.*; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import javax.imageio.ImageIO; @@ -44,6 +46,8 @@ PropertiesConfig config; public final static double MAX_X_OFFSET = 0; + + private 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; @@ -348,6 +352,7 @@ if (null == ds || 0 == ds.getRasterCount()) return; createWaterPng(dto, ds, layer, layer.getWaters().getData().get(i)); + copyWaterTif(dto, ds, layer.getWaters().getData().get(i)); } finally { if (null != ds) ds.delete(); } @@ -368,6 +373,12 @@ String png = waterPath + File.separator + sizes[0] + "_" + sizes[1] + ".png"; water2Png(dto, layer, tif, png, sizes[0], sizes[1]); } + } + + private static 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 static String getNameWithExt(String file) { @@ -521,14 +532,10 @@ layer.getTerrain().setEpsg(null); String json = JSON.toJSONString(layer); - //String json = JSONUtil.toJsonPrettyStr(layer); + // String json = JSONUtil.toJsonPrettyStr(layer); String filePath = dto.getOutPath() + File.separator + "layer.json"; - FileWriter fw = new FileWriter(filePath); - BufferedWriter bw = new BufferedWriter(fw); - bw.write(json); - bw.close(); - fw.close(); + writeJson(filePath, json); } /** @@ -538,28 +545,39 @@ String rainGageFilePath = config.getInPath() + File.separator + dto.getServiceName() + File.separator + "RainGage.dat"; String filePath = dto.getOutPath() + File.separator + "rainfall.json"; - String line; - Map<String, Double> rainFallJsons = new LinkedHashMap<>(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + Map<String, Double> map = new LinkedHashMap<>(); + FileReader fr = new FileReader(rainGageFilePath); + BufferedReader br = new BufferedReader(fr); - BufferedReader br = new BufferedReader(new FileReader(rainGageFilePath)); - // 澶勭悊绗竴琛屾暟鎹� - if ((line = br.readLine()) != null) { - while ((line = br.readLine()) != null) { - // 澶勭悊姣忎竴琛屾暟鎹� - String[] rainFall = line.split(" "); + String line = br.readLine(); + while ((line = br.readLine()) != null) { + String[] rainFall = line.split(" "); + if (rainFall.length < 7) continue; - if (rainFall.length < 7) continue; - - String sdt = rainFall[1] + "-" + rainFall[2] + "-" + rainFall[3] + " " + rainFall[4] + ":" + rainFall[5]; - BigDecimal num = new BigDecimal(rainFall[6]); - rainFallJsons.put("" + sdf.parse(sdt).getTime(), num.setScale(2, RoundingMode.HALF_UP).doubleValue()); - } + String sdt = rainFall[1] + "-" + rainFall[2] + "-" + rainFall[3] + " " + rainFall[4] + ":" + rainFall[5]; + BigDecimal num = new BigDecimal(rainFall[6]); + map.put("" + SDF.parse(sdt).getTime(), num.setScale(2, RoundingMode.HALF_UP).doubleValue()); } + br.close(); + fr.close(); + String json = JSON.toJSONString(map); + writeJson(filePath, json); + } + + private void copeBuildingDepthJson(ResultDto dto, List<BuildingDepthVo> list) throws IOException { + if (CollectionUtils.isEmpty(list)) return; + + String json = JSON.toJSONString(list); + String filePath = dto.getOutPath() + File.separator + "building.json"; + + writeJson(filePath, json); + } + + private void writeJson(String filePath, String json) throws IOException { FileWriter fw = new FileWriter(filePath); BufferedWriter bw = new BufferedWriter(fw); - bw.write(JSON.toJSONString(rainFallJsons)); + bw.write(json); bw.close(); fw.close(); } -- Gitblit v1.9.3