| | |
| | | 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.StringHelper; |
| | | import com.moon.server.helper.WebHelper; |
| | | import com.moon.server.service.data.RasterAnalysisService; |
| | | import io.swagger.annotations.Api; |
| | |
| | | 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.*; |
| | | |
| | | /** |
| | | * 栅格分析 |
| | |
| | | @Resource |
| | | RasterAnalysisService rasterService; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "根据geometry获取对应范围的灰度值") |
| | | @PostMapping |
| | | public ResponseMsg<Object> rasterAnalysis(@RequestBody List<ImageEntity> images) { |
| | | // 输入的几何Geometry: POINT (75.772 2.498) |
| | | String geometryString = images.get(0).getGeometryString(); |
| | | Geometry geometry = Geometry.CreateFromWkt(geometryString); |
| | | |
| | | 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> 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(wkt, 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 = "") |
| | | @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(wkt); |
| | | |
| | | return success(rs.size(), rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | |
| | | @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(wkt); |
| | | |
| | | return success(rs.size(), rs); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |