张洋洋
2025-02-12 75a3851294865b31d228872ea677f80cd0cda028
[add]tif裁剪
已添加1个文件
已修改3个文件
143 ■■■■■ 文件已修改
src/main/java/com/se/simu/controller/SimuController.java 96 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/utils/ProjectionToGeographicUtil.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/utils/TiffClipper.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/utils/TiffToRGBUtil.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/controller/SimuController.java
@@ -492,54 +492,54 @@
        SemUtils.cityJsonToSem(pointPath, filePatn + "node.sem");
        return success(filePatn + "node.sem");
    }
//    @ApiOperation(value = "管点转cityjson")
//    @GetMapping(value = "/pointToCityJson", produces = "application/json; charset=UTF-8")
//    public R<String> pointToCityJson(@RequestParam("shpPath") String shpPath) throws Exception {
//        String path = outPath + "\\point\\";
//        List<Map<String, Object>> list = ShpReadUtils.readPointShp(shpPath);
//        JSONObject jsonObject = getModule("pointmodule.json");
//        for (Map<String, Object> map : list
//        ) {
//            //拼装坐标
//            JSONArray vertice = new JSONArray();
//            vertice.add(map.get("lon"));
//            vertice.add(map.get("lat"));
//            vertice.add(0.0);
//            jsonObject.getJSONArray("vertices").add(vertice);
//            //拼装基础信息
//            JSONObject cityObject = new JSONObject();
//            cityObject.put("type", "+PipePoint");
//            JSONObject attribute = new JSONObject();
//            attribute.put("name", map.get("fsw"));
//            cityObject.put("attributes", attribute);
//            JSONArray geometry = new JSONArray();
//            JSONObject metry = new JSONObject();
//            metry.put("type", "MultiPoint");
//            metry.put("lod", 0);
//            JSONArray boundarie = new JSONArray();
//            boundarie.add(jsonObject.getJSONArray("vertices").size() - 1);
//            metry.put("boundaries", boundarie);
//            geometry.add(metry);
//            cityObject.put("geometry", geometry);
//            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);
//        fileWriter.write(jsonObject.toJSONString());
//        fileWriter.close();
//        String filePatn = inPath + "\\tongzhou\\";
//        File file = new File(filePatn);
//        if (!file.exists()) {
//            file.mkdirs();
//        }
//        SemUtils.cityJsonToSem(pointPath, filePatn + "node.sem");
//        return success(filePatn + "node.sem");
//    }
    @ApiOperation(value = "管点转cityjson")
    @GetMapping(value = "/pointToCityJson", produces = "application/json; charset=UTF-8")
    public R<String> pointToCityJson(@RequestParam("shpPath") String shpPath) throws Exception {
        String path = outPath + "\\point\\";
        List<Map<String, Object>> list = ShpReadUtils.readPointShp(shpPath);
        JSONObject jsonObject = getModule("pointmodule.json");
        for (Map<String, Object> map : list
        ) {
            //拼装坐标
            JSONArray vertice = new JSONArray();
            vertice.add(map.get("lon"));
            vertice.add(map.get("lat"));
            vertice.add(0.0);
            jsonObject.getJSONArray("vertices").add(vertice);
            //拼装基础信息
            JSONObject cityObject = new JSONObject();
            cityObject.put("type", "+PipePoint");
            JSONObject attribute = new JSONObject();
            attribute.put("name", map.get("fsw"));
            cityObject.put("attributes", attribute);
            JSONArray geometry = new JSONArray();
            JSONObject metry = new JSONObject();
            metry.put("type", "MultiPoint");
            metry.put("lod", 0);
            JSONArray boundarie = new JSONArray();
            boundarie.add(jsonObject.getJSONArray("vertices").size() - 1);
            metry.put("boundaries", boundarie);
            geometry.add(metry);
            cityObject.put("geometry", geometry);
            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);
        fileWriter.write(jsonObject.toJSONString());
        fileWriter.close();
        String filePatn = inPath + "\\tongzhou\\";
        File file = new File(filePatn);
        if (!file.exists()) {
            file.mkdirs();
        }
        SemUtils.cityJsonToSem(pointPath, filePatn + "node.sem");
        return success(filePatn + "node.sem");
    }
    @ApiOperation(value = "管线sem生成")
    @PostMapping(value = "/lineToSem", produces = "application/json; charset=UTF-8")
src/main/java/com/se/simu/utils/ProjectionToGeographicUtil.java
@@ -51,7 +51,6 @@
    }
    public static void main(String[] args) {
        System.out.println(getPoint(470554.2614775232,4416699.023973457));
        System.out.println(get4548Point(116.65575979450138,39.883938395445966));
        System.out.println(get4548Point(116.66,39.8962));
    }
}
src/main/java/com/se/simu/utils/TiffClipper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,42 @@
package com.se.simu.utils;
import org.gdal.gdal.Dataset;
import org.gdal.gdal.TranslateOptions;
import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconstConstants;
import java.util.Vector;
public class TiffClipper {
    public static void cropTiffByLatLon(String inputFilePath, String outputFilePath,
                                        double minX, double minY, double maxX, double maxY) throws Exception{
        // æ³¨å†Œæ‰€æœ‰ GDAL é©±åЍ
        gdal.AllRegister();
        Vector vector=new Vector();
        vector.add("-projwin");
        vector.add(String.valueOf(minX));
        vector.add(String.valueOf(maxY));
        vector.add(String.valueOf(maxX));
        vector.add(String.valueOf(minY));
        TranslateOptions options = new TranslateOptions(vector);
        // æ‰“开输入数据集
        Dataset ds = gdal.Open(inputFilePath, gdalconstConstants.GA_ReadOnly);
        if (ds == null) {
            throw new Exception("无法打开输入文件: " + inputFilePath);
        }
        // æ‰§è¡Œè£å‰ªæ“ä½œ
        Dataset outputDataset = gdal.Translate(outputFilePath, ds, options);
        if (outputDataset != null) {
            System.out.println("裁剪成功,输出文件: " + outputFilePath);
            // é‡Šæ”¾æ•°æ®é›†èµ„源
            outputDataset.delete();
        } else {
            System.err.println("裁剪失败");
        }
        // é”€æ¯ GDAL é©±åŠ¨ç®¡ç†å™¨
        gdal.GDALDestroyDriverManager();
    }
    public static void main(String[] args) throws Exception{
        cropTiffByLatLon("D:\\城市内涝\\sem\\DEM.tif","D:\\城市内涝\\sem\\DEM100.tif",470066.5191659781,4417962.449727667,470922.1436516798,4418059.07638588);
    }
}
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\\DEM.tif","D:\\城市内涝\\sem\\DEM.png");
       tifToPng("D:\\城市内涝\\sem\\DEM100.tif","D:\\城市内涝\\sem\\DEM100.png");
    }
    public static void tifToPng(String tifPath, String pngPath) throws Exception {
        // æ³¨å†Œæ‰€æœ‰çš„ GDAL é©±åЍ