Browse Source

feat : 배포 이후 geojson 읽어오지 못하는 현상 수정

pull/18/head
qkr7828 8 months ago
parent
commit
7a387f59bc
  1. 40
      pav-server/src/main/java/com/palnet/comn/utils/CoordUtils.java

40
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.Point;
import org.locationtech.jts.geom.Polygon; import org.locationtech.jts.geom.Polygon;
import org.springframework.core.io.ClassPathResource; 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; import lombok.extern.slf4j.Slf4j;
@ -33,7 +36,7 @@ public class CoordUtils {
private static final CoordUtils INSTANCE = new CoordUtils(); private static final CoordUtils INSTANCE = new CoordUtils();
private String baseFileName = "/all_location.geojson"; private String baseFileName = "all_location.geojson";
private List<JSONObject> allLocation; private List<JSONObject> allLocation;
@ -97,20 +100,18 @@ public class CoordUtils {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
String path = basePath + coords + baseFileName; String path = basePath + coords + "/" + baseFileName;
try(InputStream inputStream = new ClassPathResource(path).getInputStream(); try (InputStream inputStream = new ClassPathResource(path).getInputStream()) {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8192)) { byte[] binaryData = FileCopyUtils.copyToByteArray(inputStream);
String content = new String(binaryData, "UTF-8");
JSONParser jsonParser = new JSONParser(); JSONParser jsonParser = new JSONParser();
jsonObject = (JSONObject) jsonParser.parse(content);
jsonObject = (JSONObject) jsonParser.parse(reader); } catch (Exception e) {
e.printStackTrace();
}catch(Exception e) { }
e.getStackTrace();
}
return jsonObject; return jsonObject;
} }
@ -257,22 +258,21 @@ public class CoordUtils {
Point point = null; Point point = null;
try(InputStream inputStream = new ClassPathResource(path).getInputStream(); try (InputStream inputStream = new ClassPathResource(path).getInputStream()) {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8192)) {
JSONParser jsonParser = new JSONParser(); byte[] binaryData = FileCopyUtils.copyToByteArray(inputStream);
String content = new String(binaryData, "UTF-8");
JSONObject jsonObject = (JSONObject) jsonParser.parse(reader); JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(content);
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.printStackTrace();
e.getStackTrace(); }
}
return this.contains(features, point); return this.contains(features, point);

Loading…
Cancel
Save