From 30a47805b1e3233827a6a2db4d97bfb7f6250384 Mon Sep 17 00:00:00 2001 From: 张洋洋 <10611411+yang-yang-z@user.noreply.gitee.com> Date: 星期四, 13 二月 2025 11:56:47 +0800 Subject: [PATCH] [add]tif裁剪 --- src/main/java/com/se/simu/config/PropertiesConfig.java | 10 +++++ src/main/java/com/se/simu/utils/TiffToRGBUtil.java | 2 src/main/resources/terrainmodule.json | 2 src/main/resources/application-zyy.yml | 1 src/main/java/com/se/simu/controller/SimuController.java | 47 +++++++++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/se/simu/config/PropertiesConfig.java b/src/main/java/com/se/simu/config/PropertiesConfig.java index cb2ef33..1e5427e 100644 --- a/src/main/java/com/se/simu/config/PropertiesConfig.java +++ b/src/main/java/com/se/simu/config/PropertiesConfig.java @@ -72,6 +72,8 @@ private boolean copyTif; + private String tifPath; + public String getVer() { return ver; } @@ -319,4 +321,12 @@ public void setCopyTif(boolean copyTif) { this.copyTif = copyTif; } + + public String getTifPath() { + return tifPath; + } + + public void setTifPath(String tifPath) { + this.tifPath = tifPath; + } } diff --git a/src/main/java/com/se/simu/controller/SimuController.java b/src/main/java/com/se/simu/controller/SimuController.java index c1282d6..cc52949 100644 --- a/src/main/java/com/se/simu/controller/SimuController.java +++ b/src/main/java/com/se/simu/controller/SimuController.java @@ -696,6 +696,53 @@ SemUtils.cityJsonToSem(pointPath, filePatn + "link.sem"); return success(filePatn + "link.sem"); } + @ApiOperation(value = "鍦板舰杞瑂em") + @PostMapping(value = "/terrainToSem", produces = "application/json; charset=UTF-8") + public R<String> terrainToSem(@RequestBody List<GridDto> dtos) 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"); + jsonObject.put("vertices", TiffCoordinateExtractorUtil.getCoordinate(tifPath)); + FileWriter fileWriter = new FileWriter(path + "terrain.json"); + fileWriter.write(jsonObject.toJSONString()); + fileWriter.close(); + 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 = "鍦板舰杞琧ityjson") @GetMapping(value = "/terrainToCityJson", produces = "application/json; charset=UTF-8") diff --git a/src/main/java/com/se/simu/utils/TiffToRGBUtil.java b/src/main/java/com/se/simu/utils/TiffToRGBUtil.java index 66a41bd..45bda87 100644 --- a/src/main/java/com/se/simu/utils/TiffToRGBUtil.java +++ b/src/main/java/com/se/simu/utils/TiffToRGBUtil.java @@ -14,7 +14,7 @@ public class TiffToRGBUtil { public static void main(String[] args) throws Exception{ - tifToPng("D:\\鍩庡競鍐呮稘\\sem\\DEM100.tif","D:\\鍩庡競鍐呮稘\\sem\\DEM100.png"); + tifToPng("D:\\鍩庡競鍐呮稘\\sem\\tongzhou_1m_tif\\tongzhou_raster_4548_1m_clip_river_fill.tif","D:\\鍩庡競鍐呮稘\\sem\\tongzhou_1m_tif\\tongzhou_raster_4548_1m_clip_river_fill.png"); } public static void tifToPng(String tifPath, String pngPath) throws Exception { // 娉ㄥ唽鎵�鏈夌殑 GDAL 椹卞姩 diff --git a/src/main/resources/application-zyy.yml b/src/main/resources/application-zyy.yml index 91e5d15..0c609a4 100644 --- a/src/main/resources/application-zyy.yml +++ b/src/main/resources/application-zyy.yml @@ -153,3 +153,4 @@ waterPath: depth flowPath: velocity copyTif: false + tifPath: D:\鍩庡競鍐呮稘\sem\tongzhou_1m_tif\tongzhou_raster_4548_1m_clip_river_fill.tif diff --git a/src/main/resources/terrainmodule.json b/src/main/resources/terrainmodule.json index b6990de..fb5a9ea 100644 --- a/src/main/resources/terrainmodule.json +++ b/src/main/resources/terrainmodule.json @@ -1 +1 @@ -{"type":"CityJSON","version":"1.0","CityObjects":{"UUID_63b11762-6a6a-4d91-b497-6314fee1ce0f":{"type":"+Terrain","geometry":[{"type":"MultiSurface","boundaries":[[[0,1,2,3]]],"texture":{"visual":{"values":[[[0,0,1,2,3]]]}},"lod":0}]}},"appearance":{"textures":[{"type":"PNG","image":"appearances/terrain.png"}],"vertices-texture":[[0.0,0.0],[0.0,1.0],[1.0,1.0],[1.0,0.0]]}} \ No newline at end of file +{"type":"CityJSON","version":"1.0","CityObjects":{"UUID_63b11762-6a6a-4d91-b497-6314fee1ce0f":{"type":"+Terrain","geometry":[{"type":"MultiSurface","boundaries":[[[0,1,2,3]]],"texture":{"visual":{"values":[[[0,0,1,2,3]]]}},"lod":0}]}},"appearance":{"textures":[{"type":"PNG","image":"appearance/terrain.png"}],"vertices-texture":[[0.0,0.0],[0.0,1.0],[1.0,1.0],[1.0,0.0]]}} \ No newline at end of file -- Gitblit v1.9.3