From 076b2922faff4b572200793c54565aa3ddcb842e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=9E=AC=EC=9A=B0?= <박재우@host.docker.internal> Date: Tue, 14 Nov 2023 18:59:52 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A2=8C=ED=91=9C=EB=A1=9C=20=EB=B2=95?= =?UTF-8?q?=EC=A0=95=EB=8F=99=20=EC=BD=94=EB=93=9C=20=EC=B0=BE=EB=8A=94=20?= =?UTF-8?q?=EC=9C=A0=ED=8B=B8=20->=20=EC=84=B1=EB=8A=A5=20=ED=96=A5?= =?UTF-8?q?=EC=83=81=20,=20=EC=9D=B8=EC=A0=91=ED=95=9C=20=EB=B0=94?= =?UTF-8?q?=EB=8B=A4=EC=9D=98=20=EC=A2=8C=ED=91=9C=EB=8F=84=20=EA=B0=80?= =?UTF-8?q?=EC=9E=A5=20=EA=B0=80=EA=B9=8C=EC=9A=B4=20=EC=9C=A1=EC=A7=80?= =?UTF-8?q?=EC=9D=98=20=EB=8B=B4=EB=8B=B9=EC=9E=90=20=EC=B0=BE=EC=9D=84=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/palnet/comn/utils/FlightUtils.java | 120 +++++++++++++++--- 1 file changed, 105 insertions(+), 15 deletions(-) diff --git a/pav-server/src/main/java/com/palnet/comn/utils/FlightUtils.java b/pav-server/src/main/java/com/palnet/comn/utils/FlightUtils.java index 8636c7d..24fd31a 100644 --- a/pav-server/src/main/java/com/palnet/comn/utils/FlightUtils.java +++ b/pav-server/src/main/java/com/palnet/comn/utils/FlightUtils.java @@ -7,6 +7,10 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -159,15 +163,13 @@ public class FlightUtils { } //좌표의 읍면동 , 리 등 가장 세분화된 법정동 코드를 리턴 - public static JSONObject getCoordinateGis(Coordinate coordinate) throws IOException, ParseException { + public static JSONObject getCoordinateGis(Coordinate coordinate, int depth, boolean isNear) throws IOException, ParseException { String baseFileName = "all_location.geojson"; JSONObject obj = new JSONObject(); - log.info("path >>>>>> {}", basePath); - - String path = basePath; + String path = basePath + depth + "/"; while(true) { @@ -175,7 +177,9 @@ public class FlightUtils { if(!file.exists()) return obj; - obj = parseGeoJson(path+baseFileName, coordinate); + obj = parseGeoJson(path+baseFileName, coordinate, isNear); + + if(obj == null) return null; path += obj.get("CD")+"/"; @@ -183,14 +187,12 @@ public class FlightUtils { } //depth를 통해 좌표의 특정 구간(2 : 광역시, 5 : 시군구, 8 : 읍면동 / 리)에 해당하는 정보를 가져옴 - public static JSONObject getCoordinateGis(Coordinate coordinate, int depth) throws IOException, ParseException { + public static JSONObject getDepthPlace(Coordinate coordinate, int depth) throws IOException, ParseException { String baseFileName = "all_location.geojson"; JSONObject obj = new JSONObject(); - log.info("path >>>>>> {}", basePath); - String path = basePath; while(true) { @@ -199,7 +201,7 @@ public class FlightUtils { if(!file.exists()) return obj; - obj = parseGeoJson(path+baseFileName, coordinate); + obj = parseGeoJson(path+baseFileName, coordinate, false); if(obj.get("CD").toString().length() >= depth) return obj; @@ -208,8 +210,75 @@ public class FlightUtils { } } - - public static JSONObject parseGeoJson(String path, Coordinate coordinate) throws IOException, ParseException { + // isNear == true -> 좌표가 육지가 아닌 바다 + // isNear == false -> 좌표가 육지 + public static JSONObject getPlace(Coordinate coord, boolean isNear) throws IOException, ParseException { + + int numberOfThreads = 5; + ExecutorService executorService = Executors.newFixedThreadPool(numberOfThreads); + + Integer[] coords = {11, 26, 27, 28, 29, 30, 31, 36, 41, 43, 44, 45, 46, 47, 48, 50, 51}; + + List> callables = new ArrayList<>(); + + for (int i = 0; i < coords.length-1; i++) { + + int path = i; + callables.add(() -> getCoordinateGis(coord, coords[path], isNear)); + + } + + try { + + List> results = new ArrayList<>(); + + for (Callable callable : callables) { + results.add(executorService.submit(callable)); + } + + executorService.shutdown(); + + if(isNear) { + + JSONObject result = new JSONObject(); + Double distance = 1000000.0; + + for (Future rslt : results) { + + try { + JSONObject jsonObject = rslt.get(); + + if((Double)jsonObject.get("distance") < distance) { + + distance = (Double)jsonObject.get("distance"); + result = jsonObject; + + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + return result; + + } else { + for (Future rslt : results) { + + JSONObject jsonObject = rslt.get(); + + if(jsonObject != null) return jsonObject; + + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + return null; // 모든 작업이 실패한 경우 null 반환 + + } + + public static JSONObject parseGeoJson(String path, Coordinate coordinate, boolean isNear) throws IOException, ParseException { GeometryFactory geometryFactory = new GeometryFactory(); @@ -229,6 +298,10 @@ public class FlightUtils { fileInputStream.close(); reader.close(); + JSONObject result = new JSONObject(); + + Double distance = 10000000.0; + for(int i=0; i polygon.distance(point)) { + + distance = polygon.distance(point); + + result = properties; + + } + }else { + + if(polygon.contains(point)) return properties; + + } } } - - return null; + + if(isNear) { + result.put("distance", distance); + return result; + }else { + return null; + } } }