| | |
| | | -- insert into nsl.simu (name, service_name, type, area_type, area_name, status, geom) values ('预测模拟-0416', '20250416100000', 1, 1, '大兴区', 0, ST_GeomFromText('MULTIPOLYGON(((116.666748 39.639859,116.659403 39.626287,116.665956 39.654698,116.666748 39.639859)))')); |
| | | |
| | | select id,name,service_name,type,area_type,area_name,status,result,create_time,update_time,bak,data,st_astext(geom) from nsl.simu where id > 0 order by id desc; |
| | | -- update nsl.simu set status = 0, area_name = '房山区', data = '{"startTime":"2025-05-01 11:10:54","type":3,"total":50,"duration":6,"intensity":70,"history":"XX年50mm降雨"}' where id = 24; |
| | | -- update nsl.simu set status=0,area_name='房山区',result=null,data = '{"startTime":"2025-05-01 11:10:54","type":3,"total":50,"duration":6,"intensity":70,"history":"XX年50mm降雨"}' where id = 17; |
| | | -- {"startTime":"2025-05-01 10:51:33","type":3,"total":1025,"duration":96,"intensity":78.5,"rainfalls":[{"time":"2023-07-29 22:00:00","intensity":"2","total":"2"},{"time":"2023-07-29 23:00:00","intensity":"2","total":"4"},{"time":"2023-07-30 00:00:00","intensity":"3.5","total":"7.5"},{"time":"2023-07-30 01:00:00","intensity":"2.5","total":"10"},{"time":"2023-07-30 02:00:00","intensity":"2","total":"244.5"},{"time":"2023-07-30 03:00:00","intensity":"3.5","total":"339.5"},{"time":"2023-07-30 04:00:00","intensity":"6","total":"345.5"},{"time":"2023-07-30 05:00:00","intensity":"10.5","total":"356"},{"time":"2023-07-30 06:00:00","intensity":"4.5","total":"360.5"},{"time":"2023-07-30 07:00:00","intensity":"5.5","total":"366"},{"time":"2023-07-30 08:00:00","intensity":"13","total":"379"},{"time":"2023-07-30 09:00:00","intensity":"17","total":"396"},{"time":"2023-07-30 10:00:00","intensity":"15.5","total":"25.5"},{"time":"2023-07-30 11:00:00","intensity":"17.5","total":"43"},{"time":"2023-07-30 12:00:00","intensity":"16","total":"59"},{"time":"2023-07-30 13:00:00","intensity":"18.5","total":"77.5"},{"time":"2023-07-30 14:00:00","intensity":"13","total":"90.5"},{"time":"2023-07-30 15:00:00","intensity":"23.5","total":"114"},{"time":"2023-07-30 16:00:00","intensity":"28.5","total":"142.5"},{"time":"2023-07-30 17:00:00","intensity":"24.5","total":"167"},{"time":"2023-07-30 18:00:00","intensity":"43","total":"210"},{"time":"2023-07-30 19:00:00","intensity":"32.5","total":"242.5"},{"time":"2023-07-30 20:00:00","intensity":"49.5","total":"294"},{"time":"2023-07-30 21:00:00","intensity":"18.5","total":"312.5"},{"time":"2023-07-30 22:00:00","intensity":"8","total":"320.5"},{"time":"2023-07-30 23:00:00","intensity":"15.5","total":"336"},{"time":"2023-07-31 00:00:00","intensity":"12.5","total":"408.5"},{"time":"2023-07-31 01:00:00","intensity":"15","total":"423.5"},{"time":"2023-07-31 02:00:00","intensity":"4","total":"537"},{"time":"2023-07-31 03:00:00","intensity":"12","total":"647"},{"time":"2023-07-31 04:00:00","intensity":"5","total":"652"},{"time":"2023-07-31 05:00:00","intensity":"36.5","total":"688.5"},{"time":"2023-07-31 06:00:00","intensity":"18","total":"706.5"},{"time":"2023-07-31 07:00:00","intensity":"26","total":"732.5"},{"time":"2023-07-31 08:00:00","intensity":"38","total":"770.5"},{"time":"2023-07-31 09:00:00","intensity":"39.5","total":"810"},{"time":"2023-07-31 10:00:00","intensity":"38","total":"461.5"},{"time":"2023-07-31 11:00:00","intensity":"27","total":"488.5"},{"time":"2023-07-31 12:00:00","intensity":"5.5","total":"494"},{"time":"2023-07-31 13:00:00","intensity":"2.5","total":"496.5"},{"time":"2023-07-31 14:00:00","intensity":"4","total":"500.5"},{"time":"2023-07-31 15:00:00","intensity":"8","total":"508.5"},{"time":"2023-07-31 16:00:00","intensity":"8.5","total":"517"},{"time":"2023-07-31 17:00:00","intensity":"0.5","total":"517.5"},{"time":"2023-07-31 18:00:00","intensity":"10","total":"527.5"},{"time":"2023-07-31 19:00:00","intensity":"5.5","total":"533"},{"time":"2023-07-31 20:00:00","intensity":"20.5","total":"557.5"},{"time":"2023-07-31 21:00:00","intensity":"25","total":"582.5"},{"time":"2023-07-31 22:00:00","intensity":"25.5","total":"608"},{"time":"2023-07-31 23:00:00","intensity":"27","total":"635"},{"time":"2023-08-01 00:00:00","intensity":"78.5","total":"888.5"},{"time":"2023-08-01 01:00:00","intensity":"32.5","total":"921"},{"time":"2023-08-01 02:00:00","intensity":"9.5","total":"956.5"},{"time":"2023-08-01 03:00:00","intensity":"6.5","total":"981.5"},{"time":"2023-08-01 04:00:00","intensity":"22.5","total":"1004"},{"time":"2023-08-01 05:00:00","intensity":"1","total":"1005"},{"time":"2023-08-01 06:00:00","intensity":"0","total":"1005"},{"time":"2023-08-01 07:00:00","intensity":"8","total":"1013"},{"time":"2023-08-01 08:00:00","intensity":"6","total":"1019"},{"time":"2023-08-01 09:00:00","intensity":"5.5","total":"1024.5"},{"time":"2023-08-01 10:00:00","intensity":"3","total":"924"},{"time":"2023-08-01 11:00:00","intensity":"5.5","total":"929.5"},{"time":"2023-08-01 12:00:00","intensity":"8.5","total":"938"},{"time":"2023-08-01 13:00:00","intensity":"8","total":"946"},{"time":"2023-08-01 14:00:00","intensity":"0.5","total":"946.5"},{"time":"2023-08-01 16:00:00","intensity":"0","total":"946.5"},{"time":"2023-08-01 18:00:00","intensity":"0.5","total":"947"},{"time":"2023-08-01 20:00:00","intensity":"17","total":"973.5"},{"time":"2023-08-01 21:00:00","intensity":"1","total":"974.5"},{"time":"2023-08-01 22:00:00","intensity":"0.5","total":"975"},{"time":"2023-08-02 00:00:00","intensity":"0","total":"1024.5"},{"time":"2023-08-02 02:00:00","intensity":"0","total":"1025"},{"time":"2023-08-02 03:00:00","intensity":"0.5","total":"1025.5"},{"time":"2023-08-02 04:00:00","intensity":"0","total":"1025.5"},{"time":"2023-08-02 06:00:00","intensity":"0","total":"1025.5"},{"time":"2023-08-02 08:00:00","intensity":"0","total":"1025.5"},{"time":"2023-08-02 12:00:00","intensity":"0","total":"1024.5"},{"time":"2023-08-02 14:00:00","intensity":"0","total":"1024.5"},{"time":"2023-08-02 15:00:00","intensity":"0.5","total":"1025"},{"time":"2023-08-02 18:00:00","intensity":"0","total":"1025"},{"time":"2023-08-02 20:00:00","intensity":"0","total":"1025"},{"time":"2023-08-02 22:00:00","intensity":"0","total":"1025"}]} |
| | | ---------------------------------------------- 2.推演区域 |
| | | -- drop table if exists nsl.region; |
| | | create table nsl.region ( |
| | |
| | | save_frames = frames; |
| | | save_interval = duration / frames; |
| | | } |
| | | |
| | | public List<Object> getTerrain() { |
| | | return terrain; |
| | | } |
| | | |
| | | public void setTerrain(List<Object> terrain) { |
| | | this.terrain = terrain; |
| | | } |
| | | |
| | | public List<Object> getLanduse() { |
| | | return landuse; |
| | | } |
| | | |
| | | public void setLanduse(List<Object> landuse) { |
| | | this.landuse = landuse; |
| | | } |
| | | |
| | | public List<Object> getStation() { |
| | | return station; |
| | | } |
| | | |
| | | public void setStation(List<Object> station) { |
| | | this.station = station; |
| | | } |
| | | |
| | | public Integer getkSt() { |
| | | return kSt; |
| | | } |
| | | |
| | | public void setkSt(Integer kSt) { |
| | | this.kSt = kSt; |
| | | } |
| | | |
| | | public String getRaingage() { |
| | | return raingage; |
| | | } |
| | | |
| | | public void setRaingage(String raingage) { |
| | | this.raingage = raingage; |
| | | } |
| | | |
| | | public String getInfiltration() { |
| | | return infiltration; |
| | | } |
| | | |
| | | public void setInfiltration(String infiltration) { |
| | | this.infiltration = infiltration; |
| | | } |
| | | |
| | | public Integer getDuration() { |
| | | return duration; |
| | | } |
| | | |
| | | public void setDuration(Integer duration) { |
| | | this.duration = duration; |
| | | } |
| | | |
| | | public Boolean getSave_state() { |
| | | return save_state; |
| | | } |
| | | |
| | | public void setSave_state(Boolean save_state) { |
| | | this.save_state = save_state; |
| | | } |
| | | |
| | | public List<String> getSave_variables() { |
| | | return save_variables; |
| | | } |
| | | |
| | | public void setSave_variables(List<String> save_variables) { |
| | | this.save_variables = save_variables; |
| | | } |
| | | |
| | | public Integer getSave_interval() { |
| | | return save_interval; |
| | | } |
| | | |
| | | public void setSave_interval(Integer save_interval) { |
| | | this.save_interval = save_interval; |
| | | } |
| | | |
| | | public Integer getSave_frames() { |
| | | return save_frames; |
| | | } |
| | | |
| | | public void setSave_frames(Integer save_frames) { |
| | | this.save_frames = save_frames; |
| | | } |
| | | |
| | | public Integer getSave_start() { |
| | | return save_start; |
| | | } |
| | | |
| | | public void setSave_start(Integer save_start) { |
| | | this.save_start = save_start; |
| | | } |
| | | |
| | | public Double getDt() { |
| | | return dt; |
| | | } |
| | | |
| | | public void setDt(Double dt) { |
| | | this.dt = dt; |
| | | } |
| | | |
| | | public Boolean getVariable_dt() { |
| | | return variable_dt; |
| | | } |
| | | |
| | | public void setVariable_dt(Boolean variable_dt) { |
| | | this.variable_dt = variable_dt; |
| | | } |
| | | } |
| | |
| | | package com.se.nsl.service; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.se.nsl.config.PropertiesConfig; |
| | | import com.se.nsl.domain.po.DataPo; |
| | | import com.se.nsl.domain.po.Simu; |
| | | import com.se.nsl.domain.po.SimuData; |
| | | import com.se.nsl.domain.vo.ConfigVo; |
| | | import com.se.nsl.helper.ComHelper; |
| | | import com.se.nsl.helper.StringHelper; |
| | | import com.se.nsl.helper.WebHelper; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.gdal.ogr.Geometry; |
| | | import org.gdal.ogr.ogr; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.nio.file.StandardCopyOption; |
| | | import java.sql.Timestamp; |
| | | import java.util.Date; |
| | | import java.util.concurrent.ExecutorService; |
| | |
| | | |
| | | @Resource |
| | | PropertiesConfig config; |
| | | @Autowired |
| | | private UwService uwService; |
| | | |
| | | public int start(Simu simu) { |
| | | Date now = new Date(); |
| | |
| | | try { |
| | | DataPo data = JSONUtil.toBean(simu.getData(), DataPo.class); |
| | | |
| | | update(simu, 1, null); |
| | | update(simu, 1, "开始"); |
| | | |
| | | initArgs(data); |
| | | String rs = callUwSolver(data); |
| | | //gedbService.copeVectors(token, data, db); |
| | | |
| | | //update(simu, 3, null); |
| | |
| | | simuService.updateById(simu); |
| | | } |
| | | |
| | | private void initArgs(){ |
| | | /** |
| | | * 初始化参数 |
| | | */ |
| | | private void initArgs(DataPo data) throws IOException { |
| | | String inPath = config.getInPath() + File.separator + data.getInPath(); |
| | | createDir(inPath); |
| | | createDir(inPath + File.separator + "depth"); |
| | | createDir(inPath + File.separator + "velocity"); |
| | | createDir(config.getOutPath() + File.separator + data.getOutPath()); |
| | | |
| | | // 临时复制高程tif,以后需要自行切割 |
| | | File uwBat = new File(config.getUwSolverBat()); |
| | | String sourceTif = uwBat.getParent() + File.separator + "data" + File.separator + "Hillzone.tif"; |
| | | String targetTif = inPath + File.separator + config.getDemFile(); |
| | | Files.copy(Paths.get(sourceTif), Paths.get(targetTif), StandardCopyOption.REPLACE_EXISTING); |
| | | } |
| | | |
| | | private void createDir(String path) { |
| | | File f = new File(path); |
| | | if (f.exists() && f.isDirectory()) { |
| | | FileUtil.del(f); |
| | | } |
| | | f.mkdirs(); |
| | | } |
| | | |
| | | /** |
| | | * 调用UWSolver |
| | | */ |
| | | private String callUwSolver(DataPo data) throws Exception { |
| | | File uwBat = new File(config.getUwSolverBat()); |
| | | |
| | | ConfigVo vo = new ConfigVo(data.getDuration(), config.getSaveFrames()); |
| | | //String configFile = uwBat.getParent() + File.separator + data.getInPath() + ".json"; |
| | | String configFile = config.getInPath() + File.separator + data.getInPath() + File.separator + data.getInPath() + ".json"; |
| | | ComHelper.writeJson(configFile, JSON.toJSONString(vo)); |
| | | |
| | | String cmd = String.format("%s %s", config.getUwSolverBat(), configFile); |
| | | |
| | | return callBat(cmd); |
| | | } |
| | | |
| | | private String callZarr2tif(DataPo data) throws Exception { |
| | | String cmd = ""; |
| | | |
| | | return callBat(cmd); |
| | | } |
| | | |
| | | private String callBat(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 execCmdLine(cmd); |
| | | } |
| | | |
| | | private String exec(String cmd) throws Exception { |
| | | public String exec(String cmd) throws Exception { |
| | | Process process = null; |
| | | BufferedReader nr = null; |
| | | BufferedReader er = null; |
| | |
| | | } |
| | | } |
| | | |
| | | private String execCmdLine(String cmd) throws IOException, InterruptedException { |
| | | public String execCmdLine(String cmd) throws IOException, InterruptedException { |
| | | Process process = Runtime.getRuntime().exec(cmd); |
| | | |
| | | new Thread(() -> { |