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.helper.StringHelper;
|
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.gdal.ogr.Geometry;
|
import org.gdal.ogr.ogr;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
|
/**
|
* 栅格分析
|
* @author WWW
|
* @date 2023-08-23
|
*/
|
@Api(tags = "数据管理\\栅格分析")
|
@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));
|
|
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);
|
}
|
}
|
}
|