1
13693261870
2024-09-23 9981cd49e3fd18691fb6cbe472c93576af58e8df
1
已修改3个文件
75 ■■■■■ 文件已修改
src/main/java/com/se/simu/controller/SimuController.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/GedbService.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/SimuService.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/controller/SimuController.java
@@ -1,6 +1,7 @@
package com.se.simu.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.se.simu.domain.po.DataPo;
import com.se.simu.domain.po.SimuPo;
import com.se.simu.domain.vo.CreateSimuVo;
import com.se.simu.domain.vo.R;
@@ -135,10 +136,11 @@
    @GetMapping("/test")
    public R<Object> test() {
        try {
            String name = "20240913";
            // 469538.6536261877,4416744.922022615,469853.14714664617,4417049.378602433
            String bbox = "116.64388473935195,39.884315914604464,116.64754729082588,39.887069143903496";
            String taskName = "20240913";
            Object rs = gedbService.test(bbox, taskName);
            //String bbox = "116.64388473935195,39.884315914604464,116.64754729082588,39.887069143903496";
            DataPo data = new DataPo(name, name, name, 116.64388473935195, 39.884315914604464, 116.64754729082588, 39.887069143903496, 50.0, 25);
            Object rs = gedbService.test(data);
            return success(rs);
        } catch (Exception ex) {
src/main/java/com/se/simu/service/GedbService.java
@@ -83,8 +83,8 @@
    @Resource
    RestTemplate restTemplate;
    public boolean test(String bbox, String taskName) throws Exception {
        String token = getToken();
    public boolean test(DataPo data) throws Exception {
        /*String token = getToken();
        GeDb db = getSeDb(token);
        db.setBbox(bbox);
@@ -101,9 +101,24 @@
        String filePath = inPath + File.separator + fileDb.getDbid();
        downloadFiles(token, filePath, files, fileDb.getDbid(), fileId);
        clipDemFile(filePath, files, basePath, bbox, 4548);
        clipDemFile(filePath, files, basePath, bbox, 4548);*/
        String token = getToken();
        GeDb db = connectGedb(token, data);
        copeVectors(token, data, db);
        copeDem(token, data);
        return true;
    }
    private void createPath(String path) {
        File f = new File(path);
        if (f.exists() && f.isDirectory()) {
            FileUtil.del(f);
        }
        f.mkdirs();
    }
    public String getToken() throws Exception {
@@ -135,7 +150,15 @@
        return obj.getStr("data");
    }
    public GeDb getSeDb(String token) {
    public GeDb connectGedb(String token, DataPo data) {
        GeDb db = getSeDb(token);
        db.setBbox(data.getBbox());
        data.setEpsg(db.getEpsg());
        return db;
    }
    private GeDb getSeDb(String token) {
        Map<String, Object> map = new HashMap<>(1);
        map.put("token", token);
@@ -238,8 +261,11 @@
        return data.getJSONArray("features");
    }
    public void copeVectors(DataPo data, List<GeLayer> layers) throws Exception {
    public void copeVectors(String token, DataPo data, GeDb db) throws Exception {
        String basePath = inPath + File.separator + data.getInPath();
        List<GeLayer> layers = getLayers(token, db);
        queryData(token, db, layers);
        createShps(basePath, layers);
    }
@@ -257,10 +283,9 @@
        String fileId = getFileId(token, fileDb.getDbid());
        List<GeFile> files = getFileNames(token, fileDb.getDbid(), fileId);
        String basePath = inPath + File.separator + data.getInPath();
        String filePath = inPath + File.separator + fileDb.getDbid();
        downloadFiles(token, filePath, files, fileDb.getDbid(), fileId);
        clipDemFile(filePath, files, basePath, data.getBbox(), 0);
        clipDemFile(filePath, files, data);
    }
    private GeDb getFileDb(String token) {
@@ -342,40 +367,38 @@
        is.close();
    }
    private void clipDemFile(String filePath, List<GeFile> files, String basePath, String bbox, int epsg) throws Exception {
        String target = basePath + File.separator + demFile;
    private void clipDemFile(String filePath, List<GeFile> files, DataPo data) throws Exception {
        String target = inPath + File.separator + data.getInPath() + File.separator + demFile;
        for (GeFile file : files) {
            if (file.getName().toLowerCase().endsWith(demType)) {
                String source = filePath + File.separator + file.getName();
                clipDem(source, target, bbox, epsg);
                clipDem(source, target, data);
                break;
            }
        }
    }
    private void clipDem(String source, String target, String bbox, int epsg) throws Exception {
    private void clipDem(String source, String target, DataPo data) 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(",");
            Vector<String> vector = new Vector<>();
            //vector.add("-s_srs");
            //vector.add("EPSG:" + 4326);
            vector.add("-t_srs");
            vector.add("EPSG:" + epsg);
            vector.add("EPSG:" + data.getEpsg());
            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(data.getMinx().toString());
            vector.add(data.getMiny().toString());
            vector.add(data.getMaxx().toString());
            vector.add(data.getMaxy().toString());
            vector.add("-te_srs");
            vector.add("EPSG:" + 4326);
            WarpOptions warpOptions = new WarpOptions(vector);
src/main/java/com/se/simu/service/SimuService.java
@@ -172,14 +172,10 @@
            update(simu, 1, null);
            String token = gedbService.getToken();
            GeDb db = gedbService.getSeDb(token);
            db.setBbox(data.getBbox());
            data.setEpsg(db.getEpsg());
            GeDb db = gedbService.connectGedb(token, data);
            update(simu, 2, null);
            List<GeLayer> layers = gedbService.getLayers(token, db);
            gedbService.queryData(token, db, layers);
            gedbService.copeVectors(data, layers);
            gedbService.copeVectors(token, data, db);
            update(simu, 3, null);
            gedbService.copeDem(token, data);