| | |
| | | package com.se.simu.controller; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import com.se.simu.domain.po.DataPo; |
| | | import com.se.simu.domain.po.SimuPo; |
| | | import com.se.simu.domain.vo.*; |
| | | import com.se.simu.enums.RadioEnums; |
| | | import com.se.simu.enums.SemErrorEnums; |
| | | import com.se.simu.helper.StringHelper; |
| | | import com.se.simu.helper.WebHelper; |
| | | import com.se.simu.mapper.SimuMapper; |
| | | import com.se.simu.service.*; |
| | | import com.se.simu.utils.*; |
| | | import io.swagger.annotations.*; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.codec.binary.Base64; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.*; |
| | | import java.math.BigDecimal; |
| | | import java.net.URL; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Api(tags = "仿真管理") |
| | |
| | | |
| | | @Resource |
| | | PropertiesConfig config; |
| | | |
| | | @Resource |
| | | SimuMapper simuMapper; |
| | | |
| | | @Value("${simu-app.filePath}") |
| | | private String uploadedFolder; |
| | |
| | | if (StringUtils.isEmpty(floodFile)) { |
| | | return fail("范围文件地址不能为空", false); |
| | | } else { |
| | | // todo: 解析范围文件 根据不同的的格式文件进行不同的解析,获取需要计算的范围值 |
| | | // 上传格式:.shp/.tiff/.img/.geojson |
| | | // 重新给vo赋值 |
| | | // 获取文件的后缀名 |
| | | String fileName = floodFile.substring(floodFile.lastIndexOf(".")); |
| | | // 判断后缀名是否为.shp |
| | |
| | | Double minY = jsonObject.getDouble("minX"); |
| | | Double maxY = jsonObject.getDouble("maxX"); |
| | | // 3 判断范围值是否为空 |
| | | // vo.setMinx(jsonObject.getDouble("minX")); |
| | | // vo.setMaxx(jsonObject.getDouble("maxX")); |
| | | // vo.setMiny(jsonObject.getDouble("minY")); |
| | | // vo.setMaxy(jsonObject.getDouble("maxY")); |
| | | vo.setMinx(jsonObject.getDouble("minY")); |
| | | vo.setMaxx(jsonObject.getDouble("maxY")); |
| | | vo.setMiny(jsonObject.getDouble("minX")); |
| | |
| | | rangeVerify(minX, maxX, minY, maxY); |
| | | } |
| | | } |
| | | // todo: 解析范围文件 根据不同的的格式文件进行不同的解析,获取需要计算的范围值 |
| | | // 上传格式:.shp/.tiff/.img/.geojson |
| | | // 重新给vo赋值 |
| | | } catch (Exception e) { |
| | | log.error("解析范围文件失败"); |
| | | if (null == vo.getMinx() || null == vo.getMiny() || null == vo.getMaxx() || null == vo.getMaxy()) { |
| | | return fail("解析范围文件失败!选择范围不能为空,请重新选择文件!", false); |
| | | } |
| | | } |
| | | JSONArray jsonArray = new JSONArray(); |
| | | String stationFile = vo.getStationFile(); |
| | | log.info("站点文件shp地址:{}", stationFile); |
| | | try { |
| | | // 判断地址不为空 |
| | | if (StringUtils.isEmpty(stationFile)) { |
| | | return fail("站点文件shp地址不能为空", false); |
| | | if (RadioEnums.ACCESS.getCode().equals(vo.getRadio()) && StringUtils.isNotEmpty(stationFile)) { |
| | | // 1 读取shp文件,获取站点坐标值 |
| | | ShpToolUtils.readShpGetLocal(stationFile); |
| | | } |
| | | // 1 读取shp文件,获取站点坐标值 |
| | | jsonArray = ShpToolUtils.readShpGetLocal(stationFile); |
| | | System.out.println("jsonArray = " + jsonArray); |
| | | } catch (Exception e) { |
| | | log.error("解析站点文件shp失败"); |
| | | } |
| | | |
| | | String stationRainFile = vo.getStationRainFile(); |
| | | log.info("站点雨量CSV文件地址:{}", floodFile); |
| | | JSONArray array = new JSONArray(); |
| | | // 创建表名 时间戳 |
| | | String tableName = "station_rain_" + System.currentTimeMillis(); |
| | | try { |
| | | // 判断地址不为空 |
| | | if (StringUtils.isEmpty(stationRainFile)) { |
| | | return fail("站点雨量CSV文件地址不能为空", false); |
| | | //接入处理 |
| | | if (RadioEnums.ACCESS.getCode().equals(vo.getRadio())) { |
| | | String stationRainFile = vo.getStationRainFile(); |
| | | log.info("站点雨量CSV文件地址:{}", floodFile); |
| | | // 判断地址不为空 |
| | | if (StringUtils.isEmpty(stationRainFile)) { |
| | | return fail("站点雨量CSV文件地址不能为空", false); |
| | | } |
| | | // 1 读取CSV 文件 |
| | | CsvToSQLiteUtils.readCsvSaveLocal(stationRainFile, tableName); |
| | | // 获取仿真时间 duration |
| | | Integer duration = CsvToSQLiteUtils.getDuration(tableName); |
| | | log.info("仿真时间 duration = {}", duration); |
| | | vo.setDuration(duration); |
| | | // 获取降雨总量 total |
| | | Double total = CsvToSQLiteUtils.getTotal(tableName); |
| | | log.info("降雨总量 total = {}", total); |
| | | vo.setTotal(total); |
| | | } else if (RadioEnums.SIMULATE.getCode().equals(vo.getRadio())) { |
| | | if (StringUtils.isEmpty(vo.getStation())) { |
| | | return fail("模拟计算站点不能为空!", false); |
| | | } |
| | | if (vo.getTotal() == null) { |
| | | return fail("模拟计算降雨量不能为空!", false); |
| | | } |
| | | if (vo.getDuration() == null || vo.getDuration() <= 0) { |
| | | return fail("模拟计算计算时长不能为空!", false); |
| | | } |
| | | if (vo.getStationLatitude() == null) { |
| | | return fail("模拟计算计算坐标!", false); |
| | | } |
| | | if (vo.getStationLongitude() == null) { |
| | | return fail("模拟计算计算坐标!", false); |
| | | } |
| | | double aveTotal = BigDecimal.valueOf(vo.getTotal()).divide(BigDecimal.valueOf(vo.getDuration()), 2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
| | | JSONArray jsonArray = new JSONArray(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | DateTimeFormatter customFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm"); |
| | | for (int i = 0; i < vo.getDuration(); i++) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("stationName", vo.getStation()); |
| | | jsonObject.put("rainfall", aveTotal); |
| | | jsonObject.put("longitude", vo.getStationLongitude()); |
| | | jsonObject.put("latitude", vo.getStationLatitude()); |
| | | LocalDateTime plusMinutes = now.plusMinutes(i); |
| | | jsonObject.put("datetime", customFormatter.format(plusMinutes)); |
| | | jsonArray.add(jsonObject); |
| | | } |
| | | CsvToSQLiteUtils.readCsvSaveLocal(jsonArray, tableName); |
| | | } else { |
| | | return fail("无效的模型计算方式", false); |
| | | } |
| | | // 1 读取CSV 文件 |
| | | array = CsvToSQLiteUtils.readCsvSaveLocal(stationRainFile, tableName); |
| | | // 获取仿真时间 duration |
| | | Integer duration = CsvToSQLiteUtils.getDuration(tableName); |
| | | log.info("仿真时间 duration = {}", duration); |
| | | vo.setDuration(duration); |
| | | |
| | | // 获取降雨总量 total |
| | | Double total = CsvToSQLiteUtils.getTotal(tableName); |
| | | log.info("降雨总量 total = {}", total); |
| | | vo.setTotal(total); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("解析站点雨量CSV文件失败"); |
| | | return fail("雨量处理失败!", false); |
| | | } |
| | | // TODO: 2024/12/24 根据这些文件的地址,获取文件内容,创建仿真视图 |
| | | try { |
| | |
| | | return fail("防汛范围不能为空", false); |
| | | } |
| | | } |
| | | if (StringUtils.isEmpty(vo.getSemUrl())) { |
| | | return fail("sem文件生成路径不能为空!", false); |
| | | } |
| | | List<GridDto> dtos = new ArrayList<>(); |
| | | dtos.add(new GridDto(vo.getMiny(), vo.getMaxx())); |
| | | dtos.add(new GridDto(vo.getMaxy(), vo.getMaxx())); |
| | | dtos.add(new GridDto(vo.getMaxy(), vo.getMinx())); |
| | | dtos.add(new GridDto(vo.getMiny(), vo.getMinx())); |
| | | String bbox = ""; |
| | | //生成点和线的实体库模型并保存路径 |
| | | String name = vo.getSemUrl(); |
| | | String token = EntityLibraryUtils.login(); |
| | | vo.setPointName(name + "-point"); |
| | | vo.setLinkName(name + "-line"); |
| | | JSONArray min = ProjectionToGeographicUtil.get4548Point(dtos.get(3).getLon(), dtos.get(3).getLat()); |
| | | JSONArray max = ProjectionToGeographicUtil.get4548Point(dtos.get(1).getLon(), dtos.get(1).getLat()); |
| | | bbox = bbox + min.getDouble(0) + "," + min.getDouble(1) + "," + max.getDouble(0) + "," + max.getDouble(1); |
| | | JSONObject point = getModule("layerQueryPointParams.json"); |
| | | String pointUrl = assemble(vo.getPointName(), point.getString("layerid"), bbox, token); |
| | | vo.setPointName(pointUrl); |
| | | JSONObject link = getModule("layerQueryParams.json"); |
| | | String linkUrl = assemble(vo.getLinkName(), link.getString("layerid"), bbox, token); |
| | | vo.setLinkName(linkUrl); |
| | | SimuPo simu = saveSimu(vo); |
| | | //生成sem文件 |
| | | asyncCall(tableName, dtos, vo, token, simu); |
| | | |
| | | // 开始模拟计算 |
| | | boolean flag = simuFilesService.createByfiles(vo); |
| | | return success(flag, flag ? "成功" : "失败"); |
| | | //boolean flag = simuFilesService.createByfiles(vo, token); |
| | | return success(simu.getId() != null ? "成功" : "失败"); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "tarr文件组装") |
| | | @GetMapping(value = "/saveZarr", produces = "application/json; charset=UTF-8") |
| | | public R<String> saveZarr(@RequestParam("name") String tableName) throws Exception { |
| | | public SimuPo saveSimu(CreateFilesSimuVo vo) { |
| | | Date now = new Date(); |
| | | String date = StringHelper.YMDHMS2_FORMAT.format(now); |
| | | if (StringHelper.isEmpty(vo.getName())) { |
| | | vo.setName(date); |
| | | } |
| | | DataPo data = BeanUtil.copyProperties(vo, DataPo.class); |
| | | data.setPath(date, date); |
| | | SimuPo simu = new SimuPo(vo.getNum(), vo.getPid(), vo.getName(), JSONUtil.toJsonStr(data), 0, vo.getBak()); |
| | | simu.setServiceName(date); |
| | | simu.setCreateTime(new Timestamp(now.getTime())); |
| | | simu.setSemUrl(vo.getSemUrl()); |
| | | simu.setPointUrl(vo.getPointName()); |
| | | simu.setLinkUrl(vo.getLinkName()); |
| | | simu.setSemUrl(inPath + "\\" + vo.getSemUrl()); |
| | | int rows = simuMapper.insert(simu); |
| | | return simu; |
| | | } |
| | | |
| | | @ApiOperation(value = "获取点路径") |
| | | @GetMapping("/getPointUrl") |
| | | public R<String> getPointUrl(@RequestParam("id") Integer id) throws Exception { |
| | | SimuPo po = simuService.getSimuById(id); |
| | | String token = EntityLibraryUtils.login(); |
| | | if (po != null) { |
| | | return success(po.getPointUrl().replace("{token}", token)); |
| | | } |
| | | return success(null); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取线路径") |
| | | @GetMapping("/getLineUrl") |
| | | public R<String> getLineUrl(@RequestParam("id") Integer id) throws Exception { |
| | | SimuPo po = simuService.getSimuById(id); |
| | | String token = EntityLibraryUtils.login(); |
| | | if (po != null) { |
| | | return success(po.getLinkUrl().replace("{token}", token)); |
| | | } |
| | | return success(null); |
| | | } |
| | | |
| | | private void asyncCall(String tableName, List<GridDto> dtos, CreateFilesSimuVo vo, String token, SimuPo simu) { |
| | | ExecutorService executor = Executors.newSingleThreadExecutor(); |
| | | executor.execute(new Runnable() { |
| | | @Override |
| | | @SneakyThrows |
| | | public void run() { |
| | | createSem(tableName, dtos, vo, token, simu); |
| | | } |
| | | }); |
| | | executor.shutdown(); |
| | | } |
| | | |
| | | public void createSem(String tableName, List<GridDto> dtos, CreateFilesSimuVo vo, String token, SimuPo simu) throws Exception { |
| | | int code=1; |
| | | try { |
| | | vo.setSemUrl(inPath + "\\" + vo.getSemUrl()); |
| | | boolean ends = vo.getSemUrl().endsWith("\\"); |
| | | if (!ends) { |
| | | vo.setSemUrl(vo.getSemUrl() + "\\"); |
| | | } |
| | | File file = new File(vo.getSemUrl()); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | //初始化 |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //降雨文件生成 |
| | | saveZarr(tableName, vo.getSemUrl()); |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //管点生成 |
| | | pointTosem(dtos, token, vo.getSemUrl()); |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //管线生成 |
| | | lineToSem(dtos, token, vo.getSemUrl()); |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //范围生成 |
| | | gridToCityJson(dtos, vo.getSemUrl()); |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //河流生成 |
| | | riverToSem(vo.getSemUrl()); |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //土地利用生成 |
| | | landuseToSem(vo.getSemUrl()); |
| | | update(simu, code, null); |
| | | code+=1; |
| | | //地形生成 |
| | | terrainToSem(dtos, vo.getSemUrl()); |
| | | update(simu, 10, null); |
| | | code+=1; |
| | | //9=调用求解/10=求解分析 |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | update(simu, -simu.getStatus(), SemErrorEnums.of(code)); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | private void update(SimuPo simu, int status, String rs) { |
| | | simu.setStatus(status); |
| | | if (null != rs) simu.setResult(rs); |
| | | simu.setUpdateTime(WebHelper.getCurrentTimestamp()); |
| | | |
| | | simuMapper.updateById(simu); |
| | | } |
| | | |
| | | public String assemble(String name, String layerid, String bbox, String token) throws Exception { |
| | | JSONObject jsonObject = EntityLibraryUtils.createAssemble(name, token); |
| | | String packageid = jsonObject.getString("packageid"); |
| | | EntityLibraryUtils.addAssemble(layerid, token, packageid, bbox); |
| | | JSONObject result = EntityLibraryUtils.submitAssemble(token, packageid); |
| | | Random random = new Random(); |
| | | int randomNumber = random.nextInt(90000) + 10000; |
| | | String url = "http://106.120.22.26:8024/geo-service/package/3d/normal/85257774fdb64e5f99f6778696cad02a/" + packageid + "/" + layerid + "//l0/tileset.json?r=" + randomNumber + "&token={token}"; |
| | | return url; |
| | | } |
| | | |
| | | public R<String> saveZarr(String tableName, String semUrl) throws Exception { |
| | | List<String> list = CsvToSQLiteUtils.getNameList(tableName); |
| | | String path = outPath + "\\"; |
| | | String rainfall = "rainfall\\"; |
| | | String basePath = path + tableName + "\\" + rainfall; |
| | | JSONObject jsonObject = getModule("rainfallmodule.json"); |
| | | String startTime = null; |
| | | String endTime = null; |
| | | for (String src : list |
| | | ) { |
| | | File directories = new File(basePath); |
| | |
| | | System.out.println("Directories already exist."); |
| | | } |
| | | List<StationRainVo> stationRainVos = CsvToSQLiteUtils.getList(tableName, src); |
| | | if (startTime == null) { |
| | | startTime = stationRainVos.get(0).getDatetime(); |
| | | } |
| | | if (endTime == null) { |
| | | endTime = stationRainVos.get(stationRainVos.size() - 1).getDatetime(); |
| | | } |
| | | ZarrUtils.saveZarrRainfall(basePath + src, stationRainVos); |
| | | ZarrUtils.saveZarrTime(basePath + src, stationRainVos); |
| | | ZipUtils.toZarr(basePath + src, basePath + src + ".zip"); |
| | |
| | | FileWriter fileWriter = new FileWriter(path + tableName + "\\降雨量.json"); |
| | | fileWriter.write(jsonObject.toJSONString()); |
| | | fileWriter.close(); |
| | | String filePatn = inPath + "\\tongzhou\\"; |
| | | File file = new File(filePatn); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | SemUtils.cityJsonToSem(path + tableName + "\\降雨量.json", filePatn + "raingage.sem"); |
| | | return success(filePatn + "raingage.sem"); |
| | | SemUtils.cityJsonToSem(path + tableName + "\\降雨量.json", semUrl + "raingage.sem"); |
| | | getConfigJson(startTime, endTime, semUrl); |
| | | return success(semUrl + "raingage.sem"); |
| | | } |
| | | |
| | | @ApiOperation(value = "管点转sem") |
| | | @PostMapping(value = "/pointTosem", produces = "application/json; charset=UTF-8") |
| | | public R<String> pointTosem(@RequestBody List<GridDto> dtos) throws Exception { |
| | | public void getConfigJson(String startTime, String endTime, String semUrl) throws Exception { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm"); |
| | | Date start = sdf.parse(startTime); |
| | | Date end = sdf.parse(endTime); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); |
| | | JSONObject jsonObject = getModule("config.json"); |
| | | jsonObject.put("start_datetime", simpleDateFormat.format(start)); |
| | | jsonObject.put("end_datetime", simpleDateFormat.format(end)); |
| | | FileWriter fileWriter = new FileWriter(semUrl + "\\config.json"); |
| | | fileWriter.write(jsonObject.toJSONString()); |
| | | fileWriter.close(); |
| | | } |
| | | |
| | | public R<String> pointTosem(List<GridDto> dtos, String token, String semUrl) throws Exception { |
| | | String path = outPath + "\\point\\"; |
| | | String publicKey = EntityLibraryUtils.getPublicKey(); |
| | | String token = EntityLibraryUtils.login(); |
| | | JSONArray jsonArrayList = EntityLibraryUtils.getPointInfo(dtos, token); |
| | | JSONObject jsonObject = getModule("pointmodule.json"); |
| | | for (int s = 0; s < jsonArrayList.size(); s++) { |
| | |
| | | FileWriter fileWriter = new FileWriter(pointPath); |
| | | fileWriter.write(jsonObject.toJSONString()); |
| | | fileWriter.close(); |
| | | String filePatn = inPath + "\\tongzhou\\"; |
| | | File file = new File(filePatn); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | SemUtils.cityJsonToSem(pointPath, filePatn + "node.sem"); |
| | | return success(filePatn + "node.sem"); |
| | | SemUtils.cityJsonToSem(pointPath, semUrl + "node.sem"); |
| | | return success(semUrl + "node.sem"); |
| | | } |
| | | @ApiOperation(value = "管点转cityjson") |
| | | @GetMapping(value = "/pointToCityJson", produces = "application/json; charset=UTF-8") |
| | | public R<String> pointToCityJson(@RequestParam("shpPath") String shpPath) throws Exception { |
| | | |
| | | |
| | | public R<String> pointToCityJson(String shpPath) throws Exception { |
| | | String path = outPath + "\\point\\"; |
| | | List<Map<String, Object>> list = ShpReadUtils.readPointShp(shpPath); |
| | | JSONObject jsonObject = getModule("pointmodule.json"); |
| | |
| | | return success(filePatn + "node.sem"); |
| | | } |
| | | |
| | | @ApiOperation(value = "管线sem生成") |
| | | @PostMapping(value = "/lineToSem", produces = "application/json; charset=UTF-8") |
| | | public R<String> lineToSem(@RequestBody List<GridDto> dtos) throws Exception { |
| | | public R<String> lineToSem(List<GridDto> dtos, String token, String semUrl) throws Exception { |
| | | String path = outPath + "\\line\\"; |
| | | String publicKey = EntityLibraryUtils.getPublicKey(); |
| | | String token = EntityLibraryUtils.login(); |
| | | JSONArray jsonArrayList = EntityLibraryUtils.getLineInfo(dtos, token); |
| | | if (jsonArrayList.size() == 0) { |
| | | return fail("该区域不存在管线!"); |
| | |
| | | FileWriter fileWriter = new FileWriter(pointPath); |
| | | fileWriter.write(jsonObject.toJSONString()); |
| | | fileWriter.close(); |
| | | String filePatn = inPath + "\\tongzhou\\"; |
| | | File file = new File(filePatn); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | SemUtils.cityJsonToSem(pointPath, filePatn + "link.sem"); |
| | | return success(filePatn + "link.sem"); |
| | | SemUtils.cityJsonToSem(pointPath, semUrl + "link.sem"); |
| | | return success(semUrl + "link.sem"); |
| | | } |
| | | |
| | | @ApiOperation(value = "管线转cityjson") |
| | | @GetMapping(value = "/lineToCityJson", produces = "application/json; charset=UTF-8") |
| | | public R<String> lineToCityJson(@RequestParam("shpPath") String shpPath) throws Exception { |
| | | public R<String> lineToCityJson(String shpPath) throws Exception { |
| | | String path = outPath + "\\line\\"; |
| | | List<Map<String, Object>> list = ShpReadUtils.readPointShp(shpPath); |
| | | JSONObject jsonObject = getModule("linemodule.json"); |
| | |
| | | return success(filePatn + "link.sem"); |
| | | } |
| | | |
| | | @ApiOperation(value = "地形转cityjson") |
| | | @GetMapping(value = "/terrainToCityJson", produces = "application/json; charset=UTF-8") |
| | | public R<String> terrainToCityJson(@RequestParam("tifPath") String tifPath) throws Exception { |
| | | public R<String> terrainToSem(List<GridDto> dtos, String semUrl) throws Exception { |
| | | long times = System.currentTimeMillis(); |
| | | String path = outPath + "\\terrain\\" + times + "\\"; |
| | | File dirFile = new File(path + "appearance"); |
| | | if (!dirFile.exists()) { |
| | | dirFile.mkdirs(); |
| | | } |
| | | double minx = 180.0; |
| | | double maxx = 0.0; |
| | | double miny = 180.0; |
| | | double maxy = 0.0; |
| | | for (GridDto dto : dtos |
| | | ) { |
| | | if (dto.getLon() > maxx) { |
| | | maxx = dto.getLon(); |
| | | } |
| | | if (dto.getLon() < minx) { |
| | | minx = dto.getLon(); |
| | | } |
| | | if (dto.getLat() > maxy) { |
| | | maxy = dto.getLat(); |
| | | } |
| | | if (dto.getLat() < miny) { |
| | | miny = dto.getLat(); |
| | | } |
| | | } |
| | | JSONArray min = ProjectionToGeographicUtil.get4548Point(minx, miny); |
| | | JSONArray max = ProjectionToGeographicUtil.get4548Point(maxx, maxy); |
| | | String tifPath = path + "terrain.tif"; |
| | | TiffClipper.cropTiffByLatLon(config.getTifPath(), tifPath, min.getDouble(0), min.getDouble(1), max.getDouble(0), max.getDouble(1)); |
| | | String pngPath = path + "appearance\\terrain.png"; |
| | | TiffToRGBUtil.tifToPng(tifPath, pngPath); |
| | | JSONObject jsonObject = getModule("terrainmodule.json"); |
| | | JSONArray array=new JSONArray(); |
| | | array.add(ProjectionToGeographicUtil.getPoint(dtos.get(0).getLon(),dtos.get(0).getLat())); |
| | | array.add(ProjectionToGeographicUtil.getPoint(dtos.get(1).getLon(),dtos.get(1).getLat())); |
| | | array.add(ProjectionToGeographicUtil.getPoint(dtos.get(2).getLon(),dtos.get(2).getLat())); |
| | | array.add(ProjectionToGeographicUtil.getPoint(dtos.get(3).getLon(),dtos.get(3).getLat())); |
| | | //jsonObject.put("vertices", TiffCoordinateExtractorUtil.getCoordinate(tifPath)); |
| | | jsonObject.put("vertices", array); |
| | | FileWriter fileWriter = new FileWriter(path + "terrain.json"); |
| | | fileWriter.write(jsonObject.toJSONString()); |
| | | fileWriter.close(); |
| | | SemUtils.cityJsonToSem(path + "terrain.json", semUrl + "terrain.sem"); |
| | | return success(semUrl + "terrain.sem"); |
| | | } |
| | | |
| | | public R<String> terrainToCityJson(String tifPath) throws Exception { |
| | | long times = System.currentTimeMillis(); |
| | | String path = outPath + "\\terrain\\" + times + "\\"; |
| | | File dirFile = new File(path + "appearance"); |
| | |
| | | return success(filePatn + "terrain.sem"); |
| | | } |
| | | |
| | | @ApiOperation(value = "grid转cityjson") |
| | | @PostMapping(value = "/gridToCityJson", produces = "application/json; charset=UTF-8") |
| | | public R<String> gridToCityJson(@RequestBody List<GridDto> dtos) throws Exception { |
| | | public R<String> gridToCityJson(List<GridDto> dtos, String semUrl) throws Exception { |
| | | long times = System.currentTimeMillis(); |
| | | String path = outPath + "\\grid\\" + times + "\\"; |
| | | File dirFile = new File(path); |
| | |
| | | FileWriter fileWriter = new FileWriter(path + "grid.json"); |
| | | fileWriter.write(jsonObject.toJSONString()); |
| | | fileWriter.close(); |
| | | String filePatn = inPath + "\\tongzhou\\"; |
| | | File file = new File(filePatn); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | SemUtils.cityJsonToSem(path + "grid.json", filePatn + "grid.sem"); |
| | | return success(filePatn + "grid.sem"); |
| | | SemUtils.cityJsonToSem(path + "grid.json", semUrl + "grid.sem"); |
| | | return success(semUrl + "grid.sem"); |
| | | } |
| | | |
| | | @ApiOperation(value = "river转sem") |
| | | @GetMapping(value = "/riverToSem", produces = "application/json; charset=UTF-8") |
| | | public R<String> riverToSem() throws Exception { |
| | | public R<String> riverToSem(String semUrl) throws Exception { |
| | | long times = System.currentTimeMillis(); |
| | | String path = outPath + "\\river\\" + times + "\\"; |
| | | File dirFile = new File(path); |
| | |
| | | FileWriter fileWriter = new FileWriter(path + "river.json"); |
| | | fileWriter.write(jsonObject.toJSONString()); |
| | | fileWriter.close(); |
| | | String filePatn = inPath + "\\tongzhou\\"; |
| | | File file = new File(filePatn); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | SemUtils.cityJsonToSem(path + "river.json", filePatn + "river.sem"); |
| | | return success(filePatn + "river.sem"); |
| | | SemUtils.cityJsonToSem(path + "river.json", semUrl + "river.sem"); |
| | | return success(semUrl + "river.sem"); |
| | | } |
| | | |
| | | @ApiOperation(value = "landuse转sem") |
| | | @GetMapping(value = "/landuseToSem", produces = "application/json; charset=UTF-8") |
| | | public R<String> landuseToSem() throws Exception { |
| | | public R<String> landuseToSem(String semUrl) throws Exception { |
| | | long times = System.currentTimeMillis(); |
| | | String path = outPath + "\\landuse\\" + times + "\\"; |
| | | File dirFile = new File(path); |
| | |
| | | FileWriter fileWriter = new FileWriter(path + "landuse.json"); |
| | | fileWriter.write(jsonObject.toJSONString()); |
| | | fileWriter.close(); |
| | | String filePatn = inPath + "\\tongzhou\\"; |
| | | File file = new File(filePatn); |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | SemUtils.cityJsonToSem(path + "landuse.json", filePatn + "landuse.sem"); |
| | | return success(filePatn + "landuse.sem"); |
| | | SemUtils.cityJsonToSem(path + "landuse.json", semUrl + "landuse.sem"); |
| | | return success(semUrl + "landuse.sem"); |
| | | } |
| | | |
| | | public JSONObject getModule(String moduleName) { |