月球大数据地理空间分析展示平台-【后端】-月球后台服务
1
13693261870
2024-11-11 fee67ca8a0760315047a52fc4101a8f4f80b7a7f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package com.moon.server.controller.data;
 
import com.moon.server.annotation.SysLog;
import com.moon.server.controller.all.BaseController;
import com.moon.server.entity.all.ResponseMsg;
import com.moon.server.entity.all.StaticData;
import com.moon.server.helper.StringHelper;
import com.moon.server.helper.WebHelper;
import com.moon.server.service.data.RasterAnalysisService;
import com.moon.server.service.data.SlopeAnalysisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.gdal.ogr.Geometry;
import org.gdal.ogr.ogr;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
 
@Api(tags = "数据管理\\栅格分析")
@RestController
@SuppressWarnings("ALL")
@RequestMapping("/rasterAnalysis")
public class RasterAnalysisController extends BaseController {
    @Resource
    RasterAnalysisService rasterService;
 
    @Resource
    SlopeAnalysisService slopeAnalysisService;
 
    private final static List<Integer> PIXELS = new ArrayList<>(Arrays.asList(1, 2, 4, 8, 16, 32, 64, 128, 256));
 
    private final static List<Integer> NODES = new ArrayList<>(Arrays.asList(16, 32, 64, 96, 128, 192, 256, 384, 512, 768, 1024));
 
    @SysLog()
    @ApiOperation(value = "查询点分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wkt", value = "点WKT", dataType = "String", example = "POINT (157.750107 29.036669)"),
            @ApiImplicitParam(name = "pixel", value = "像素值", dataType = "Integer", example = "1")
    })
    @GetMapping(value = "/selectByPoint")
    public ResponseMsg<Object> selectByPoint(String wkt, Integer pixel) {
        try {
            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, ", "));
            }
 
            List<?> rs = rasterService.analysis(geo, pixel);
 
            return success(rs.size(), rs);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "查询线分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wkt", value = "线WKT", dataType = "String", example = "LINESTRING(165.680851 31.333443,166.383982 31.283475,166.016355 30.908709)"),
            @ApiImplicitParam(name = "nodes", value = "节点数", dataType = "Integer", example = "16")
    })
    @GetMapping(value = "/selectByPolyline")
    public ResponseMsg<Object> selectByPolyline(String wkt, Integer nodes) {
        try {
            if (StringHelper.isEmpty(wkt)) {
                return fail("WKT字符串不能为空");
            }
            Geometry geo = Geometry.CreateFromWkt(wkt);
            if (null == geo || geo.GetGeometryType() != ogr.wkbLineString) {
                return fail("WKT字符串不正确");
            }
            if (null == nodes || !NODES.contains(nodes)) {
                return fail("节点数只能为:" + StringHelper.join(NODES, ", "));
            }
 
            List<?> rs = rasterService.analysis(geo, nodes);
 
            return success(rs.size(), rs);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "查询面分析")
    @ApiImplicitParams({
            //@ApiImplicitParam(name = "wkt", value = "面WKT", dataType = "String", example = "POLYGON ((165.680851 31.333443,166.383982 31.283475,166.016355 30.908709,165.680851 31.333443))")
            @ApiImplicitParam(name = "wkt", value = "面WKT", dataType = "String", example = "POLYGON ((56.61 33.94,115.04 33.56,114.09 -7.17,52.22 -6.22,56.61 33.94))")
    })
    @GetMapping(value = "/selectByPolygon")
    public ResponseMsg<Object> selectByPolygon(String wkt) {
        try {
            if (StringHelper.isEmpty(wkt)) {
                return fail("WKT字符串不能为空");
            }
            Geometry geo = Geometry.CreateFromWkt(wkt);
            if (null == geo || geo.GetGeometryType() != ogr.wkbPolygon) {
                return fail("WKT字符串不正确");
            }
 
            List<?> rs = rasterService.analysis(geo, 0);
 
            return success(rs.size(), rs);
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "使用WKT查询分析,结果以消息推送")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wkt", value = "WKT字符串", dataType = "String", example = "POLYGON ((56.61 33.94,115.04 33.56,114.09 -7.17,52.22 -6.22,56.61 33.94))"),
            @ApiImplicitParam(name = "size", value = "像素值(点)或节点数(线)", dataType = "Integer", example = "16")
    })
    @GetMapping(value = "/selectByWktForPost")
    public void selectByWktForPost(String wkt, Integer size, HttpServletRequest req, HttpServletResponse res) {
        try {
            if (StringHelper.isEmpty(wkt)) {
                WebHelper.writeStr2Page(res, "WKT字符串不能为空");
                return;
            }
            Geometry geo = Geometry.CreateFromWkt(wkt);
            if (null == geo) {
                WebHelper.writeStr2Page(res, "WKT字符串不正确");
                return;
            }
            int wktType = geo.GetGeometryType();
            if (wktType != ogr.wkbPoint && wktType != ogr.wkbLineString && wktType != ogr.wkbPolygon) {
                WebHelper.writeStr2Page(res, "WKT字符串只支持点、线串和面类型");
                return;
            }
            if (null == size || size < 0 || size > StaticData.I1024) {
                WebHelper.writeStr2Page(res, "像素值(点)或节点数(线)值不正确");
                return;
            }
 
            String token = WebHelper.getToken(req);
            rasterService.analysisForPost(geo, size, token);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
 
    @SysLog()
    @ApiOperation(value = "下载坡度分析Excel")
    @ApiImplicitParams({
            @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) {
        try {
            if (StringHelper.isEmpty(wkt)) {
                WebHelper.writeStr2Page(res, "WKT字符串不能为空");
                return;
            }
            Geometry geo = Geometry.CreateFromWkt(wkt);
            if (null == geo) {
                WebHelper.writeStr2Page(res, "WKT字符串不正确");
                return;
            }
            int wktType = geo.GetGeometryType();
            if (wktType != ogr.wkbPolygon) {
                WebHelper.writeStr2Page(res, "WKT字符串只支持面类型");
                return;
            }
 
            slopeAnalysisService.downloadSlopXls(geo, res);
        } catch (Exception ex) {
            WebHelper.writeStr2Page(res, ex.getMessage());
            log.error(ex.getMessage(), ex);
        }
    }
}