From 440888a8ae5f0a6df4eba6710f096327d4d78c9c Mon Sep 17 00:00:00 2001 From: 张洋洋 <10611411+yang-yang-z@user.noreply.gitee.com> Date: 星期四, 23 一月 2025 16:33:53 +0800 Subject: [PATCH] [add]cityjson转sem --- src/main/java/com/se/simu/controller/SimuController.java | 41 ++++++++++++++++++++++++++++++++--------- 1 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/se/simu/controller/SimuController.java b/src/main/java/com/se/simu/controller/SimuController.java index 6c0aa4e..58bdf74 100644 --- a/src/main/java/com/se/simu/controller/SimuController.java +++ b/src/main/java/com/se/simu/controller/SimuController.java @@ -343,7 +343,7 @@ @ApiOperation(value = "tarr鏂囦欢缁勮") @GetMapping(value = "/saveZarr", produces = "application/json; charset=UTF-8") - public R<Boolean> saveZarr(@RequestParam("name") String tableName) throws IOException { + public R<String> saveZarr(@RequestParam("name") String tableName) throws Exception { List<String> list = CsvToSQLiteUtils.getNameList(tableName); String path = outPath + "\\"; String rainfall = "rainfall\\"; @@ -387,7 +387,7 @@ metry.put("type", "MultiPoint"); metry.put("lod", 0); JSONArray boundarie = new JSONArray(); - boundarie.add(jsonObject.getJSONArray("vertices").size()); + boundarie.add(jsonObject.getJSONArray("vertices").size()-1); metry.put("boundaries", boundarie); geometry.add(metry); cityObject.put("geometry", geometry); @@ -400,7 +400,8 @@ FileWriter fileWriter = new FileWriter(path + tableName + "\\闄嶉洦閲�.json"); fileWriter.write(jsonObject.toJSONString()); fileWriter.close(); - return success(true); + SemUtils.cityJsonToSem(path + tableName + "\\闄嶉洦閲�.json",path + tableName + "\\station_rain.sem"); + return success(path + tableName + "\\station_rain.sem"); } @ApiOperation(value = "绠$偣杞琧ityjson") @@ -428,7 +429,7 @@ metry.put("type", "MultiPoint"); metry.put("lod", 0); JSONArray boundarie = new JSONArray(); - boundarie.add(jsonObject.getJSONArray("vertices").size()); + boundarie.add(jsonObject.getJSONArray("vertices").size()-1); metry.put("boundaries", boundarie); geometry.add(metry); cityObject.put("geometry", geometry); @@ -443,7 +444,8 @@ FileWriter fileWriter = new FileWriter(pointPath); fileWriter.write(jsonObject.toJSONString()); fileWriter.close(); - return success(pointPath); + SemUtils.cityJsonToSem(pointPath,path + times + "\\point.sem"); + return success(path + times + "\\point.sem"); } @ApiOperation(value = "绠$嚎杞琧ityjson") @@ -468,12 +470,14 @@ for (int i = 0; i < array.size(); i++) { JSONObject object = JSONObject.parseObject(array.get(i).toString()); jsonObject.getJSONArray("vertices").add(ProjectionToGeographicUtil.getPoint(Double.valueOf(object.get("x").toString()),Double.valueOf(object.get("y").toString()))); - boundarie.add(jsonObject.getJSONArray("vertices").size()); + boundarie.add(jsonObject.getJSONArray("vertices").size()-1); } JSONArray jsonArray=new JSONArray(); jsonArray.add(boundarie); metry.put("boundaries", jsonArray); - cityObject.put("geometry",metry); + JSONArray metryArray=new JSONArray(); + metryArray.add(metry); + cityObject.put("geometry",metryArray); cityObject.put("attributes",attribute); cityObject.put("attributes", attribute); geometry.add(metry); @@ -488,9 +492,28 @@ FileWriter fileWriter = new FileWriter(pointPath); fileWriter.write(jsonObject.toJSONString()); fileWriter.close(); - return success(pointPath); + SemUtils.cityJsonToSem(pointPath, path + times + "\\line.sem"); + return success(path + times + "\\line.sem"); } - + @ApiOperation(value = "鍦板舰杞琧ityjson") + @GetMapping(value = "/terrainToCityJson", produces = "application/json; charset=UTF-8") + public R<String> terrainToCityJson(@RequestParam("tifPath") String tifPath) throws Exception { + long times = System.currentTimeMillis(); + String path = outPath + "\\terrain\\"+times+"\\"; + File dirFile = new File(path+"appearance"); + if (!dirFile.exists()) { + dirFile.mkdirs(); + } + String pngPath=path+"appearance\\terrain.png"; + TiffToRGBUtil.tifToPng(tifPath,pngPath); + JSONObject jsonObject = getModule("terrainmodule.json"); + jsonObject.put("vertices",TiffCoordinateExtractorUtil.getCoordinate(tifPath)); + 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"); + } public JSONObject getModule(String moduleName) { JSONObject jsonObject = new JSONObject(); try { -- Gitblit v1.9.3