From fee67ca8a0760315047a52fc4101a8f4f80b7a7f Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 11 十一月 2024 15:02:54 +0800 Subject: [PATCH] 1 --- src/main/java/com/moon/server/controller/data/RasterAnalysisController.java | 116 ++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 69 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/moon/server/controller/data/RasterAnalysisController.java b/src/main/java/com/moon/server/controller/data/RasterAnalysisController.java index 1d213f0..7760150 100644 --- a/src/main/java/com/moon/server/controller/data/RasterAnalysisController.java +++ b/src/main/java/com/moon/server/controller/data/RasterAnalysisController.java @@ -3,9 +3,11 @@ 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; @@ -15,33 +17,34 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.*; -/** - * 鏍呮牸鍒嗘瀽 - * @author WWW - * @date 2023-08-23 - */ @Api(tags = "鏁版嵁绠$悊\\鏍呮牸鍒嗘瀽") @RestController +@SuppressWarnings("ALL") @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)); + @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 = "鐐筗KT", dataType = "String", example = "POINT (115.94927385452 32.3754479115071)"), + @ApiImplicitParam(name = "wkt", value = "鐐筗KT", 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 { - // Map<String, Double> map = new HashMap<>(5); map.put("鍥惧眰鍚�", 0.0); return success(map) if (StringHelper.isEmpty(wkt)) { return fail("WKT瀛楃涓蹭笉鑳戒负绌�"); } @@ -49,11 +52,11 @@ if (null == geo || geo.GetGeometryType() != ogr.wkbPoint) { return fail("WKT瀛楃涓蹭笉姝g‘"); } - if (null == pixel || !pixels.contains(pixel)) { - return fail("鍍忕偣鍊煎彧鑳戒负锛�" + StringHelper.join(pixels, ", ")); + if (null == pixel || !PIXELS.contains(pixel)) { + return fail("鍍忕礌鍊煎彧鑳戒负锛�" + StringHelper.join(PIXELS, ", ")); } - List<?> rs = rasterService.analysisPoint(wkt, pixel); + List<?> rs = rasterService.analysis(geo, pixel); return success(rs.size(), rs); } catch (Exception ex) { @@ -64,10 +67,11 @@ @SysLog() @ApiOperation(value = "鏌ヨ绾垮垎鏋�") @ApiImplicitParams({ - @ApiImplicitParam(name = "wkt", value = "绾縒KT", dataType = "String", example = "LINESTRING(115.94927385452 32.3754479115071,121.989371092554 32.2766788010181,121.850621222894 29.6874200067864)") + @ApiImplicitParam(name = "wkt", value = "绾縒KT", 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) { + public ResponseMsg<Object> selectByPolyline(String wkt, Integer nodes) { try { if (StringHelper.isEmpty(wkt)) { return fail("WKT瀛楃涓蹭笉鑳戒负绌�"); @@ -76,8 +80,11 @@ if (null == geo || geo.GetGeometryType() != ogr.wkbLineString) { return fail("WKT瀛楃涓蹭笉姝g‘"); } + if (null == nodes || !NODES.contains(nodes)) { + return fail("鑺傜偣鏁板彧鑳戒负锛�" + StringHelper.join(NODES, ", ")); + } - List<?> rs = rasterService.analysisPolyline(wkt); + List<?> rs = rasterService.analysis(geo, nodes); return success(rs.size(), rs); } catch (Exception ex) { @@ -88,7 +95,8 @@ @SysLog() @ApiOperation(value = "鏌ヨ闈㈠垎鏋�") @ApiImplicitParams({ - @ApiImplicitParam(name = "wkt", value = "闈KT", dataType = "String", example = "POLYGON ((115.94927385452 32.3754479115071,121.989371092554 32.2766788010181,121.850621222894 29.6874200067864,115.9727267226 29.7835368627922,115.94927385452 32.3754479115071))") + //@ApiImplicitParam(name = "wkt", value = "闈KT", dataType = "String", example = "POLYGON ((165.680851 31.333443,166.383982 31.283475,166.016355 30.908709,165.680851 31.333443))") + @ApiImplicitParam(name = "wkt", value = "闈KT", 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) { @@ -101,7 +109,7 @@ return fail("WKT瀛楃涓蹭笉姝g‘"); } - List<?> rs = rasterService.analysisPolygon(wkt); + List<?> rs = rasterService.analysis(geo, 0); return success(rs.size(), rs); } catch (Exception ex) { @@ -110,52 +118,66 @@ } @SysLog() - @ApiOperation(value = "涓嬭浇鐐瑰垎鏋�") + @ApiOperation(value = "浣跨敤WKT鏌ヨ鍒嗘瀽锛岀粨鏋滀互娑堟伅鎺ㄩ��") @ApiImplicitParams({ - @ApiImplicitParam(name = "wkt", value = "鐐筗KT", dataType = "String", example = "") + @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 = "/downloadByPoint") - public void downloadByPoint(String wkt, HttpServletResponse res) { + @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瀛楃涓蹭笉姝g‘"); + 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, "鍍忕礌鍊�(鐐�)鎴栬妭鐐规暟(绾�)鍊间笉姝g‘"); + return; + } - String filePath = "鐢熸垚鏂囦欢鐨勮矾寰�"; - WebHelper.download(filePath, "鏂囦欢鍚�", res); + String token = WebHelper.getToken(req); + rasterService.analysisForPost(geo, size, token); } catch (Exception ex) { log.error(ex.getMessage(), ex); } } @SysLog() - @ApiOperation(value = "涓嬭浇绾垮垎鏋�") + @ApiOperation(value = "涓嬭浇鍧″害鍒嗘瀽Excel") @ApiImplicitParams({ - @ApiImplicitParam(name = "wkt", value = "绾縒KT", dataType = "String", example = "") + @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 = "/downloadByPolyline") - public void downloadByPolyline(String wkt, HttpServletResponse res) { + @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瀛楃涓蹭笉姝g‘"); + return; + } + int wktType = geo.GetGeometryType(); + if (wktType != ogr.wkbPolygon) { + WebHelper.writeStr2Page(res, "WKT瀛楃涓插彧鏀寔闈㈢被鍨�"); + return; + } - String filePath = "鐢熸垚鏂囦欢鐨勮矾寰�"; - WebHelper.download(filePath, "鏂囦欢鍚�", res); + slopeAnalysisService.downloadSlopXls(geo, res); } catch (Exception ex) { - log.error(ex.getMessage(), ex); - } - } - - @SysLog() - @ApiOperation(value = "涓嬭浇闈㈠垎鏋�") - @ApiImplicitParams({ - @ApiImplicitParam(name = "wkt", value = "闈KT", dataType = "String", example = "") - }) - @GetMapping(value = "/downloadByPolygon") - public void downloadByPolygon(String wkt, HttpServletResponse res) { - try { - // ... - - String filePath = "鐢熸垚鏂囦欢鐨勮矾寰�"; - WebHelper.download(filePath, "鏂囦欢鍚�", res); - } catch (Exception ex) { + WebHelper.writeStr2Page(res, ex.getMessage()); log.error(ex.getMessage(), ex); } } -- Gitblit v1.9.3