1
13693261870
2024-09-22 e5d40172f9bd9b0b967cb0e74b551f1a135dae6f
1
已修改3个文件
73 ■■■■ 文件已修改
src/main/java/com/se/simu/domain/po/DataPo.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/GedbService.java 35 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/SimuService.java 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/domain/po/DataPo.java
@@ -87,6 +87,11 @@
        this.duration = duration;
    }
    public void setPath(String inPath, String outPath) {
        this.inPath = inPath;
        this.outPath = outPath;
    }
    public boolean setExtent(Double minx, Double miny, Double maxx, Double maxy) {
        this.minx = minx;
        this.miny = miny;
src/main/java/com/se/simu/service/GedbService.java
@@ -13,6 +13,7 @@
import com.se.simu.helper.StringHelper;
import lombok.extern.slf4j.Slf4j;
import org.gdal.gdal.Dataset;
import org.gdal.gdal.WarpOptions;
import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconst;
import org.springframework.beans.factory.annotation.Value;
@@ -99,7 +100,7 @@
        String filePath = inPath + File.separator + fileDb.getDbid();
        downloadFiles(token, filePath, files, fileDb.getDbid(), fileId);
        clipDemFile(filePath, files, basePath, bbox);
        clipDemFile(filePath, files, basePath, bbox, 4528);
        return true;
    }
@@ -332,24 +333,50 @@
        is.close();
    }
    private void clipDemFile(String filePath, List<GeFile> files, String basePath, String bbox) throws Exception {
    private void clipDemFile(String filePath, List<GeFile> files, String basePath, String bbox, int epsg) throws Exception {
        String target = basePath + File.separator + demName;
        for (GeFile file : files) {
            if (file.getName().toLowerCase().endsWith(demType)) {
                String source = filePath + File.separator + file.getName();
                clipDem(source, target, bbox);
                clipDem(source, target, bbox, epsg);
                break;
            }
        }
    }
    private void clipDem(String source, String target, String bbox) throws Exception {
    private void clipDem(String source, String target, String bbox, int epsg) throws Exception {
        Dataset ds = null;
        try {
            ds = gdal.Open(source, gdalconst.GA_ReadOnly);
            if (null == ds || ds.getRasterCount() < 1 || null == ds.GetSpatialRef()) throw new Exception("DEM数据无效");
            // String bbox = "116.64388473935195,39.884315914604464,116.64754729082588,39.887069143903496";
            String[] bb = bbox.split(",");
            // gdalwarp -ot UInt16 -s_srs EPSG:4326 -t_srs EPSG:2382 -r bilinear -of GTiff -te 116.526854182 40.0481829856 116.532848182 40.0541769856
            // -te_srs EPSG:4326 -co COMPRESS=DEFLATE -co PREDICTOR=1 -co ZLEVEL=6 -co TILED=YES -wo OPTIMIZE_SIZE=TRUE E:\GDALhomework\000002.tif E:/CSDN/warped1.tif
            Vector<String> vector = new Vector<>();
            //vector.add("-s_srs");
            //vector.add("EPSG:" + 4326);
            vector.add("-t_srs");
            vector.add("EPSG:" + epsg);
            vector.add("-r");
            vector.add("bilinear");
            vector.add("-of");
            vector.add("GTiff");
            vector.add("-te");
            vector.add(bb[0]);
            vector.add(bb[1]);
            vector.add(bb[2]);
            vector.add(bb[3]);
            vector.add("-te_srs");
            vector.add("EPSG:" + 4326);
            WarpOptions warpOptions = new WarpOptions(vector);
            Dataset destDs = gdal.Warp(target, new Dataset[]{ds}, warpOptions);
            destDs.delete();
        } finally {
            if (null != ds) ds.delete();
        }
src/main/java/com/se/simu/service/SimuService.java
@@ -46,6 +46,9 @@
    @Resource
    SimuMapper simuMapper;
    @Resource
    GedbService gedbService;
    /**
     * 获取
     */
@@ -121,9 +124,28 @@
    public boolean create(CreateSimuVo vo) {
        DataPo data = BeanUtil.copyProperties(vo, DataPo.class);
        SimuPo simu = new SimuPo(vo.getNum(), vo.getName(), JSONUtil.toJsonStr(data), 0, vo.getBak());
        //
        return true;
        data.setPath(vo.getName(), vo.getName());
        initPath(data);
        int rows = simuMapper.insert(simu);
        if (rows > 0) {
            asyncCall(simu);
        }
        return rows > 0;
    }
    private void initPath(DataPo data) {
        createDir(inPath + File.separator + data.getInPath());
        createDir(outPath + File.separator + data.getOutPath());
    }
    private void createDir(String path) {
        File dir = new File(path);
        if (!dir.exists() || !dir.isDirectory()) {
            dir.mkdirs();
        }
    }
    private void asyncCall(SimuPo simu) {
@@ -132,13 +154,16 @@
            @Override
            @SneakyThrows
            public void run() {
                scopeTask(simu);
                scope(simu);
            }
        });
        executor.shutdown();
    }
    private void scopeTask(SimuPo simu) {
    /**
     * 处理,状态:0-创建仿真,1-连接GEDB库,2-下载空间数据,3-下载高程数据,4-模拟内涝仿真,5-处理仿真数据,10-完成,-10-出错
     */
    private void scope(SimuPo simu) {
        try {
            DataPo data = JSONUtil.toBean(simu.getData(), DataPo.class);
            update(simu, 1, null);