From 3c7edc1846cab6a1bdc02512a5f59a4031e2e07e Mon Sep 17 00:00:00 2001 From: 张洋洋 <10611411+yang-yang-z@user.noreply.gitee.com> Date: 星期六, 08 二月 2025 14:24:34 +0800 Subject: [PATCH] [add]cityjson转sem --- src/main/java/com/se/simu/domain/dto/GridDto.java | 26 +++++++++++++ src/main/resources/grid.json | 1 src/main/java/com/se/simu/utils/SemUtils.java | 17 +------- src/main/java/com/se/simu/controller/SimuController.java | 60 ++++++++++++++++++++++------- 4 files changed, 75 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/se/simu/controller/SimuController.java b/src/main/java/com/se/simu/controller/SimuController.java index 58bdf74..e11153d 100644 --- a/src/main/java/com/se/simu/controller/SimuController.java +++ b/src/main/java/com/se/simu/controller/SimuController.java @@ -7,6 +7,7 @@ import com.se.simu.config.PropertiesConfig; import com.se.simu.domain.dto.GeDb; import com.se.simu.domain.dto.GeLayer; +import com.se.simu.domain.dto.GridDto; import com.se.simu.domain.po.DataPo; import com.se.simu.domain.po.SimuPo; import com.se.simu.domain.vo.*; @@ -387,7 +388,7 @@ metry.put("type", "MultiPoint"); metry.put("lod", 0); JSONArray boundarie = new JSONArray(); - boundarie.add(jsonObject.getJSONArray("vertices").size()-1); + boundarie.add(jsonObject.getJSONArray("vertices").size() - 1); metry.put("boundaries", boundarie); geometry.add(metry); cityObject.put("geometry", geometry); @@ -400,7 +401,7 @@ FileWriter fileWriter = new FileWriter(path + tableName + "\\闄嶉洦閲�.json"); fileWriter.write(jsonObject.toJSONString()); fileWriter.close(); - SemUtils.cityJsonToSem(path + tableName + "\\闄嶉洦閲�.json",path + tableName + "\\station_rain.sem"); + SemUtils.cityJsonToSem(path + tableName + "\\闄嶉洦閲�.json", path + tableName + "\\station_rain.sem"); return success(path + tableName + "\\station_rain.sem"); } @@ -429,7 +430,7 @@ metry.put("type", "MultiPoint"); metry.put("lod", 0); JSONArray boundarie = new JSONArray(); - boundarie.add(jsonObject.getJSONArray("vertices").size()-1); + boundarie.add(jsonObject.getJSONArray("vertices").size() - 1); metry.put("boundaries", boundarie); geometry.add(metry); cityObject.put("geometry", geometry); @@ -444,7 +445,7 @@ FileWriter fileWriter = new FileWriter(pointPath); fileWriter.write(jsonObject.toJSONString()); fileWriter.close(); - SemUtils.cityJsonToSem(pointPath,path + times + "\\point.sem"); + SemUtils.cityJsonToSem(pointPath, path + times + "\\point.sem"); return success(path + times + "\\point.sem"); } @@ -469,16 +470,16 @@ 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()); - jsonObject.getJSONArray("vertices").add(ProjectionToGeographicUtil.getPoint(Double.valueOf(object.get("x").toString()),Double.valueOf(object.get("y").toString()))); - boundarie.add(jsonObject.getJSONArray("vertices").size()-1); + jsonObject.getJSONArray("vertices").add(ProjectionToGeographicUtil.getPoint(Double.valueOf(object.get("x").toString()), Double.valueOf(object.get("y").toString()))); + boundarie.add(jsonObject.getJSONArray("vertices").size() - 1); } - JSONArray jsonArray=new JSONArray(); + JSONArray jsonArray = new JSONArray(); jsonArray.add(boundarie); metry.put("boundaries", jsonArray); - JSONArray metryArray=new JSONArray(); + JSONArray metryArray = new JSONArray(); metryArray.add(metry); - cityObject.put("geometry",metryArray); - cityObject.put("attributes",attribute); + cityObject.put("geometry", metryArray); + cityObject.put("attributes", attribute); cityObject.put("attributes", attribute); geometry.add(metry); jsonObject.getJSONObject("CityObjects").put("UUID_" + UUID.randomUUID().toString(), cityObject); @@ -495,25 +496,54 @@ 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"); + 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); + String pngPath = path + "appearance\\terrain.png"; + TiffToRGBUtil.tifToPng(tifPath, pngPath); JSONObject jsonObject = getModule("terrainmodule.json"); - jsonObject.put("vertices",TiffCoordinateExtractorUtil.getCoordinate(tifPath)); + 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"); } + + @ApiOperation(value = "grid杞琧ityjson") + @PostMapping(value = "/gridToCityJson", produces = "application/json; charset=UTF-8") + public R<String> gridToCityJson(@RequestBody List<GridDto> dtos) throws Exception { + long times = System.currentTimeMillis(); + String path = outPath + "\\grid\\" + times + "\\"; + 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(); + jsonArray.add(dto.getLon()); + jsonArray.add(dto.getLat()); + jsonArray.add(0); + array.add(jsonArray); + } + 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"); + } + public JSONObject getModule(String moduleName) { JSONObject jsonObject = new JSONObject(); try { diff --git a/src/main/java/com/se/simu/domain/dto/GridDto.java b/src/main/java/com/se/simu/domain/dto/GridDto.java new file mode 100644 index 0000000..fb18ec7 --- /dev/null +++ b/src/main/java/com/se/simu/domain/dto/GridDto.java @@ -0,0 +1,26 @@ +package com.se.simu.domain.dto; + +import java.io.Serializable; + +public class GridDto implements Serializable { + + private Double lat; + + private Double lon; + + public Double getLat() { + return lat; + } + + public void setLat(Double lat) { + this.lat = lat; + } + + public Double getLon() { + return lon; + } + + public void setLon(Double lon) { + this.lon = lon; + } +} diff --git a/src/main/java/com/se/simu/utils/SemUtils.java b/src/main/java/com/se/simu/utils/SemUtils.java index b16bf0a..f0fe654 100644 --- a/src/main/java/com/se/simu/utils/SemUtils.java +++ b/src/main/java/com/se/simu/utils/SemUtils.java @@ -5,18 +5,7 @@ public class SemUtils { public static void main(String[] args) throws Exception { - //cityjson杞瑂em 绠$偣 瀹屾垚 -// SEM sem = SEM.fromCityJSON("D:\\out\\point\\1737602481122\\绠$偣.json"); -// sem.writeToFile("D:\\out\\point\\1737602481122\\point.sem"); - //cityjson杞瑂em 绠$嚎 -// SEM sem = SEM.fromCityJSON("D:\\out\\line\\1737615372545\\绠$嚎.json"); -// sem.writeToFile("D:\\out\\line\\1737615372545\\绠$嚎.sem"); - //cityjson杞瑂em 鍦板舰 瀹屾垚 -// SEM sem = SEM.fromCityJSON("D:\\out\\terrain\\1737603153671\\terrain.json"); -// sem.writeToFile("D:\\out\\terrain\\1737603153671\\terrain.sem"); - //cityjson杞瑂em 闄嶉洦(鎴愬姛) - SEM sem = SEM.fromCityJSON("D:\\out\\station_rain_1736399134241\\闄嶉洦閲�.json"); - sem.writeToFile("D:\\out\\station_rain_1736399134241\\闄嶉洦閲�.sem"); + semToCityJson(); } public static void cityJsonToSem(String jsonUrl,String semUrl) throws Exception { //cityjson杞瑂em @@ -25,7 +14,7 @@ } public static void semToCityJson() throws Exception { //sem杞琧ityjson - SEM sem2 = new SEM("C:\\XXX\\Grid.sem"); - sem2.writeToCityJSON("C:\\XXX\\Gridout.json"); + SEM sem2 = new SEM("D:\\鍩庡競鍐呮稘\\sem\\tongzhou\\tongzhou\\grid.sem"); + sem2.writeToCityJSON("D:\\鍩庡競鍐呮稘\\sem\\tongzhou\\tongzhou\\grid\\grid.json"); } } diff --git a/src/main/resources/grid.json b/src/main/resources/grid.json new file mode 100644 index 0000000..f3ddb4c --- /dev/null +++ b/src/main/resources/grid.json @@ -0,0 +1 @@ +{"type":"CityJSON","version":"1.0","metadata":{"datasetPointOfContact":{}},"Dynamizers":[{"gmlId":"UUID_f5a04e3c-ba56-44d0-922d-de80f208267a"}],"CityObjects":{"UUID_f5a04e3c-ba56-44d0-922d-de80f208267a":{"type":"+Grid","geometry":[{"type":"MultiSurface","boundaries":[[[0,1,2,3]]],"lod":0}]}},"vertices":[],"appearance":{"materials":[],"textures":[],"vertices-texture":[]},"geometry-templates":{"templates":[],"vertices-templates":[]}} \ No newline at end of file -- Gitblit v1.9.3