Browse Source

좌표로 법정동코드 찾기(beta)

pull/12/head
박재우 11 months ago
parent
commit
3d9aff1a26
  1. 102
      pav-server/src/main/java/com/palnet/comn/utils/FlightUtils.java

102
pav-server/src/main/java/com/palnet/comn/utils/FlightUtils.java

@ -1,7 +1,16 @@
package com.palnet.comn.utils; package com.palnet.comn.utils;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateSequence; import org.locationtech.jts.geom.CoordinateSequence;
import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.Geometry;
@ -18,6 +27,9 @@ import org.locationtech.proj4j.CRSFactory;
import org.locationtech.proj4j.CoordinateReferenceSystem; import org.locationtech.proj4j.CoordinateReferenceSystem;
import org.locationtech.proj4j.ProjCoordinate; import org.locationtech.proj4j.ProjCoordinate;
import lombok.extern.log4j.Log4j2;
@Log4j2
public class FlightUtils { public class FlightUtils {
//기본좌표를 받아 버퍼좌표를 생성하는 유틸 //기본좌표를 받아 버퍼좌표를 생성하는 유틸
public static Coordinate[] createBuffer(Coordinate[] lineCoords, Integer bufval) { public static Coordinate[] createBuffer(Coordinate[] lineCoords, Integer bufval) {
@ -134,4 +146,94 @@ public class FlightUtils {
return result; return result;
} }
public static JSONObject getCoordinateGis(Coordinate coordinate) throws IOException, ParseException {
String path = "C:\\Users\\Jaewoo\\Downloads\\pal\\pav\\kac\\coordinate\\CoordinateFolder\\";
String baseFileName = "all_location.geojson";
JSONObject obj = new JSONObject();
while(true) {
try {
obj = parseGeoJson(path+baseFileName, coordinate);
path += obj.get("CD")+"\\";
System.out.println(obj.toString());
}catch(Exception e) {
log.error("error>>>> : {}" , e);
return obj;
}
}
}
public static JSONObject parseGeoJson(String path, Coordinate coordinate) throws IOException, ParseException {
GeometryFactory geometryFactory = new GeometryFactory();
FileInputStream fileInputStream = new FileInputStream(path);
BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream, "UTF-8"), 8192);
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);
Point point = geometryFactory.createPoint(coordinate);
String type = (String) jsonObject.get("type");
Object airArea = jsonObject;
List<JSONObject> features = (List<JSONObject>) jsonObject.get("features");
fileInputStream.close();
reader.close();
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 y = ((JSONArray) coord).get(0);
Object x = ((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;
}
} }

Loading…
Cancel
Save