13693261870
2024-10-31 f7c642eed8ae076553f95a1f0ac5fd2e7c31b6a1
修改返回值
已修改2个文件
18 ■■■■■ 文件已修改
src/main/java/com/se/simu/controller/WaterController.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/WaterService.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/controller/WaterController.java
@@ -1,6 +1,7 @@
package com.se.simu.controller;
import com.se.simu.domain.po.SimuPo;
import com.se.simu.domain.vo.R;
import com.se.simu.helper.WebHelper;
import com.se.simu.service.SimuService;
import com.se.simu.service.WaterService;
@@ -28,7 +29,7 @@
@Slf4j
@RestController
@RequestMapping("/waterlogging")
public class WaterController {
public class WaterController extends BaseController {
    @Resource
    SimuService simuService;
@@ -134,7 +135,7 @@
            @ApiImplicitParam(name = "y", value = "Y", dataType = "double", paramType = "query", example = "39.8868915"),
            @ApiImplicitParam(name = "timestamp", value = "时间戳", dataType = "long", paramType = "query", example = "1730217660000")
    })
    public Double getWaterHeight(@PathVariable String serviceName, double x, double y, long timestamp, HttpServletResponse res) {
    public R<Double> getWaterHeight(@PathVariable String serviceName, double x, double y, long timestamp, HttpServletResponse res) {
        try {
            SimuPo simu = simuService.getSimuByServiceName(serviceName);
            if (null == simu) {
@@ -142,10 +143,10 @@
            }
            // 根据服务名+时间戳+坐标,查询对应的积水深度
            return waterService.getWaterHeight(simu, x, y, timestamp);
            return success(waterService.getWaterHeight(simu, x, y, timestamp));
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return null;
            return fail(ex);
        }
    }
src/main/java/com/se/simu/service/WaterService.java
@@ -152,11 +152,10 @@
                return null;
            }
            double[] values = new double[1];
            ds.GetRasterBand(1).ReadRaster(XY[0], XY[1], 1, 1, values);
            double val = values[0];
            double[] vals = new double[1];
            ds.GetRasterBand(1).ReadRaster(XY[0], XY[1], 1, 1, vals);
            return isValid(val) ? val : null;
            return isValid(vals[0]) ? vals[0] : null;
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return null;
@@ -184,8 +183,6 @@
     * @return 像素坐标
     */
    public int[] coordinates2ColRow(double[] gt, double x, double y) {
        int[] ints = new int[2];
        // 向下取整,如果向上取整会导致计算结果偏大,从而在后面读取到邻近像元的数据
        //Double col = Math.floor(((y - gt[3]) * gt[1] - (x - gt[0]) * gt[4]) / (gt[5] * gt[1] - gt[2] * gt[4]));
        Double col = Math.floor((y * gt[1] - x * gt[4] + gt[0] * gt[4] - gt[3] * gt[1]) / (gt[5] * gt[1] - gt[2] * gt[4]));