From c3137476e71b28cb77f52d24b2714cee336fc2f4 Mon Sep 17 00:00:00 2001 From: 张洋洋 <10611411+yang-yang-z@user.noreply.gitee.com> Date: 星期一, 10 二月 2025 13:43:40 +0800 Subject: [PATCH] [add]cityjson转sem --- src/main/resources/river.json | 1 src/main/java/com/se/simu/utils/SemUtils.java | 4 +- src/main/java/com/se/simu/controller/SimuController.java | 102 +++++++++++++++++++++++++++++++++++++++++++------- src/main/resources/landuse.json | 1 4 files changed, 91 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/se/simu/controller/SimuController.java b/src/main/java/com/se/simu/controller/SimuController.java index e11153d..dd371ea 100644 --- a/src/main/java/com/se/simu/controller/SimuController.java +++ b/src/main/java/com/se/simu/controller/SimuController.java @@ -54,6 +54,9 @@ @Value("${config.outPath}") private String outPath; + @Value("${config.inPath}") + private String inPath; + @Resource ResultService resultService; @@ -401,8 +404,13 @@ FileWriter fileWriter = new FileWriter(path + tableName + "\\闄嶉洦閲�.json"); fileWriter.write(jsonObject.toJSONString()); fileWriter.close(); - SemUtils.cityJsonToSem(path + tableName + "\\闄嶉洦閲�.json", path + tableName + "\\station_rain.sem"); - return success(path + tableName + "\\station_rain.sem"); + 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"); } @ApiOperation(value = "绠$偣杞琧ityjson") @@ -445,8 +453,13 @@ FileWriter fileWriter = new FileWriter(pointPath); fileWriter.write(jsonObject.toJSONString()); fileWriter.close(); - SemUtils.cityJsonToSem(pointPath, path + times + "\\point.sem"); - return success(path + times + "\\point.sem"); + 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"); } @ApiOperation(value = "绠$嚎杞琧ityjson") @@ -493,8 +506,13 @@ FileWriter fileWriter = new FileWriter(pointPath); fileWriter.write(jsonObject.toJSONString()); fileWriter.close(); - SemUtils.cityJsonToSem(pointPath, path + times + "\\line.sem"); - return success(path + times + "\\line.sem"); + 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"); } @ApiOperation(value = "鍦板舰杞琧ityjson") @@ -513,8 +531,13 @@ FileWriter fileWriter = new FileWriter(path + "terrain.json"); fileWriter.write(jsonObject.toJSONString()); fileWriter.close(); - SemUtils.cityJsonToSem(path + "terrain.json", path + "terrain.sem"); - return success(path + "terrain.sem"); + String filePatn = inPath + "\\tongzhou\\"; + File file = new File(filePatn); + if (!file.exists()) { + file.mkdirs(); + } + SemUtils.cityJsonToSem(path + "terrain.json", filePatn + "terrain.sem"); + return success(filePatn + "terrain.sem"); } @ApiOperation(value = "grid杞琧ityjson") @@ -522,26 +545,75 @@ public R<String> gridToCityJson(@RequestBody List<GridDto> dtos) throws Exception { long times = System.currentTimeMillis(); String path = outPath + "\\grid\\" + times + "\\"; - File dirFile = new File(path ); + File dirFile = new File(path); if (!dirFile.exists()) { dirFile.mkdirs(); } JSONObject jsonObject = getModule("grid.json"); JSONArray array = jsonObject.getJSONArray("vertices"); - for (GridDto dto:dtos - ) { - JSONArray jsonArray=new JSONArray(); + for (GridDto dto : dtos + ) { + JSONArray jsonArray = new JSONArray(); jsonArray.add(dto.getLon()); jsonArray.add(dto.getLat()); jsonArray.add(0); array.add(jsonArray); } - jsonObject.put("vertices",array); + jsonObject.put("vertices", array); FileWriter fileWriter = new FileWriter(path + "grid.json"); fileWriter.write(jsonObject.toJSONString()); fileWriter.close(); - SemUtils.cityJsonToSem(path + "grid.json", path + "grid.sem"); - return success(path + "grid.sem"); + 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"); + } + + @ApiOperation(value = "river杞瑂em") + @GetMapping(value = "/riverToSem", produces = "application/json; charset=UTF-8") + public R<String> riverToSem() throws Exception { + long times = System.currentTimeMillis(); + String path = outPath + "\\river\\" + times + "\\"; + File dirFile = new File(path); + if (!dirFile.exists()) { + dirFile.mkdirs(); + } + JSONObject jsonObject = getModule("river.json"); + 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"); + } + + @ApiOperation(value = "landuse杞瑂em") + @GetMapping(value = "/landuseToSem", produces = "application/json; charset=UTF-8") + public R<String> landuseToSem() throws Exception { + long times = System.currentTimeMillis(); + String path = outPath + "\\landuse\\" + times + "\\"; + File dirFile = new File(path); + if (!dirFile.exists()) { + dirFile.mkdirs(); + } + JSONObject jsonObject = getModule("landuse.json"); + 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"); } public JSONObject getModule(String moduleName) { diff --git a/src/main/java/com/se/simu/utils/SemUtils.java b/src/main/java/com/se/simu/utils/SemUtils.java index f0fe654..3b37a09 100644 --- a/src/main/java/com/se/simu/utils/SemUtils.java +++ b/src/main/java/com/se/simu/utils/SemUtils.java @@ -14,7 +14,7 @@ } public static void semToCityJson() throws Exception { //sem杞琧ityjson - SEM sem2 = new SEM("D:\\鍩庡競鍐呮稘\\sem\\tongzhou\\tongzhou\\grid.sem"); - sem2.writeToCityJSON("D:\\鍩庡競鍐呮稘\\sem\\tongzhou\\tongzhou\\grid\\grid.json"); + SEM sem2 = new SEM("D:\\鍩庡競鍐呮稘\\sem\\tongzhou\\tongzhou\\landuse.sem"); + sem2.writeToCityJSON("D:\\鍩庡競鍐呮稘\\sem\\tongzhou\\tongzhou\\landuse\\landuse.json"); } } diff --git a/src/main/resources/landuse.json b/src/main/resources/landuse.json new file mode 100644 index 0000000..02ffbef --- /dev/null +++ b/src/main/resources/landuse.json @@ -0,0 +1 @@ +{"type":"CityJSON","metadata":{"referenceSystem":"urn:ogc:def:crs:EPSG::4326","datasetPointOfContact":{}},"version":"1.0","CityObjects":{},"vertices":[]} \ No newline at end of file diff --git a/src/main/resources/river.json b/src/main/resources/river.json new file mode 100644 index 0000000..2eb29f2 --- /dev/null +++ b/src/main/resources/river.json @@ -0,0 +1 @@ +{"type":"CityJSON","version":"1.0","metadata":{"referenceSystem":"urn:ogc:def:crs:EPSG::4326","datasetPointOfContact":{}},"CityObjects":{},"vertices":[],"appearance":{"materials":[],"textures":[],"vertices-texture":[]},"geometry-templates":{"templates":[],"vertices-templates":[]}} \ No newline at end of file -- Gitblit v1.9.3