| | |
| | | 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点坐标 |
| | | */ |
| | |
| | | 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(); |
| | | } |
| | | |
| | | } |