【无标题】geotool 计算四边形较长边对称轴的三分之一处坐标

import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.referencing.CRS;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;

public class FourSidedFigure {

private Coordinate[] coordinates;

public FourSidedFigure(Coordinate[] coordinates) {
    this.coordinates = coordinates;
}

public Coordinate getLongEdgeTrisection() throws FactoryException, TransformException {
    // 创建一个 GeometryFactory 对象
    GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();

    // 创建一个 LineString 对象,表示四边形的四条边
    LineString lineString = geometryFactory.createLineString(coordinates);

    // 计算每条边的长度,找出长边
    double maxLength = 0.0;
    int maxIndex = 0;
    for (int i = 0; i < 4; i++) {
        Coordinate p1 = coordinates[i];
        Coordinate p2 = coordinates[(i + 1) % 4];
        double length = p1.distance(p2);
        if (length > maxLength) {
            maxLength = length;
            maxIndex = i;
        }
    }

    // 计算长边的中点坐标
    Coordinate p1 = coordinates[maxIndex];
    Coordinate p2 = coordinates[(maxIndex + 1) % 4];
    double midLon = (p1.x + p2.x) / 2.0;
    double midLat = (p1.y + p2.y) / 2.0;

    // 计算长边中点到起点的方位角
    double azimuth = Math.atan2(p2.y - p1.y, p2.x - p1.x);

    // 使用三角函数计算长边对承轴的三分之一处的坐标
    double distance = maxLength / 3.0;
    double trisectionLon = midLon + distance * Math.cos(azimuth) / 111325.0;
    double trisectionLat = midLat + distance * Math.sin(azimuth) / 111139.0;

    // 将坐标转换为 WGS84 坐标参考系统
    CoordinateReferenceSystem crs = CRS.decode("EPSG:43
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值