From 7a387f59bcf53b90322eccf58f21b3d1776ca3e9 Mon Sep 17 00:00:00 2001 From: qkr7828 Date: Mon, 29 Jan 2024 13:49:59 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EB=B0=B0=ED=8F=AC=20=EC=9D=B4?= =?UTF-8?q?=ED=9B=84=20geojson=20=EC=9D=BD=EC=96=B4=EC=98=A4=EC=A7=80=20?= =?UTF-8?q?=EB=AA=BB=ED=95=98=EB=8A=94=20=ED=98=84=EC=83=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/palnet/comn/utils/CoordUtils.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 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 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);