- 浏览: 309840 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
a455642158:
xiajy 写道他妈的都该名字了,更可恶的金山手机助手是:sj ...
解决ADB server didn't ACK问题 -
wwt455653509:
关闭tadb.exe,重启eclipse搞定
解决ADB server didn't ACK问题 -
Frederic:
感谢,真是帮了大忙!腾讯
解决ADB server didn't ACK问题 -
xiajy:
他妈的都该名字了,更可恶的金山手机助手是:sjk_daemon ...
解决ADB server didn't ACK问题 -
xiaofeilv321:
赞同
解决ADB server didn't ACK问题
The code encapsulating a location on an Ellipsoid,
Negative latitudes are in the southern hemisphere, and negative longitudes are in the western hemisphere. The Comparable<T> implementation is omitted for clarity.
Now, we start getting to the fun part. The next type encapsulates the “geodetic curve.”
A “geodetic curve” is the solution we’re looking for. It describes how to get from one point on an ellipsoid to another. The ellipsoidal distance is the distance, in meters, between the two points along the surface of the ellipsoid. The azimuth is the direction of travel from the starting point to the ending point. The reverse azimuth, of course, is the direction back from the endpoint (which isn’t necessarily a 180 degree turn on an ellipsoid).
The final input to Vincenty’s Formula we need is an ellipsoid. We hold onto four parameters of an ellipsoid: the length of each semi-axis (in meters), the flattening ratio, and the inverse of the flattening ratio. Technically, we only need the length of one semi-axis and any one of the other three parameters. We’ll record all four for convenience.
Generally, you won’t need to specify ellipsoid parameters. The Ellipsoid type has a number of static instances that define “reference ellipsoids”. Reference ellipsoids represent some organization’s consensus on the “best” ellipsoidal parameters to use to model Earth. Two of the most widely accepted reference ellipsoids are defined above: WGS84 (the 1984 World Geodetic System) and GRS80 (the 1980 Geodetic Reference System).
Finally, we have the class that actually implements Vincenty’s Formula to solve the Geodetic Inverse Problem given a reference ellipsoid and two sets of global coordinates (equation numbers in comments relate directly to Vincenty’s publication):
The library also supports 3-D geodetic calculations (measurements that account for the elevation above or below the reference ellipsoid). For complete source code, documentation, and examples, download the entire Java library.
referencehttp://www.gavaghan.org/blog/2007/11/16/java-gps-receivers-and-geocaching-vincentys-formula/
http://www.gavaghan.org/blog/free-source-code/geodesy-library-vincentys-formula-java/
public class GlobalCoordinates implements Comparable<GlobalCoordinates>, Serializable { private double mLatitude; private double mLongitude; public GlobalCoordinates(double latitude, double longitude) { mLatitude = latitude; mLongitude = longitude; } public double getLatitude() { return mLatitude; } public void setLatitude(double latitude) { mLatitude = latitude; } public double getLongitude() { return mLongitude; } public void setLongitude(double longitude) { mLongitude = longitude; } }
Negative latitudes are in the southern hemisphere, and negative longitudes are in the western hemisphere. The Comparable<T> implementation is omitted for clarity.
Now, we start getting to the fun part. The next type encapsulates the “geodetic curve.”
public class GeodeticCurve implements Serializable { private final double mEllipsoidalDistance; private final double mAzimuth; private final double mReverseAzimuth; public GeodeticCurve(double ellipsoidalDistance, double azimuth, double reverseAzimuth) { mEllipsoidalDistance = ellipsoidalDistance; mAzimuth = azimuth; mReverseAzimuth = reverseAzimuth; } public double getEllipsoidalDistance() { return mEllipsoidalDistance; } public double getAzimuth() { return mAzimuth; } public double getReverseAzimuth() { return mReverseAzimuth; } }
A “geodetic curve” is the solution we’re looking for. It describes how to get from one point on an ellipsoid to another. The ellipsoidal distance is the distance, in meters, between the two points along the surface of the ellipsoid. The azimuth is the direction of travel from the starting point to the ending point. The reverse azimuth, of course, is the direction back from the endpoint (which isn’t necessarily a 180 degree turn on an ellipsoid).
The final input to Vincenty’s Formula we need is an ellipsoid. We hold onto four parameters of an ellipsoid: the length of each semi-axis (in meters), the flattening ratio, and the inverse of the flattening ratio. Technically, we only need the length of one semi-axis and any one of the other three parameters. We’ll record all four for convenience.
public class Ellipsoid implements Serializable { private final double mSemiMajorAxis; private final double mSemiMinorAxis; private final double mFlattening; private final double mInverseFlattening; private Ellipsoid(double semiMajor, double semiMinor, double flattening, double inverseFlattening) { mSemiMajorAxis = semiMajor; mSemiMinorAxis = semiMinor; mFlattening = flattening; mInverseFlattening = inverseFlattening; } static public final Ellipsoid WGS84 = fromAAndInverseF(6378137.0, 298.257223563); static public final Ellipsoid GRS80 = fromAAndInverseF(6378137.0, 298.257222101); static public final Ellipsoid GRS67 = fromAAndInverseF(6378160.0, 298.25); static public final Ellipsoid ANS = fromAAndInverseF(6378160.0, 298.25); static public final Ellipsoid Clarke1880 = fromAAndInverseF(6378249.145, 293.465); static public Ellipsoid fromAAndInverseF(double semiMajor, double inverseFlattening) { double f = 1.0 / inverseFlattening; double b = (1.0 – f) * semiMajor; return new Ellipsoid(semiMajor, b, f, inverseFlattening); } public double getSemiMajorAxis() { return mSemiMajorAxis; } public double getSemiMinorAxis() { return mSemiMinorAxis; } public double getFlattening() { return mFlattening; } public double getInverseFlattening() { return mInverseFlattening; } }
Generally, you won’t need to specify ellipsoid parameters. The Ellipsoid type has a number of static instances that define “reference ellipsoids”. Reference ellipsoids represent some organization’s consensus on the “best” ellipsoidal parameters to use to model Earth. Two of the most widely accepted reference ellipsoids are defined above: WGS84 (the 1984 World Geodetic System) and GRS80 (the 1980 Geodetic Reference System).
Finally, we have the class that actually implements Vincenty’s Formula to solve the Geodetic Inverse Problem given a reference ellipsoid and two sets of global coordinates (equation numbers in comments relate directly to Vincenty’s publication):
public class GeodeticCalculator { private final double TwoPi = 2.0 * Math.PI; public GeodeticCurve calculateGeodeticCurve(Ellipsoid ellipsoid, GlobalCoordinates start, GlobalCoordinates end) { // get constants double a = ellipsoid.getSemiMajorAxis(); double b = ellipsoid.getSemiMinorAxis(); double f = ellipsoid.getFlattening(); // get parameters as radians double phi1 = Angle.toRadians(start.getLatitude()); double lambda1 = Angle.toRadians(start.getLongitude()); double phi2 = Angle.toRadians(end.getLatitude()); double lambda2 = Angle.toRadians(end.getLongitude()); // calculations double a2 = a * a; double b2 = b * b; double a2b2b2 = (a2 – b2) / b2; double omega = lambda2 – lambda1; double tanphi1 = Math.tan(phi1); double tanU1 = (1.0 – f) * tanphi1; double U1 = Math.atan(tanU1); double sinU1 = Math.sin(U1); double cosU1 = Math.cos(U1); double tanphi2 = Math.tan(phi2); double tanU2 = (1.0 – f) * tanphi2; double U2 = Math.atan(tanU2); double sinU2 = Math.sin(U2); double cosU2 = Math.cos(U2); double sinU1sinU2 = sinU1 * sinU2; double cosU1sinU2 = cosU1 * sinU2; double sinU1cosU2 = sinU1 * cosU2; double cosU1cosU2 = cosU1 * cosU2; // eq. 13 double lambda = omega; // intermediates we’ll need to compute ’s’ double A = 0.0; double B = 0.0; double sigma = 0.0; double deltasigma = 0.0; double lambda0; boolean converged = false; for (int i = 0; i < 10; i++) { lambda0 = lambda; double sinlambda = Math.sin(lambda); double coslambda = Math.cos(lambda); // eq. 14 double sin2sigma = (cosU2 * sinlambda * cosU2 * sinlambda) + (cosU1sinU2 – sinU1cosU2 * coslambda) * (cosU1sinU2 – sinU1cosU2 * coslambda); double sinsigma = Math.sqrt(sin2sigma); // eq. 15 double cossigma = sinU1sinU2 + (cosU1cosU2 * coslambda); // eq. 16 sigma = Math.atan2(sinsigma, cossigma); // eq. 17 Careful! sin2sigma might be almost 0! double sinalpha = (sin2sigma == 0) ? 0.0 : cosU1cosU2 * sinlambda / sinsigma; double alpha = Math.asin(sinalpha); double cosalpha = Math.cos(alpha); double cos2alpha = cosalpha * cosalpha; // eq. 18 Careful! cos2alpha might be almost 0! double cos2sigmam = cos2alpha == 0.0 ? 0.0 : cossigma – 2 * sinU1sinU2 / cos2alpha; double u2 = cos2alpha * a2b2b2; double cos2sigmam2 = cos2sigmam * cos2sigmam; // eq. 3 A = 1.0 + u2 / 16384 * (4096 + u2 * (-768 + u2 * (320 – 175 * u2))); // eq. 4 B = u2 / 1024 * (256 + u2 * (-128 + u2 * (74 – 47 * u2))); // eq. 6 deltasigma = B * sinsigma * (cos2sigmam + B / 4 * (cossigma * (-1 + 2 * cos2sigmam2) – B / 6 * cos2sigmam * (-3 + 4 * sin2sigma) * (-3 + 4 * cos2sigmam2))); // eq. 10 double C = f / 16 * cos2alpha * (4 + f * (4 – 3 * cos2alpha)); // eq. 11 (modified) lambda = omega + (1 – C) * f * sinalpha * (sigma + C * sinsigma * (cos2sigmam + C * cossigma * (-1 + 2 * cos2sigmam2))); // see how much improvement we got double change = Math.abs((lambda – lambda0) / lambda); if ((i > 1) && (change < 0.0000000000001)) { converged = true; break; } } // eq. 19 double s = b * A * (sigma – deltasigma); double alpha1; double alpha2; // didn’t converge? must be N/S if (!converged) { if (phi1 > phi2) { alpha1 = 180.0; alpha2 = 0.0; } else if (phi1 < phi2) { alpha1 = 0.0; alpha2 = 180.0; } else { alpha1 = Double.NaN; alpha2 = Double.NaN; } } // else, it converged, so do the math else { double radians; // eq. 20 radians = Math.atan2(cosU2 * Math.sin(lambda), (cosU1sinU2 – sinU1cosU2 * Math.cos(lambda))); if (radians < 0.0) radians += TwoPi; alpha1 = Angle.toDegrees(radians); // eq. 21 radians = Math.atan2(cosU1 * Math.sin(lambda), (-sinU1cosU2 + cosU1sinU2 * Math.cos(lambda))) + Math.PI; if (radians < 0.0) radians += TwoPi; alpha2 = Angle.toDegrees(radians); } if (alpha1 >= 360.0) alpha1 -= 360.0; if (alpha2 >= 360.0) alpha2 -= 360.0; return new GeodeticCurve(s, alpha1, alpha2); } } There you have it! You have the tools you need to know the answer to the question “How far is it from here to there?” Here’s an example of using the code to calculate how far it is from the Lincoln Memorial in Washington, D.C. to the Eiffel Tower in Paris: public class Example { static public void main(String[] args) { // instantiate the calculator GeodeticCalculator geoCalc = new GeodeticCalculator(); // select a reference elllipsoid Ellipsoid reference = Ellipsoid.WGS84; // set Lincoln Memorial coordinates GlobalCoordinates lincolnMemorial; lincolnMemorial = new GlobalCoordinates(38.88922, -77.04978); // set Eiffel Tower coordinates GlobalCoordinates eiffelTower; eiffelTower = new GlobalCoordinates(48.85889, 2.29583); // calculate the geodetic curve GeodeticCurve geoCurve = geoCalc.calculateGeodeticCurve( reference, lincolnMemorial, eiffelTower ); double ellipseKilometers = geoCurve.getEllipsoidalDistance() / 1000.0; double ellipseMiles = ellipseKilometers * 0.621371192; System.out.println(“Lincoln Memorial to Eiffel Tower using WGS84″); System.out.printf( ” Ellipsoidal Distance: %1.2f kilometers (%1.2f miles)\n”, ellipseKilometers, ellipseMiles ); System.out.printf(” Azimuth: %1.2f degrees\n”, geoCurve.getAzimuth() ); System.out.printf(” Reverse Azimuth: %1.2f degrees\n”, geoCurve.getReverseAzimuth() ); } }
The library also supports 3-D geodetic calculations (measurements that account for the elevation above or below the reference ellipsoid). For complete source code, documentation, and examples, download the entire Java library.
referencehttp://www.gavaghan.org/blog/2007/11/16/java-gps-receivers-and-geocaching-vincentys-formula/
http://www.gavaghan.org/blog/free-source-code/geodesy-library-vincentys-formula-java/
- geodesy.zip (90.8 KB)
- 下载次数: 3
- inverse.pdf (810.4 KB)
- 下载次数: 3
发表评论
-
使用fatjar导出有第三方库引用的jar
2013-11-26 16:24 1378把android项目导出为jar时,老是不能把第三方库一起导出 ... -
(转)关于百度地图和高德地图,关于地图坐标系
2013-11-21 11:23 8794原文作者: 深白Andy 原 ... -
android操作png
2013-10-16 11:31 1421PNGJ是纯Java库的高效编码解码/ PNG图像的库,开源项 ... -
通过SharedPreference实现共享数据
2013-04-22 17:07 2337如果程序B想要访问程序A的sharedPreference可以 ... -
android 安装app私有存储目录下的apk
2013-04-08 18:05 3254一般安装app就是 Intent i = new Intent ... -
android在线播放音频视频
2012-12-05 17:43 1903在项目中要用到终端现场录制视频音频,用户在web页面看,所以找 ... -
Android video streaming and encoder
2012-11-26 15:38 1621一个开源的android流媒体项目https://code.g ... -
锁定屏幕
2012-10-24 21:52 1214if (!mDPM.isAdminActive(mDevice ... -
android 企业级开发框架
2012-10-24 17:38 1295http://code.google.com/p/openmo ... -
afinal 开发框架
2012-10-20 18:03 1239afinal 是一个android的 orm 和 ioc 框架 ... -
在后台保持屏幕唤醒状态
2012-10-16 21:05 997在网上找了很久,都是在前台起作用的,只有自己实现了,还有些小问 ... -
NFC Android 应用开发指南
2012-09-30 14:44 1385文档里说的很详细很有用,能看完,对NFC在android上的开 ... -
(转)百度地图API经纬度转换接口
2012-09-28 20:55 31683先列参考文 百度提供的各种地图API http://dev.b ... -
(转)google地图纠偏
2012-09-28 12:13 2035由于受到国家一些法律 ... -
位置服务的封装
2012-09-24 21:33 939/** * Retrieve accurate locat ... -
结合重力感应器来计算手机移动的方位
2012-09-24 21:24 1184public void onSensorChanged( Se ... -
根据Latitude/Longitude 计算方位,距离等
2012-09-24 21:09 3963里面有详细的说明http://www.movable-type ... -
通过google api获得位置的方向
2012-09-23 15:10 975private String[] getDirectio ... -
模拟位置信息
2012-09-23 12:40 1165计算两点间距离 方法一 double dist = 0.0; ... -
Encrypting an Object with DES
2012-09-20 09:50 713try { // Generate a tempor ...
相关推荐
经纬度计算距离经纬度计算距离工具, 挺不错的。经纬度计算距离经纬度计算距离工具, 挺不错的。
根据经纬度计算地球上任意两点间的距离,精度高,GUI界面操作简单,小白可直接使用。
java根据两点的经纬度计算直线距离,以及百度地图、高德地图、谷歌地图不同调用方法
mysql函数-根据经纬度坐标计算距离
通过两个经纬度计算两个经纬度之间的距离,误差在2-5米,通过高德地图测试通过
经纬度计算距离
两点之间计算距离的小工具,对求两点之间的距离很有帮助,希望对您有用
1、已知两点经纬度求距离方位角 2、已知一点经纬度、距离、方位角求另一点经纬度。 java源码。本人手敲,亲测简单实用。可用于百度地图、Google地图开发,误差极小基本可忽略。
经纬度计算距离工具可以快速的计算两点这间的距离
java计算两个经纬度之间的距离,并且按照由近及远的距离排序
电子-根据两点经纬度计算距离.doc,单片机/嵌入式STM32-F0/F1/F2
根据经纬度计算距离,根据两点的经纬度计算两点的的距离,单位为(米)。
根据网上给出的代码,增加了批量功能。计算一批经纬度的平均经度与平均纬度,然后各经纬度与平均值之间的距离
经过两点之间经纬度计算直线距离,两种方法皆可用
经纬度计算距离,经纬度计算距离公式,matlab源码
新人报道,因为测试的时候拿到数据库的经纬度计算不方便,就自己写了个计算的软件,方便测试人员使用
python 经纬度计算距离,输入经纬度即可计算亮点距离,导入即可调用。
已知两点经纬度,自动计算距离。在表格分别输入两点的经度、纬度,即可计算出这两个点之间的距离长度。已知两点经纬度,自动计算距离。在表格分别输入两点的经度、纬度,即可计算出这两个点之间的距离长度。