Browse Source

비행구역 buffer 작업

feature/auth
노승철 2 years ago
parent
commit
8ed8f1a21d
  1. 33
      src/main/java/com/palnet/biz/api/bas/flight/service/BasFlightService.java
  2. 37
      src/main/java/com/palnet/comn/utils/AreaUtils.java

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

@ -60,6 +60,15 @@ public class BasFlightService {
List<FltPlanAreaCoord> coordEntityList = fltPlanAreaCoordRepository.findByPlanAreaSnoOrderByPlanAreaCoordSnoAsc(areaEntity.getPlanAreaSno()); List<FltPlanAreaCoord> coordEntityList = fltPlanAreaCoordRepository.findByPlanAreaSnoOrderByPlanAreaCoordSnoAsc(areaEntity.getPlanAreaSno());
if (coordEntityList != null && !coordEntityList.isEmpty()) { if (coordEntityList != null && !coordEntityList.isEmpty()) {
areaModel.setCoordList(BasFlightMapper.mapper.entityToModelCoordList(coordEntityList)); areaModel.setCoordList(BasFlightMapper.mapper.entityToModelCoordList(coordEntityList));
// Line인 경우 BufferList 생성
if("LINE".equals(areaEntity.getAreaType())) {
List<Coordinate> convertCoordinates = areaUtils.convertCoordinates(areaModel.getCoordList());
List<Coordinate> bufferList = areaUtils.buffer(convertCoordinates, areaModel.getBufferZone());
List<BasFlightPlanAreaCoordModel> bufferCoordList = areaUtils.convertModel(bufferList);
areaModel.setBufferCoordList(bufferCoordList);
}
} }
area.add(areaModel); area.add(areaModel);
} }
@ -303,29 +312,13 @@ public class BasFlightService {
// 비행 구역 buffer zone // 비행 구역 buffer zone
public List<BasFlightPlanAreaModel> getBuffer(List<BasFlightPlanAreaModel> rq) { public List<BasFlightPlanAreaModel> getBuffer(List<BasFlightPlanAreaModel> rq) {
List<BasFlightPlanAreaCoordModel> bufferCoordList = new ArrayList<>();
for(BasFlightPlanAreaModel area : rq) { for(BasFlightPlanAreaModel area : rq) {
if("LINE".equals(area.getAreaType())) { if("LINE".equals(area.getAreaType())) {
List<Coordinate> coordinates = new ArrayList<>(); List<Coordinate> convertCoordinates = areaUtils.convertCoordinates(area.getCoordList());
List<Coordinate> bufferList = areaUtils.buffer(convertCoordinates, area.getBufferZone());
for(BasFlightPlanAreaCoordModel coord : area.getCoordList()) { List<BasFlightPlanAreaCoordModel> bufferCoordList = areaUtils.convertModel(bufferList);
Coordinate coordinate = new Coordinate(coord.getLon(), coord.getLat());
coordinates.add(coordinate);
}
List<Coordinate> bufferList = areaUtils.buffer(coordinates, area.getBufferZone());
for(Coordinate buffer : bufferList) {
BasFlightPlanAreaCoordModel bufferCoord = new BasFlightPlanAreaCoordModel();
bufferCoord.setLat(buffer.getY());
bufferCoord.setLon(buffer.getX());
bufferCoordList.add(bufferCoord);
}
area.setBufferCoordList(bufferCoordList); area.setBufferCoordList(bufferCoordList);
log.info("RQ: {}", rq); log.info("RQ: {}", rq);
@ -334,8 +327,6 @@ public class BasFlightService {
} }
} }
return rq; return rq;
} }

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

@ -3,6 +3,7 @@ package com.palnet.comn.utils;
import com.palnet.biz.api.bas.flight.model.BasFlightPlanAreaCoordModel; import com.palnet.biz.api.bas.flight.model.BasFlightPlanAreaCoordModel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.locationtech.jts.geom.*; import org.locationtech.jts.geom.*;
import org.locationtech.jts.operation.buffer.BufferOp;
import org.locationtech.jts.operation.buffer.BufferParameters; import org.locationtech.jts.operation.buffer.BufferParameters;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -19,12 +20,20 @@ public class AreaUtils {
GeometryFactory geometryFactory = new GeometryFactory(); GeometryFactory geometryFactory = new GeometryFactory();
LineString line = new GeometryFactory().createLineString(coordList.toArray(new Coordinate[] {})); LineString line = new GeometryFactory().createLineString(coordList.toArray(new Coordinate[] {}));
Geometry geometry = geometryFactory.createGeometry(line); Geometry geometry = geometryFactory.createGeometry(line);
// buffer
int nSegments = 10;
int cap = BufferParameters.CAP_SQUARE; int cap = BufferParameters.CAP_SQUARE;
Geometry buffer = geometry.buffer(bufferZone,20,cap); int join = BufferParameters.JOIN_ROUND;
BufferParameters bufferParam = new BufferParameters(nSegments, cap, join, join);
// Geometry buffer = geometry.buffer(bufferZone,20,cap);
BufferOp ops = new BufferOp(geometry, bufferParam);
Coordinate[] coords = buffer.getCoordinates(); Geometry bufTrans = ops.getResultGeometry((bufferZone/177763.63662580872)*2);
Coordinate[] coords = bufTrans.getCoordinates();
bufferList.addAll(Arrays.asList(coords)); bufferList.addAll(Arrays.asList(coords));
@ -33,15 +42,31 @@ public class AreaUtils {
public List<Coordinate> convertCoordinates(List<BasFlightPlanAreaCoordModel> coordList) { public List<Coordinate> convertCoordinates(List<BasFlightPlanAreaCoordModel> coordList) {
List<Coordinate> convertCoordList = new ArrayList<>(); List<Coordinate> coordinates = new ArrayList<>();
for(BasFlightPlanAreaCoordModel coord : coordList) { for(BasFlightPlanAreaCoordModel coord : coordList) {
Coordinate coordinate = new Coordinate(coord.getLon(), coord.getLat()); Coordinate coordinate = new Coordinate(coord.getLon(), coord.getLat());
convertCoordList.add(coordinate); coordinates.add(coordinate);
}
return coordinates;
}
public List<BasFlightPlanAreaCoordModel> convertModel(List<Coordinate> bufferList) {
List<BasFlightPlanAreaCoordModel> bufferCoordList = new ArrayList<>();
for(Coordinate buffer : bufferList) {
BasFlightPlanAreaCoordModel bufferCoord = new BasFlightPlanAreaCoordModel();
bufferCoord.setLat(buffer.getY());
bufferCoord.setLon(buffer.getX());
bufferCoordList.add(bufferCoord);
} }
return convertCoordList; return bufferCoordList;
} }
} }

Loading…
Cancel
Save