From 07b0c2b723f16d88c64a0e9151fdbef81a0a8a74 Mon Sep 17 00:00:00 2001 From: 张洋洋 <10611411+yang-yang-z@user.noreply.gitee.com> Date: 星期一, 13 一月 2025 17:54:10 +0800 Subject: [PATCH] [add]管线json --- src/main/java/com/se/simu/controller/SimuController.java | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/se/simu/controller/SimuController.java b/src/main/java/com/se/simu/controller/SimuController.java index d1337f8..5879100 100644 --- a/src/main/java/com/se/simu/controller/SimuController.java +++ b/src/main/java/com/se/simu/controller/SimuController.java @@ -406,7 +406,7 @@ @ApiOperation(value = "绠$偣杞琧ityjson") @GetMapping(value = "/pointToCityJson", produces = "application/json; charset=UTF-8") public R<String> pointToCityJson(@RequestParam("shpPath") String shpPath) throws Exception { - String path = outPath + "\\"; + String path = outPath + "\\point\\"; List<Map<String, Object>> list = ShpReadUtils.readPointShp(shpPath); JSONObject jsonObject = getModule("pointmodule.json"); for (Map<String, Object> map : list @@ -432,12 +432,60 @@ metry.put("boundaries", boundarie); geometry.add(metry); cityObject.put("geometry", geometry); - jsonObject.getJSONObject("CityObjects").put("UUID_"+UUID.randomUUID().toString(), cityObject); + jsonObject.getJSONObject("CityObjects").put("UUID_" + UUID.randomUUID().toString(), cityObject); } - long times=System.currentTimeMillis(); - String pointPath=path + times + "\\绠$偣.json"; - File dirFile=new File(path + times); - if (!dirFile.exists()){ + long times = System.currentTimeMillis(); + String pointPath = path + times + "\\绠$偣.json"; + File dirFile = new File(path + times); + if (!dirFile.exists()) { + dirFile.mkdirs(); + } + FileWriter fileWriter = new FileWriter(pointPath); + fileWriter.write(jsonObject.toJSONString()); + fileWriter.close(); + return success(pointPath); + } + + @ApiOperation(value = "绠$嚎杞琧ityjson") + @GetMapping(value = "/lineToCityJson", produces = "application/json; charset=UTF-8") + public R<String> lineToCityJson(@RequestParam("shpPath") String shpPath) throws Exception { + String path = outPath + "\\line\\"; + List<Map<String, Object>> list = ShpReadUtils.readPointShp(shpPath); + JSONObject jsonObject = getModule("linemodule.json"); + for (Map<String, Object> map : list + ) { + //鎷艰鍩虹淇℃伅 + JSONObject cityObject = new JSONObject(); + cityObject.put("type", "+PipeLine"); + JSONObject attribute = new JSONObject(); + attribute.put("name", map.get("msfs")); + JSONArray geometry = new JSONArray(); + JSONObject metry = new JSONObject(); + metry.put("type", "MultiLineString"); + metry.put("lod", 0); + JSONArray boundarie = new JSONArray(); + JSONArray array = JSONObject.parseObject(map.get("the_geom").toString()).getJSONArray("coordinates"); + for (int i = 0; i < array.size(); i++) { + JSONObject object = JSONObject.parseObject(array.get(i).toString()); + JSONArray vertice = new JSONArray(); + //todo 鏈潵淇敼鍧愭爣绯� + vertice.add(object.get("x")); + vertice.add(object.get("y")); + vertice.add(0.0); + jsonObject.getJSONArray("vertices").add(vertice); + boundarie.add(jsonObject.getJSONArray("vertices").size()); + } + metry.put("boundaries", boundarie); + cityObject.put("geometry",metry); + cityObject.put("attributes",attribute); + cityObject.put("attributes", attribute); + geometry.add(metry); + jsonObject.getJSONObject("CityObjects").put("UUID_" + UUID.randomUUID().toString(), cityObject); + } + long times = System.currentTimeMillis(); + String pointPath = path + times + "\\绠$嚎.json"; + File dirFile = new File(path + times); + if (!dirFile.exists()) { dirFile.mkdirs(); } FileWriter fileWriter = new FileWriter(pointPath); -- Gitblit v1.9.3