Browse Source

비행구역 좌표계 변환 처리

feature/auth
노승철 2 years ago
parent
commit
c2f26f9658
  1. 11
      src/main/java/com/palnet/biz/api/bas/flight/service/BasFlightService.java
  2. 42
      src/main/java/com/palnet/comn/utils/AreaUtils.java

11
src/main/java/com/palnet/biz/api/bas/flight/service/BasFlightService.java

@ -309,11 +309,12 @@ public class BasFlightService {
for(BasFlightPlanAreaModel area : rq) {
if("LINE".equals(area.getAreaType())) {
List<Coordinate> convertCoordinates = areaUtils.convertCoordinates(area.getCoordList());
List<Coordinate> bufferList = areaUtils.buffer(convertCoordinates, area.getBufferZone()); // buffer 영역 생성
// boolean overlaps = areaUtils.overlaps(bufferList); // buffer 영역 장애물 포함 여부 체크
List<BasFlightPlanAreaCoordModel> bufferCoordList = areaUtils.convertModel(bufferList);
List<Coordinate> convertCoordinates = areaUtils.convertCoordinates(area.getCoordList()); // 객체 타입 변환
List<Coordinate> transCoordList = areaUtils.transform(convertCoordinates, "EPSG:4326", "EPSG:5181");
List<Coordinate> bufferList = areaUtils.buffer(transCoordList, area.getBufferZone()); // buffer 영역 생성
List<Coordinate> transBufferList = areaUtils.transform(bufferList, "EPSG:5181", "EPSG:4326"); // buffer 영역 좌표계 변환
List<BasFlightPlanAreaCoordModel> bufferCoordList = areaUtils.convertModel(transBufferList);
area.setBufferCoordList(bufferCoordList);
}

42
src/main/java/com/palnet/comn/utils/AreaUtils.java

@ -10,6 +10,10 @@ import org.locationtech.jts.geom.impl.CoordinateArraySequence;
import org.locationtech.jts.operation.buffer.BufferOp;
import org.locationtech.jts.operation.buffer.BufferParameters;
import org.locationtech.jts.util.GeometricShapeFactory;
import org.locationtech.proj4j.BasicCoordinateTransform;
import org.locationtech.proj4j.CRSFactory;
import org.locationtech.proj4j.CoordinateReferenceSystem;
import org.locationtech.proj4j.ProjCoordinate;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
@ -35,6 +39,34 @@ public class AreaUtils {
this.init();
}
/**
* TODO 좌표계 변환
*
* @param coordList
* @return
*/
public List<Coordinate> transform(List<Coordinate> coordList, String from, String to) {
CRSFactory factory = new CRSFactory();
CoordinateReferenceSystem srcCRS = factory.createFromName(from);
CoordinateReferenceSystem tgtCRS = factory.createFromName(to);
BasicCoordinateTransform transform = new BasicCoordinateTransform(srcCRS, tgtCRS);
List<Coordinate> result = new ArrayList<>();
for(Coordinate coord : coordList) {
ProjCoordinate projCoordinate = new ProjCoordinate(coord.getX(), coord.getY());
ProjCoordinate projTrasform = transform.transform(projCoordinate, new ProjCoordinate());
Coordinate target = new Coordinate(projTrasform.x, projTrasform.y);
result.add(target);
}
return result;
}
/**
* TODO 비행 구역 생성시 장애물 영역 포함 체크
*
@ -95,7 +127,6 @@ public class AreaUtils {
*/
public List<Coordinate> buffer(List<Coordinate> coordList, Integer bufferZone) {
List<Coordinate> bufferList = new ArrayList<>();
// GeometryFactory geometryFactory = new GeometryFactory();
LineString line = geometryFactory.createLineString(coordList.toArray(new Coordinate[] {}));
Geometry geometry = geometryFactory.createGeometry(line);
@ -108,7 +139,8 @@ public class AreaUtils {
BufferParameters bufferParam = new BufferParameters(nSegments, cap, join, join);
BufferOp ops = new BufferOp(geometry, bufferParam);
Geometry bufTrans = ops.getResultGeometry((bufferZone/177763.63662580872)*2);
// Geometry bufTrans = ops.getResultGeometry((bufferZone/177763.63662580872)*2);
Geometry bufTrans = ops.getResultGeometry(bufferZone);
Coordinate[] coords = bufTrans.getCoordinates();
@ -118,10 +150,8 @@ public class AreaUtils {
}
public List<Coordinate> createCircle(Coordinate CircleCoord, Integer BufferZone) {
List<Coordinate> coordList = new ArrayList<>();
GeometricShapeFactory shapeFactory = new GeometricShapeFactory();
// GeometryFactory geometryFactory = new GeometryFactory();
double lng = CircleCoord.x;
double lat = CircleCoord.y;
@ -137,7 +167,7 @@ public class AreaUtils {
Geometry geometry = geometryFactory.createGeometry(circle);
Coordinate[] coords = geometry.getCoordinates();
List<Coordinate> coordList = new ArrayList<>();
coordList.addAll(Arrays.asList(coords));
return coordList;

Loading…
Cancel
Save