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