|
|
@ -7,6 +7,10 @@ import java.io.IOException; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
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.JSONArray; |
|
|
|
import org.json.simple.JSONObject; |
|
|
|
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"; |
|
|
|
String baseFileName = "all_location.geojson"; |
|
|
|
|
|
|
|
|
|
|
|
JSONObject obj = new JSONObject(); |
|
|
|
JSONObject obj = new JSONObject(); |
|
|
|
|
|
|
|
|
|
|
|
log.info("path >>>>>> {}", basePath); |
|
|
|
String path = basePath + depth + "/"; |
|
|
|
|
|
|
|
|
|
|
|
String path = basePath; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(true) { |
|
|
|
while(true) { |
|
|
|
|
|
|
|
|
|
|
@ -175,7 +177,9 @@ public class FlightUtils { |
|
|
|
|
|
|
|
|
|
|
|
if(!file.exists()) return obj; |
|
|
|
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")+"/"; |
|
|
|
path += obj.get("CD")+"/"; |
|
|
|
|
|
|
|
|
|
|
@ -183,14 +187,12 @@ public class FlightUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//depth를 통해 좌표의 특정 구간(2 : 광역시, 5 : 시군구, 8 : 읍면동 / 리)에 해당하는 정보를 가져옴
|
|
|
|
//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"; |
|
|
|
String baseFileName = "all_location.geojson"; |
|
|
|
|
|
|
|
|
|
|
|
JSONObject obj = new JSONObject(); |
|
|
|
JSONObject obj = new JSONObject(); |
|
|
|
|
|
|
|
|
|
|
|
log.info("path >>>>>> {}", basePath); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String path = basePath; |
|
|
|
String path = basePath; |
|
|
|
|
|
|
|
|
|
|
|
while(true) { |
|
|
|
while(true) { |
|
|
@ -199,7 +201,7 @@ public class FlightUtils { |
|
|
|
|
|
|
|
|
|
|
|
if(!file.exists()) return obj; |
|
|
|
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; |
|
|
|
if(obj.get("CD").toString().length() >= depth) return obj; |
|
|
|
|
|
|
|
|
|
|
@ -208,8 +210,75 @@ public class FlightUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// isNear == true -> 좌표가 육지가 아닌 바다
|
|
|
|
public static JSONObject parseGeoJson(String path, Coordinate coordinate) throws IOException, ParseException { |
|
|
|
// 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<Callable<JSONObject>> callables = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < coords.length-1; i++) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int path = i; |
|
|
|
|
|
|
|
callables.add(() -> getCoordinateGis(coord, coords[path], isNear)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Future<JSONObject>> results = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Callable<JSONObject> callable : callables) { |
|
|
|
|
|
|
|
results.add(executorService.submit(callable)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
executorService.shutdown(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(isNear) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
|
|
|
|
Double distance = 1000000.0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Future<JSONObject> 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<JSONObject> 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(); |
|
|
|
GeometryFactory geometryFactory = new GeometryFactory(); |
|
|
|
|
|
|
|
|
|
|
@ -229,6 +298,10 @@ public class FlightUtils { |
|
|
|
fileInputStream.close(); |
|
|
|
fileInputStream.close(); |
|
|
|
reader.close(); |
|
|
|
reader.close(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Double distance = 10000000.0; |
|
|
|
|
|
|
|
|
|
|
|
for(int i=0; i<features.size(); i++) { |
|
|
|
for(int i=0; i<features.size(); i++) { |
|
|
|
|
|
|
|
|
|
|
|
JSONObject geometry = (JSONObject) features.get(i).get("geometry"); |
|
|
|
JSONObject geometry = (JSONObject) features.get(i).get("geometry"); |
|
|
@ -265,11 +338,28 @@ public class FlightUtils { |
|
|
|
|
|
|
|
|
|
|
|
Polygon polygon = geometryFactory.createPolygon(polygonPaths.toArray(new Coordinate[] {})); |
|
|
|
Polygon polygon = geometryFactory.createPolygon(polygonPaths.toArray(new Coordinate[] {})); |
|
|
|
|
|
|
|
|
|
|
|
if(polygon.contains(point)) return properties; |
|
|
|
if(isNear) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(distance > 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; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|