‘liusuyi’
2023-11-01 606d7388589829e6a7108a48898d4e4126312d73
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.ard.utils.other;
 
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.gavaghan.geodesy.GlobalPosition;
 
/**
 * @Description: gis工具类
 * @ClassName: GisUtils
 * @Author: 刘苏义
 * @Date: 2023年07月03日15:23
 * @Version: 1.0
 **/
public class GisUtils {
    public static GeodeticCalculator geodeticCalculator = new GeodeticCalculator();
    /**
     * 根据经纬度,计算两点间的距离
     *
     * @param From 第一个点的经纬度
     * @param To  第二个点的经纬度
     * @return 返回距离 单位米
     */
    public static double getDistance(double[] From, double[] To) {
        double longitudeFrom = From[0];
        double latitudeFrom = From[1];
        double longitudeTo = To[0];
        double latitudeTo = To[1];
        GlobalCoordinates source = new GlobalCoordinates(latitudeFrom, longitudeFrom);
        GlobalCoordinates target = new GlobalCoordinates(latitudeTo, longitudeTo);
        return geodeticCalculator.calculateGeodeticCurve(Ellipsoid.WGS84, source, target).getEllipsoidalDistance();
    }
    /**
     * 通过A点坐标,长度和Y轴角度计算B点坐标
     */
    public static Double[] CalculateCoordinates(Double[] radarCoordinates, double distance, Double angle) {
        //double[] to_wgs84 = LonlatConver.gcj02_To_Wgs84(radarCoordinates[0], radarCoordinates[1]);
        double Ax = radarCoordinates[0]; // A 点的 X 坐标
        double Ay = radarCoordinates[1]; // A 点的 Y 坐标
        double AB = distance; // AB 的长度
        double angleWithYAxisDegrees = angle; // AB 与 Y 轴的角度(以度数表示)
        GeodeticCalculator calculator = new GeodeticCalculator();
        GlobalCoordinates globalCoordinates = new GlobalCoordinates(Ay, Ax);
        GlobalCoordinates globalCoordinates1 = calculator.calculateEndingGlobalCoordinates(Ellipsoid.WGS84, globalCoordinates, angleWithYAxisDegrees, AB);
        return new Double[]{globalCoordinates1.getLongitude(), globalCoordinates1.getLatitude()};
    }
    /**
     * 计算从from到to方向的直线与正北方向夹角
     *
     * @param longitudeFrom 第一个点的经度
     * @param latitudeFrom  第一个点的纬度
     * @param longitudeTo   第二个点的经度
     * @param latitudeTo    第二个点的纬度
     * @return 返回角度
     */
    public static double getNorthAngle(double longitudeFrom, double latitudeFrom, double longitudeTo, double latitudeTo) {
        GlobalPosition source = new GlobalPosition(latitudeFrom, longitudeFrom, 0);
        GlobalPosition target = new GlobalPosition(latitudeTo, longitudeTo, 0);
        return geodeticCalculator.calculateGeodeticMeasurement(Ellipsoid.WGS84, source, target).getAzimuth();
    }
 
}