From c2f26f96589d464cc62609d5e1ac02a6d9b70dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?scnoh=28=EB=85=B8=EC=8A=B9=EC=B2=A0=29?= Date: Tue, 23 Aug 2022 13:56:23 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B9=84=ED=96=89=EA=B5=AC=EC=97=AD=20?= =?UTF-8?q?=EC=A2=8C=ED=91=9C=EA=B3=84=20=EB=B3=80=ED=99=98=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bas/flight/service/BasFlightService.java | 11 ++--- .../java/com/palnet/comn/utils/AreaUtils.java | 42 ++++++++++++++++--- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/palnet/biz/api/bas/flight/service/BasFlightService.java b/src/main/java/com/palnet/biz/api/bas/flight/service/BasFlightService.java index 51a57b3..a54b351 100644 --- a/src/main/java/com/palnet/biz/api/bas/flight/service/BasFlightService.java +++ b/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 convertCoordinates = areaUtils.convertCoordinates(area.getCoordList()); - - List bufferList = areaUtils.buffer(convertCoordinates, area.getBufferZone()); // buffer 영역 생성 -// boolean overlaps = areaUtils.overlaps(bufferList); // buffer 영역 장애물 포함 여부 체크 - List bufferCoordList = areaUtils.convertModel(bufferList); + List convertCoordinates = areaUtils.convertCoordinates(area.getCoordList()); // 객체 타입 변환 + List transCoordList = areaUtils.transform(convertCoordinates, "EPSG:4326", "EPSG:5181"); + + List bufferList = areaUtils.buffer(transCoordList, area.getBufferZone()); // buffer 영역 생성 + List transBufferList = areaUtils.transform(bufferList, "EPSG:5181", "EPSG:4326"); // buffer 영역 좌표계 변환 + List bufferCoordList = areaUtils.convertModel(transBufferList); area.setBufferCoordList(bufferCoordList); } diff --git a/src/main/java/com/palnet/comn/utils/AreaUtils.java b/src/main/java/com/palnet/comn/utils/AreaUtils.java index ee3b63d..3777b23 100644 --- a/src/main/java/com/palnet/comn/utils/AreaUtils.java +++ b/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 transform(List 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 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 buffer(List coordList, Integer bufferZone) { List 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 createCircle(Coordinate CircleCoord, Integer BufferZone) { - List 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 coordList = new ArrayList<>(); coordList.addAll(Arrays.asList(coords)); return coordList;