月球大数据地理空间分析展示平台-【后端】-月球后台服务
13693261870
2023-11-16 906e2586e2e6e95830f93b50f8c5233189007715
完成坡度分析开发
已修改3个文件
47 ■■■■ 文件已修改
src/main/java/com/moon/server/controller/data/RasterAnalysisController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/moon/server/entity/data/PointEntity.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/moon/server/service/data/SlopeAnalysisService.java 37 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/moon/server/controller/data/RasterAnalysisController.java
@@ -159,7 +159,7 @@
    @SysLog()
    @ApiOperation(value = "下载坡度分析Excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wkt", value = "WKT字符串", dataType = "String", example = "POLYGON ((-103.2 -12.9,-84.2 -14.3,-86.8 -27.5,-105.1 -25.3,-103.2 -12.9))")
            @ApiImplicitParam(name = "wkt", value = "WKT字符串", dataType = "String", example = "POLYGON ((-73.093 4.598,-72.494 4.669,-72.951 4.241,-73.093 4.598))")
    })
    @GetMapping(value = "/downloadSlopXls")
    public void downloadSlopXls(String wkt, HttpServletRequest req, HttpServletResponse res) {
src/main/java/com/moon/server/entity/data/PointEntity.java
@@ -1,5 +1,7 @@
package com.moon.server.entity.data;
import com.moon.server.helper.WebHelper;
/**
 * 点实体类
 * @author WWW
@@ -16,9 +18,9 @@
    }
    public PointEntity(double x, double y, double val) {
        this.x = x;
        this.y = y;
        this.val = val;
        this.x = WebHelper.round(x, 6);
        this.y = WebHelper.round(y, 6);
        this.val = WebHelper.round(val, 2);
    }
    public double getX() {
src/main/java/com/moon/server/service/data/SlopeAnalysisService.java
@@ -1,8 +1,9 @@
package com.moon.server.service.data;
import com.moon.server.entity.all.StaticData;
import com.moon.server.entity.ctrl.CountEntity;
import com.moon.server.entity.data.PointEntity;
import com.moon.server.helper.FileHelper;
import com.moon.server.helper.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.gdal.gdal.Dataset;
@@ -12,11 +13,10 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
/**
 * 栅格分析服务
@@ -28,6 +28,9 @@
    @Value("${sys.path.slopFile}")
    private String filePath;
    @Resource
    protected PathHelper pathHelper;
    private String xlsTemplate;
    private final static Log log = LogFactory.getLog(SlopeAnalysisService.class);
@@ -37,7 +40,7 @@
     */
    private String getXlsTemplate() {
        if (null == xlsTemplate) {
            xlsTemplate = FileHelper.getClassPath() + File.separator + "config" + File.separator + "slop.xlsx";
            xlsTemplate = FileHelper.getClassPath() + "config/slope.xlsx";
        }
        return xlsTemplate;
@@ -59,7 +62,13 @@
                throw new Exception("分析结果为空(查询范围无效)");
            }
            //
            String xlsFile = createXls(list, getXlsTemplate());
            if (null == xlsFile || !new File(xlsFile).exists()) {
                throw new Exception("创建坡度分析Excel失败");
            }
            String fileName = FileHelper.getFileName(xlsFile);
            WebHelper.download(xlsFile, fileName, res);
        } finally {
            if (null != ds) {
                ds.delete();
@@ -97,11 +106,25 @@
                ds.GetRasterBand(StaticData.I1).ReadRaster(x, y, 1, 1, values);
                if (!Double.isNaN(values[0])) {
                    list.add(new PointEntity(point.GetY(), point.GetX(), values[0]));
                    list.add(new PointEntity(point.GetX(), point.GetY(), values[0]));
                }
            }
        }
        return list;
    }
    /**
     * 创建Excel
     */
    public String createXls(List<PointEntity> list, String template) {
        String target = pathHelper.getTempPath() + File.separator + "slope_" + StringHelper.YMD2_FORMAT.format(new Date()) + ".xlsx";
        Map<String, List<PointEntity>> map = new HashMap<>(1);
        map.put("data", list);
        ExcelHelper.writeToTemplate(template, target, map);
        return target;
    }
}