| | |
| | | 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; |
| | |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/waterlogging") |
| | | public class WaterController { |
| | | public class WaterController extends BaseController { |
| | | @Resource |
| | | SimuService simuService; |
| | | |
| | |
| | | @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) { |
| | |
| | | } |
| | | |
| | | // 根据服务名+时间戳+坐标,查询对应的积水深度 |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | * @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])); |