张洋洋
2025-02-13 30a47805b1e3233827a6a2db4d97bfb7f6250384
[add]tif裁剪
已修改5个文件
62 ■■■■■ 文件已修改
src/main/java/com/se/simu/config/PropertiesConfig.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/controller/SimuController.java 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/utils/TiffToRGBUtil.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-zyy.yml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/terrainmodule.json 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
    }
}
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 = "地形转sem")
    @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 = "地形转cityjson")
    @GetMapping(value = "/terrainToCityJson", produces = "application/json; charset=UTF-8")
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 驱动
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
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]]}}
{"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]]}}