| | |
| | | import org.gavaghan.geodesy.Ellipsoid; |
| | | import org.gavaghan.geodesy.GeodeticCalculator; |
| | | import org.gavaghan.geodesy.GlobalCoordinates; |
| | | import org.gavaghan.geodesy.GlobalPosition; |
| | | |
| | | /** |
| | | * @Description: gis工具类 |
| | |
| | | * @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 = to_wgs84[0]; // A 点的 X 坐标 |
| | | double Ay = to_wgs84[1]; // A 点的 Y 坐标 |
| | | 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 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(); |
| | | } |
| | | |
| | | } |