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 8636c7dd..24fd31ac 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; + } } }