package org.sxkj.odm.feign;
|
|
import com.alibaba.fastjson.JSON;
|
import lombok.AllArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.locationtech.jts.geom.Coordinate;
|
import org.locationtech.jts.geom.Point;
|
import org.springblade.core.tenant.annotation.NonDS;
|
import org.springblade.core.tool.utils.StringUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
import org.sxkj.odm.entity.MyPoint;
|
import org.sxkj.odm.service.IOdmTaskInfoService;
|
import org.sxkj.odm.utils.ParseTifUtils;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* @Description 绘制像素框
|
* @Author AIX
|
* @Date 2025/12/31 11:32
|
* @Version 1.0
|
*/
|
@NonDS
|
@RestController
|
@AllArgsConstructor
|
@Slf4j
|
public class DrawPixelBoxClient implements IDrawPixelBoxClient {
|
|
@Autowired
|
private IOdmTaskInfoService odmTaskInfoService;
|
|
@Override
|
@GetMapping("/client/draw-image-pixel-box")
|
public Boolean drawImagePixelBox(@RequestParam("type") int type,
|
@RequestParam("tifFilePath") String tifFilePath,
|
@RequestParam("filePath") String filePath,
|
@RequestParam("outPath") String outPath,
|
@RequestParam("points") String points,
|
@RequestParam("geom") String geom) {
|
|
log.info("开始绘制像素框: type={}, tifFilePath={}, filePath={}, outPath={}, points={}, geom={}", type, tifFilePath, filePath, outPath, points, geom);
|
if (StringUtil.isBlank(filePath) || StringUtil.isBlank(outPath)) {
|
log.error("非法参数,文件路径不能为空");
|
return false;
|
}
|
switch (type) {
|
case 0:
|
log.info("tif绘制像素框");
|
if (null == geom || geom.isEmpty() || StringUtil.isBlank(tifFilePath) || !tifFilePath.contains("tif")) {
|
log.error("地理点集合为空或者tif文件路径不正确");
|
return false;
|
}
|
List<Coordinate> coordinates = polygonStringToCoordinates(geom);
|
// 将所有点转换成地理坐标
|
List<Point> pointList = ParseTifUtils.getTifPosByMoreLngLat(tifFilePath, new ArrayList<>(coordinates));
|
log.debug("tif 地理坐标数据:{}", pointList);
|
// 地理坐标转换成像素坐标
|
List<MyPoint> pixelByPointList = odmTaskInfoService.getPixelByPointList(tifFilePath, pointList);
|
return ParseTifUtils.drawPolygonByPoints(filePath, outPath, pixelByPointList, "jpg");
|
case 1:
|
log.info("图片绘制像素框");
|
if (null == points || points.isEmpty()) {
|
log.error("像素点集合为空");
|
return false;
|
}
|
List<MyPoint> point1 = JSON.parseArray(points, MyPoint.class);
|
return ParseTifUtils.drawPolygonByPoints(filePath, outPath, point1, "jpg");
|
default:
|
break;
|
}
|
|
return false;
|
}
|
|
/**
|
* polygon 数据转点集合数据
|
*
|
* @param polygonString
|
* @return
|
*/
|
public List<Coordinate> polygonStringToCoordinates(String polygonString) {
|
List<Coordinate> points = new ArrayList<>();
|
String[] coordinates = polygonString.replace("POLYGON((", "").replace("))", "").split(",");
|
// 遍历转换
|
for (String coordinate : coordinates) {
|
String[] point = coordinate.trim().split(" ");
|
double x = Double.parseDouble(point[0]);
|
double y = Double.parseDouble(point[1]);
|
points.add(new Coordinate(x, y));
|
}
|
return points;
|
}
|
}
|