From 8300bfcfd58e84d27163ba94b8e026cfcf4f90a6 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期六, 16 九月 2023 08:37:48 +0800 Subject: [PATCH] 添加坐标系初始化 --- src/main/java/com/moon/server/controller/data/RasterAnalysisController.java | 143 ++++++++++++++++------------------------------- 1 files changed, 48 insertions(+), 95 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 58536b7..c866f6d 100644 --- a/src/main/java/com/moon/server/controller/data/RasterAnalysisController.java +++ b/src/main/java/com/moon/server/controller/data/RasterAnalysisController.java @@ -3,8 +3,7 @@ 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.data.ImageEntity; -import com.moon.server.helper.WebHelper; +import com.moon.server.helper.StringHelper; import com.moon.server.service.data.RasterAnalysisService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -15,12 +14,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * 鏍呮牸鍒嗘瀽 @@ -34,40 +28,33 @@ @Resource RasterAnalysisService rasterService; - @SysLog() - @ApiOperation(value = "鏍规嵁geometry鑾峰彇瀵瑰簲鑼冨洿鐨勭伆搴﹀��") - @PostMapping - public ResponseMsg<Object> rasterAnalysis(@RequestBody List<ImageEntity> images) { - // 杈撳叆鐨勫嚑浣旼eometry: POINT (75.772 2.498) - String geometryString = images.get(0).getGeometryString(); - Geometry geometry = Geometry.CreateFromWkt(geometryString); + private final static List<Integer> PIXELS = new ArrayList<>(Arrays.asList(1, 2, 4, 8, 16, 32, 64, 128, 256)); - for (ImageEntity i : images) { - String path = i.getPath(); - if (geometry.GetGeometryType() == ogr.wkbPoint) { - i.setResult(rasterService.processPoint(path, geometryString, i.getPointSize())); - } else if (geometry.GetGeometryType() == ogr.wkbLineString) { - i.setResult(rasterService.processLine(path, geometryString)); - } else if (geometry.GetGeometryType() == ogr.wkbPolygon) { - i.setResult(rasterService.processPolygon(path, geometryString)); - } - } - - return success(images); - } + 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 = "") + @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) { + public ResponseMsg<Object> selectByPoint(String wkt, Integer pixel) { 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.wkbPoint) { + return fail("WKT瀛楃涓蹭笉姝g‘"); + } + if (null == pixel || !PIXELS.contains(pixel)) { + return fail("鍍忕礌鍊煎彧鑳戒负锛�" + StringHelper.join(PIXELS, ", ")); + } - return success(map); + List<?> rs = rasterService.analysis(geo, pixel); + + return success(rs.size(), rs); } catch (Exception ex) { return fail(ex, null); } @@ -76,17 +63,26 @@ @SysLog() @ApiOperation(value = "鏌ヨ绾垮垎鏋�") @ApiImplicitParams({ - @ApiImplicitParam(name = "wkt", value = "绾縒KT", dataType = "String", example = "") + @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 { - 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瀛楃涓蹭笉姝g‘"); + } + if (null == nodes || !NODES.contains(nodes)) { + return fail("鑺傜偣鏁板彧鑳戒负锛�" + StringHelper.join(NODES, ", ")); + } - return success(map); + List<?> rs = rasterService.analysis(geo, nodes); + + return success(rs.size(), rs); } catch (Exception ex) { return fail(ex, null); } @@ -95,68 +91,25 @@ @SysLog() @ApiOperation(value = "鏌ヨ闈㈠垎鏋�") @ApiImplicitParams({ - @ApiImplicitParam(name = "wkt", value = "闈KT", dataType = "String", example = "") + //@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) { 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瀛楃涓蹭笉姝g‘"); + } - return success(map); + List<?> rs = rasterService.analysis(geo, 0); + + return success(rs.size(), rs); } catch (Exception ex) { return fail(ex, null); - } - } - - @SysLog() - @ApiOperation(value = "涓嬭浇鐐瑰垎鏋�") - @ApiImplicitParams({ - @ApiImplicitParam(name = "wkt", value = "鐐筗KT", dataType = "String", example = "") - }) - @GetMapping(value = "/downloadByPoint") - public void downloadByPoint(String wkt, HttpServletResponse res) { - try { - // ... - - String filePath = "鐢熸垚鏂囦欢鐨勮矾寰�"; - WebHelper.download(filePath, "鏂囦欢鍚�", res); - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - } - } - - @SysLog() - @ApiOperation(value = "涓嬭浇绾垮垎鏋�") - @ApiImplicitParams({ - @ApiImplicitParam(name = "wkt", value = "绾縒KT", dataType = "String", example = "") - }) - @GetMapping(value = "/downloadByPolyline") - public void downloadByPolyline(String wkt, HttpServletResponse res) { - try { - // ... - - String filePath = "鐢熸垚鏂囦欢鐨勮矾寰�"; - WebHelper.download(filePath, "鏂囦欢鍚�", 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) { - log.error(ex.getMessage(), ex); } } } -- Gitblit v1.9.3