| | |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.se.nsl.config.PropertiesConfig; |
| | | import com.se.nsl.domain.dto.Zarr2Tif; |
| | | import com.se.nsl.domain.po.Rainfall; |
| | | import com.se.nsl.domain.po.Simu; |
| | | import com.se.nsl.domain.po.SimuData; |
| | |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.nio.charset.StandardCharsets; |
| | |
| | | /** |
| | | * 调用zarr2tif |
| | | */ |
| | | private String callZarr2tif(SimuData data) throws Exception { |
| | | String zarr2tifBat = config.getZarr2tifBat(); |
| | | File dir = new File(zarr2tifBat).getParentFile(); |
| | | String configJson = new File(dir, "config.json").getAbsolutePath(); |
| | | public String callZarr2tif(SimuData data) throws Exception { |
| | | String inPath = config.getInPath() + File.separator + data.getInPath(); |
| | | String zarrFile = inPath + File.separator + "result.zarr"; |
| | | String geotiffDir = inPath + File.separator + "depth"; |
| | | String terrainFile = inPath + File.separator + config.getDemFile(); |
| | | String jsonPath = inPath + File.separator + "zarr2tif.json"; |
| | | |
| | | String cmd = String.format("%s \"%s\"", zarr2tifBat, configJson); |
| | | String res = callBat(cmd); |
| | | Zarr2Tif zarr2Tif = new Zarr2Tif(zarrFile, geotiffDir, terrainFile, data.getStartTime()); |
| | | ComHelper.writeJson(jsonPath, JSON.toJSONString(zarr2Tif)); |
| | | |
| | | File resultTifDir = new File(dir, "result_tif"); |
| | | File targetDir = new File(config.getInPath(), data.getInPath() + File.separator + "depth"); |
| | | System.out.println("targetDir:" + targetDir); |
| | | File[] files = resultTifDir.listFiles(); |
| | | for (File file : files) { |
| | | File target = new File(targetDir, file.getName()); |
| | | Files.copy(file.toPath(), target.toPath()); |
| | | String cmd = String.format("%s \"%s\"", config.getZarr2tifBat(), jsonPath); |
| | | |
| | | return callBat2(cmd); |
| | | } |
| | | |
| | | private String callBat2(String cmd) { |
| | | try { |
| | | ProcessBuilder pb = new ProcessBuilder("cmd", "/c", cmd); |
| | | pb.redirectErrorStream(true); // 合并错误流到标准输出 |
| | | |
| | | Process process = pb.start(); |
| | | process.getOutputStream().close(); |
| | | |
| | | //StringBuilder sb = new StringBuilder(); |
| | | try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"))) { |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | System.out.println(line); |
| | | //sb.append(line); |
| | | } |
| | | } |
| | | |
| | | int exitCode = process.waitFor(); |
| | | |
| | | return "ok"; // sb.toString(); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return null; |
| | | } |
| | | |
| | | return res; |
| | | } |
| | | |
| | | /*private String callZarr2tif(SimuData data) throws Exception { |