|
|
@ -7,7 +7,6 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.geotools.geojson.feature.FeatureJSON; |
|
|
|
import org.geotools.geojson.feature.FeatureJSON; |
|
|
|
import org.geotools.geojson.geom.GeometryJSON; |
|
|
|
import org.geotools.geojson.geom.GeometryJSON; |
|
|
|
import org.geotools.geometry.jts.JTS; |
|
|
|
import org.geotools.geometry.jts.JTS; |
|
|
|
import org.geotools.geometry.jts.JTSFactoryFinder; |
|
|
|
|
|
|
|
import org.geotools.referencing.CRS; |
|
|
|
import org.geotools.referencing.CRS; |
|
|
|
import org.geotools.referencing.GeodeticCalculator; |
|
|
|
import org.geotools.referencing.GeodeticCalculator; |
|
|
|
import org.json.simple.JSONArray; |
|
|
|
import org.json.simple.JSONArray; |
|
|
@ -21,7 +20,6 @@ import org.locationtech.proj4j.BasicCoordinateTransform; |
|
|
|
import org.locationtech.proj4j.CRSFactory; |
|
|
|
import org.locationtech.proj4j.CRSFactory; |
|
|
|
import org.locationtech.proj4j.ProjCoordinate; |
|
|
|
import org.locationtech.proj4j.ProjCoordinate; |
|
|
|
import org.opengis.feature.simple.SimpleFeature; |
|
|
|
import org.opengis.feature.simple.SimpleFeature; |
|
|
|
import org.opengis.referencing.FactoryException; |
|
|
|
|
|
|
|
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
|
|
|
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
|
|
|
import org.opengis.referencing.operation.MathTransform; |
|
|
|
import org.opengis.referencing.operation.MathTransform; |
|
|
|
import org.opengis.referencing.operation.TransformException; |
|
|
|
import org.opengis.referencing.operation.TransformException; |
|
|
@ -39,12 +37,11 @@ import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
// TODO areaUtils, airspaceUtils merge
|
|
|
|
|
|
|
|
// TODO airspaceUtils의 검증 관련 로직은 해당 표시에서 적용.
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class AirAreaUtils { |
|
|
|
public class AirAreaUtils { |
|
|
|
|
|
|
|
|
|
|
|
private final int PERIMETER_OF_EARTH = 40075 * 1000; // 지구 둘레(m)
|
|
|
|
private final int PERIMETER_OF_EARTH = 40075 * 1000; // 지구 둘레(m)
|
|
|
|
|
|
|
|
|
|
|
|
private final String RESOURCE_BASE_PATH = "air/airspace/"; |
|
|
|
private final String RESOURCE_BASE_PATH = "air/airspace/"; |
|
|
|
private final String COMMON_PATH = "common/"; |
|
|
|
private final String COMMON_PATH = "common/"; |
|
|
|
private final String CUSTOM_PATH = "custom/"; |
|
|
|
private final String CUSTOM_PATH = "custom/"; |
|
|
@ -767,64 +764,6 @@ public class AirAreaUtils { |
|
|
|
return coordList; |
|
|
|
return coordList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
// 라인 버퍼 생성 샘플
|
|
|
|
|
|
|
|
public static void main(String[] args) throws FactoryException, TransformException { |
|
|
|
|
|
|
|
// EPSG:4326 좌표계 정의
|
|
|
|
|
|
|
|
CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// EPSG:3857 좌표계 정의 (투영 좌표계)
|
|
|
|
|
|
|
|
// CoordinateReferenceSystem crs3857 = CRS.decode("EPSG:3857");
|
|
|
|
|
|
|
|
CoordinateReferenceSystem crs3857 = CRS.decode("EPSG:5181"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 좌표 변환기 설정
|
|
|
|
|
|
|
|
MathTransform transformTo3857 = CRS.findMathTransform(crs4326, crs3857); |
|
|
|
|
|
|
|
MathTransform transformTo4326 = CRS.findMathTransform(crs3857, crs4326); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GeometryFactory 생성
|
|
|
|
|
|
|
|
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// LineString 좌표 정의 (EPSG:4326)
|
|
|
|
|
|
|
|
Coordinate[] coordinates = new Coordinate[]{ |
|
|
|
|
|
|
|
new Coordinate(127.0, 37.0), |
|
|
|
|
|
|
|
new Coordinate(127.1, 37.1), |
|
|
|
|
|
|
|
new Coordinate(127.2, 37.2) |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
List<Coordinate> coordinates1 = AirAreaUtils.swapCoordinates(Arrays.asList(coordinates)); |
|
|
|
|
|
|
|
LineString lineString = geometryFactory.createLineString(coordinates1.toArray(new Coordinate[0])); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// LineString을 EPSG:3857로 변환
|
|
|
|
|
|
|
|
LineString transformedLineString = (LineString) JTS.transform(lineString, transformTo3857); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 거리 (단위: 미터)
|
|
|
|
|
|
|
|
double distance = 1000; // 1km
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Buffer를 사용하여 LineString을 둘러싼 Polygon 생성 (EPSG:3857)
|
|
|
|
|
|
|
|
Polygon bufferedPolygon = (Polygon) transformedLineString.buffer(distance); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Buffered Polygon을 EPSG:4326로 변환
|
|
|
|
|
|
|
|
Polygon finalPolygon = (Polygon) JTS.transform(bufferedPolygon, transformTo4326); |
|
|
|
|
|
|
|
List<de.micromata.opengis.kml.v_2_2_0.Coordinate> finalCoordinates = Arrays.stream(finalPolygon.getCoordinates()).map(coordinate -> new de.micromata.opengis.kml.v_2_2_0.Coordinate(coordinate.y, coordinate.x)).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 결과 출력
|
|
|
|
|
|
|
|
KmlUtils.KmlRq bufferRq = KmlUtils.KmlRq.builder() |
|
|
|
|
|
|
|
.name("test") |
|
|
|
|
|
|
|
.type(KmlUtils.TYPE.POLYGON) |
|
|
|
|
|
|
|
.coordinates(finalCoordinates) |
|
|
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KmlUtils.KmlRq lineRq = KmlUtils.KmlRq.builder() |
|
|
|
|
|
|
|
.name("test") |
|
|
|
|
|
|
|
.type(KmlUtils.TYPE.LINESTRING) |
|
|
|
|
|
|
|
.coordinates(Arrays.stream(coordinates).map(coordinate -> new de.micromata.opengis.kml.v_2_2_0.Coordinate(coordinate.x, coordinate.y)).collect(Collectors.toList())) |
|
|
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
String str = KmlUtils.createKmlPolygons(List.of(bufferRq, lineRq)); |
|
|
|
|
|
|
|
System.out.println(str); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Coordinate transformCoordinate(Coordinate sourceCoord, String sourceCRSCode, String targetCRSCode) throws Exception { |
|
|
|
public static Coordinate transformCoordinate(Coordinate sourceCoord, String sourceCRSCode, String targetCRSCode) throws Exception { |
|
|
|
// 소스와 타겟 CRS 정의
|
|
|
|
// 소스와 타겟 CRS 정의
|
|
|
|
CoordinateReferenceSystem sourceCRS = CRS.decode(sourceCRSCode); |
|
|
|
CoordinateReferenceSystem sourceCRS = CRS.decode(sourceCRSCode); |
|
|
@ -837,16 +776,4 @@ public class AirAreaUtils { |
|
|
|
return JTS.transform(sourceCoord, null, transform); |
|
|
|
return JTS.transform(sourceCoord, null, transform); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Coordinate sourceCoord = new Coordinate(37.111, 127.1133); |
|
|
|
|
|
|
|
Coordinate transformedCoord = transformCoordinate(sourceCoord, "EPSG:4326", "EPSG:5181"); |
|
|
|
|
|
|
|
System.out.println("Transformed Coordinate1: " + transformedCoord); |
|
|
|
|
|
|
|
Coordinate transformedCoord2 = transformCoordinate(transformedCoord, "EPSG:5181", "EPSG:4326"); |
|
|
|
|
|
|
|
System.out.println("Transformed Coordinate2: " + transformedCoord2); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|