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 b52db75d..154d8fcf 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 @@ -23,6 +23,9 @@ import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Point; import org.locationtech.jts.geom.Polygon; import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.util.FileCopyUtils; import lombok.extern.slf4j.Slf4j; @@ -33,7 +36,7 @@ public class CoordUtils { private static final CoordUtils INSTANCE = new CoordUtils(); - private String baseFileName = "/all_location.geojson"; + private String baseFileName = "all_location.geojson"; private List allLocation; @@ -97,20 +100,18 @@ public class CoordUtils { JSONObject jsonObject = new JSONObject(); - String path = basePath + coords + baseFileName; + String path = basePath + coords + "/" + baseFileName; - try(InputStream inputStream = new ClassPathResource(path).getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8192)) { - + try (InputStream inputStream = new ClassPathResource(path).getInputStream()) { + byte[] binaryData = FileCopyUtils.copyToByteArray(inputStream); + String content = new String(binaryData, "UTF-8"); + JSONParser jsonParser = new JSONParser(); - - jsonObject = (JSONObject) jsonParser.parse(reader); - - }catch(Exception e) { - - e.getStackTrace(); - - } + jsonObject = (JSONObject) jsonParser.parse(content); + + } catch (Exception e) { + e.printStackTrace(); + } return jsonObject; } @@ -201,11 +202,11 @@ public class CoordUtils { public JSONObject getCoordinateGis(Coordinate coordinate, JSONObject polygon) throws IOException, ParseException { JSONObject obj = new JSONObject(); - + obj = parseGeoJson(polygon, coordinate); if(obj == null) return null; - + return obj; } @@ -257,22 +258,21 @@ public class CoordUtils { Point point = null; - try(InputStream inputStream = new ClassPathResource(path).getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8192)) { - + try (InputStream inputStream = new ClassPathResource(path).getInputStream()) { + + byte[] binaryData = FileCopyUtils.copyToByteArray(inputStream); + String content = new String(binaryData, "UTF-8"); + JSONParser jsonParser = new JSONParser(); - - JSONObject jsonObject = (JSONObject) jsonParser.parse(reader); - + JSONObject jsonObject = (JSONObject) jsonParser.parse(content); + point = geometryFactory.createPoint(coordinate); features = (List) jsonObject.get("features"); - }catch(Exception e) { - - e.getStackTrace(); - - } + } catch (Exception e) { + e.printStackTrace(); + } return this.contains(features, point);