From 51b42ab1f6bad2b63edf97e52fc5f6b9fb61758f Mon Sep 17 00:00:00 2001 From: qkr7828 Date: Wed, 17 Jan 2024 19:27:56 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20CoordUtil=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/palnet/comn/utils/CoordUtils.java | 107 ++++++------------ 1 file changed, 37 insertions(+), 70 deletions(-) diff --git a/pav-server/src/main/java/com/palnet/comn/utils/CoordUtils.java b/pav-server/src/main/java/com/palnet/comn/utils/CoordUtils.java index 30f2f04b..cc81f4f5 100644 --- a/pav-server/src/main/java/com/palnet/comn/utils/CoordUtils.java +++ b/pav-server/src/main/java/com/palnet/comn/utils/CoordUtils.java @@ -36,6 +36,8 @@ public class CoordUtils { private List allLocation; + private GeometryFactory geometryFactory = new GeometryFactory(); + private CoordUtils() { this.locationInit(); @@ -196,63 +198,18 @@ public class CoordUtils { } } - public static JSONObject parseGeoJson(JSONObject obj, Coordinate coordinate) throws IOException, ParseException { - - GeometryFactory geometryFactory = new GeometryFactory(); + public JSONObject parseGeoJson(JSONObject obj, Coordinate coordinate) throws IOException, ParseException { Point point = geometryFactory.createPoint(coordinate); String type = (String) obj.get("type"); List features = (List) obj.get("features"); - JSONObject result = new JSONObject(); + return this.contains(features, point); - for(int i=0; i coordinates = (List) geometry.get("coordinates"); - - for(int k = 0; k< coordinates.size(); k++) { - - List polygonPaths = new ArrayList<>(); - - for(Object coords : coordinates.get(k)) { - - for(int j = 0; j<((JSONArray)coords).size(); j++) { - - Object coord = ((JSONArray) coords).get(j); - - Object x = ((JSONArray) coord).get(0); - Object y = ((JSONArray) coord).get(1); - - Double lon = y instanceof Double ? (Double) y : Double.valueOf((Long) y); - Double lat = x instanceof Double ? (Double) x : Double.valueOf((Long) x); - - Coordinate areaCoord = new Coordinate(lon, lat); - - polygonPaths.add(areaCoord); - - } - - polygonPaths.add(polygonPaths.get(0)); - - } - - Polygon polygon = geometryFactory.createPolygon(polygonPaths.toArray(new Coordinate[] {})); - - if(polygon.contains(point)) return properties; - - } - } - return null; - } + } - public static JSONObject parseGeoJson(String path, Coordinate coordinate) throws IOException, ParseException { - - GeometryFactory geometryFactory = new GeometryFactory(); + public JSONObject parseGeoJson(String path, Coordinate coordinate) throws IOException, ParseException { List features = new ArrayList(); @@ -261,20 +218,28 @@ public class CoordUtils { try(InputStream inputStream = new ClassPathResource(path).getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8192)) { - JSONParser jsonParser = new JSONParser(); - - JSONObject jsonObject = (JSONObject) jsonParser.parse(reader); - - point = geometryFactory.createPoint(coordinate); - - features = (List) jsonObject.get("features"); - - }catch(Exception e) { - - e.getStackTrace(); - - } + JSONParser jsonParser = new JSONParser(); + + JSONObject jsonObject = (JSONObject) jsonParser.parse(reader); + + point = geometryFactory.createPoint(coordinate); + + features = (List) jsonObject.get("features"); + + }catch(Exception e) { + + e.getStackTrace(); + + } + + return this.contains(features, point); + + } + + + public JSONObject contains(List features, Point point) { + for(int i=0; i