|
|
@ -36,6 +36,8 @@ public class CoordUtils { |
|
|
|
|
|
|
|
|
|
|
|
private List<JSONObject> allLocation; |
|
|
|
private List<JSONObject> allLocation; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private GeometryFactory geometryFactory = new GeometryFactory(); |
|
|
|
|
|
|
|
|
|
|
|
private CoordUtils() { |
|
|
|
private CoordUtils() { |
|
|
|
|
|
|
|
|
|
|
|
this.locationInit(); |
|
|
|
this.locationInit(); |
|
|
@ -196,63 +198,18 @@ public class CoordUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static JSONObject parseGeoJson(JSONObject obj, Coordinate coordinate) throws IOException, ParseException { |
|
|
|
public JSONObject parseGeoJson(JSONObject obj, Coordinate coordinate) throws IOException, ParseException { |
|
|
|
|
|
|
|
|
|
|
|
GeometryFactory geometryFactory = new GeometryFactory(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Point point = geometryFactory.createPoint(coordinate); |
|
|
|
Point point = geometryFactory.createPoint(coordinate); |
|
|
|
String type = (String) obj.get("type"); |
|
|
|
String type = (String) obj.get("type"); |
|
|
|
|
|
|
|
|
|
|
|
List<JSONObject> features = (List<JSONObject>) obj.get("features"); |
|
|
|
List<JSONObject> features = (List<JSONObject>) obj.get("features"); |
|
|
|
|
|
|
|
|
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
return this.contains(features, point); |
|
|
|
|
|
|
|
|
|
|
|
for(int i=0; i<features.size(); i++) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
JSONObject geometry = (JSONObject) features.get(i).get("geometry"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject properties = (JSONObject) features.get(i).get("properties"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<JSONArray> coordinates = (List<JSONArray>) geometry.get("coordinates"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int k = 0; k< coordinates.size(); k++) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Coordinate> 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 { |
|
|
|
public JSONObject parseGeoJson(String path, Coordinate coordinate) throws IOException, ParseException { |
|
|
|
|
|
|
|
|
|
|
|
GeometryFactory geometryFactory = new GeometryFactory(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<JSONObject> features = new ArrayList<JSONObject>(); |
|
|
|
List<JSONObject> features = new ArrayList<JSONObject>(); |
|
|
|
|
|
|
|
|
|
|
@ -261,20 +218,28 @@ public class CoordUtils { |
|
|
|
try(InputStream inputStream = new ClassPathResource(path).getInputStream(); |
|
|
|
try(InputStream inputStream = new ClassPathResource(path).getInputStream(); |
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8192)) { |
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8192)) { |
|
|
|
|
|
|
|
|
|
|
|
JSONParser jsonParser = new JSONParser(); |
|
|
|
JSONParser jsonParser = new JSONParser(); |
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = (JSONObject) jsonParser.parse(reader); |
|
|
|
JSONObject jsonObject = (JSONObject) jsonParser.parse(reader); |
|
|
|
|
|
|
|
|
|
|
|
point = geometryFactory.createPoint(coordinate); |
|
|
|
point = geometryFactory.createPoint(coordinate); |
|
|
|
|
|
|
|
|
|
|
|
features = (List<JSONObject>) jsonObject.get("features"); |
|
|
|
features = (List<JSONObject>) jsonObject.get("features"); |
|
|
|
|
|
|
|
|
|
|
|
}catch(Exception e) { |
|
|
|
}catch(Exception e) { |
|
|
|
|
|
|
|
|
|
|
|
e.getStackTrace(); |
|
|
|
e.getStackTrace(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this.contains(features, point); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JSONObject contains(List<JSONObject> features, Point point) { |
|
|
|
|
|
|
|
|
|
|
|
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"); |
|
|
@ -309,12 +274,14 @@ public class CoordUtils { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Polygon polygon = geometryFactory.createPolygon(polygonPaths.toArray(new Coordinate[] {})); |
|
|
|
Polygon polygon = geometryFactory.createPolygon(polygonPaths.toArray(new Coordinate[] {})); |
|
|
|
|
|
|
|
|
|
|
|
if(polygon.contains(point)) return properties; |
|
|
|
if(polygon.contains(point)) return properties; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|