使用jts-core 1.19.0,已知圆心坐标(N37445900,E112370800)、半径 24.3海里、弧起点坐标(N37525600,E113060900)、弧终点坐标(N37210000,E112320700)创建弧线
时间: 2023-07-10 19:25:35 浏览: 189
首先,需要将坐标转换为 JTS 的 Point 类型,可以使用以下代码:
```
Coordinate centerCoordinate = new Coordinate(112.370800, 37.445900);
Point centerPoint = new GeometryFactory().createPoint(centerCoordinate);
Coordinate startPointCoordinate = new Coordinate(113.060900, 37.525600);
Point startPoint = new GeometryFactory().createPoint(startPointCoordinate);
Coordinate endPointCoordinate = new Coordinate(112.320700, 37.210000);
Point endPoint = new GeometryFactory().createPoint(endPointCoordinate);
```
然后,需要计算圆弧的起始角度和终止角度。可以使用以下代码:
```
double radius = 24.3; // 海里
double startAngle = Math.toDegrees(Math.atan2(startPoint.getY() - centerPoint.getY(), startPoint.getX() - centerPoint.getX()));
double endAngle = Math.toDegrees(Math.atan2(endPoint.getY() - centerPoint.getY(), endPoint.getX() - centerPoint.getX()));
if (endAngle < startAngle) {
endAngle += 360.0;
}
double arcAngle = endAngle - startAngle;
```
最后,使用 JTS 的 ArcBuilder 类创建圆弧,并将其转换为 LineString 类型。可以使用以下代码:
```
ArcBuilder arcBuilder = new ArcBuilder(centerPoint.getCoordinate(), radius);
arcBuilder.setStartAngle(startAngle);
arcBuilder.setAngleExtent(arcAngle);
Geometry arcGeometry = arcBuilder.getGeometry(new GeometryFactory());
LineString arcLineString = (LineString) arcGeometry;
```
现在,`arcLineString` 就是所需的圆弧线。可以将其用于后续的操作。
阅读全文