月球大数据地理空间分析展示平台-【后端】-月球后台服务
13693261870
2023-09-11 9ba86955948dff0655ce7f028beddfdce2bad0b4
src/main/java/com/moon/server/controller/data/RasterAnalysisController.java
@@ -3,21 +3,20 @@
import com.moon.server.annotation.SysLog;
import com.moon.server.controller.all.BaseController;
import com.moon.server.entity.all.ResponseMsg;
import com.moon.server.helper.StringHelper;
import com.moon.server.helper.WebHelper;
import com.moon.server.service.data.RasterAnalysisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.gdal.ogr.Geometry;
import org.gdal.ogr.ogr;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 * 栅格分析
@@ -28,18 +27,35 @@
@RestController
@RequestMapping("/rasterAnalysis")
public class RasterAnalysisController extends BaseController {
    @Resource
    RasterAnalysisService rasterService;
    private final static List<Integer> PIXELS = new ArrayList<>(Arrays.asList(1, 2, 4, 8, 16, 32, 64, 128, 256));
    @SysLog()
    @ApiOperation(value = "查询点分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wkt", value = "点WKT", dataType = "String", example = "")
            @ApiImplicitParam(name = "wkt", value = "点WKT", dataType = "String", example = "POINT (115.94927385452 32.3754479115071)"),
            @ApiImplicitParam(name = "pixel", value = "像素值", dataType = "Integer", example = "1")
    })
    @GetMapping(value = "/selectByPoint")
    public ResponseMsg<Object> selectByPoint(String wkt) {
    public ResponseMsg<Object> selectByPoint(String wkt, Integer pixel) {
        try {
            Map<String, Double> map = new HashMap<>(5);
            map.put("图层名", 0.0);
            // Map<String, Double> map = new HashMap<>(5);  map.put("图层名", 0.0);  return success(map)
            if (StringHelper.isEmpty(wkt)) {
                return fail("WKT字符串不能为空");
            }
            Geometry geo = Geometry.CreateFromWkt(wkt);
            if (null == geo || geo.GetGeometryType() != ogr.wkbPoint) {
                return fail("WKT字符串不正确");
            }
            if (null == pixel || !PIXELS.contains(pixel)) {
                return fail("像点值只能为:" + StringHelper.join(PIXELS, ", "));
            }
            return success(map);
            List<?> rs = rasterService.analysisPoint(geo, pixel);
            return success(rs.size(), rs);
        } catch (Exception ex) {
            return fail(ex, null);
        }
@@ -48,17 +64,22 @@
    @SysLog()
    @ApiOperation(value = "查询线分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wkt", value = "线WKT", dataType = "String", example = "")
            @ApiImplicitParam(name = "wkt", value = "线WKT", dataType = "String", example = "LINESTRING(115.94927385452 32.3754479115071,121.989371092554 32.2766788010181,121.850621222894 29.6874200067864)")
    })
    @GetMapping(value = "/selectByPolyline")
    public ResponseMsg<Object> selectByPolyline(String wkt) {
        try {
            Map<String, List<Double>> map = new HashMap<>(5);
            List<Double> list = new ArrayList<>();
            list.add(0.0);
            map.put("图层名", list);
            if (StringHelper.isEmpty(wkt)) {
                return fail("WKT字符串不能为空");
            }
            Geometry geo = Geometry.CreateFromWkt(wkt);
            if (null == geo || geo.GetGeometryType() != ogr.wkbLineString) {
                return fail("WKT字符串不正确");
            }
            return success(map);
            List<?> rs = rasterService.analysisPolyline(geo);
            return success(rs.size(), rs);
        } catch (Exception ex) {
            return fail(ex, null);
        }
@@ -67,15 +88,22 @@
    @SysLog()
    @ApiOperation(value = "查询面分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wkt", value = "面WKT", dataType = "String", example = "")
            @ApiImplicitParam(name = "wkt", value = "面WKT", dataType = "String", example = "POLYGON ((115.94927385452 32.3754479115071,121.989371092554 32.2766788010181,121.850621222894 29.6874200067864,115.9727267226 29.7835368627922,115.94927385452 32.3754479115071))")
    })
    @GetMapping(value = "/selectByPolygon")
    public ResponseMsg<Object> selectByPolygon(String wkt) {
        try {
            Map<String, Double> map = new HashMap<>(5);
            map.put("图层名", 0.0);
            if (StringHelper.isEmpty(wkt)) {
                return fail("WKT字符串不能为空");
            }
            Geometry geo = Geometry.CreateFromWkt(wkt);
            if (null == geo || geo.GetGeometryType() != ogr.wkbPolygon) {
                return fail("WKT字符串不正确");
            }
            return success(map);
            List<?> rs = rasterService.analysisPolygon(geo);
            return success(rs.size(), rs);
        } catch (Exception ex) {
            return fail(ex, null);
        }
@@ -86,8 +114,8 @@
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wkt", value = "点WKT", dataType = "String", example = "")
    })
    @RequestMapping(value = "/downloadByPoint")
    public void downloadByPoint(String wkt, HttpServletRequest req, HttpServletResponse res) {
    @GetMapping(value = "/downloadByPoint")
    public void downloadByPoint(String wkt, HttpServletResponse res) {
        try {
            // ...
@@ -103,8 +131,8 @@
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wkt", value = "线WKT", dataType = "String", example = "")
    })
    @RequestMapping(value = "/downloadByPolyline")
    public void downloadByPolyline(String wkt, HttpServletRequest req, HttpServletResponse res) {
    @GetMapping(value = "/downloadByPolyline")
    public void downloadByPolyline(String wkt, HttpServletResponse res) {
        try {
            // ...
@@ -120,8 +148,8 @@
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wkt", value = "面WKT", dataType = "String", example = "")
    })
    @RequestMapping(value = "/downloadByPolygon")
    public void downloadByPolygon(String wkt, HttpServletRequest req, HttpServletResponse res) {
    @GetMapping(value = "/downloadByPolygon")
    public void downloadByPolygon(String wkt, HttpServletResponse res) {
        try {
            // ...