how to convert between degrees, minutes, seconds to Decimal coordinates

一笑奈何 提交于 2019-11-26 17:45:23

问题


Looking for a java utility. It is even better if you can tell me how to do it using geotools library.


回答1:


By "Decimal coordinates" do you mean latitude and longitude (also known as the decimal degree)? If so, what you're trying to do is pretty easy:

Given a DMS (Degrees, Minutes, Seconds) coordinate such as W87°43′41″, it's trivial to convert it to a number of decimal degrees using the following method: Calculate the total number of seconds, 43′41″ = (43*60 + 41) = 2621 seconds. The fractional part is total number of seconds divided by 3600. 2621 / 3600 = ~0.728056 Add fractional degrees to whole degrees to produce the final result: 87 + 0.728056 = 87.728056

Since it is a West longitude coordinate, negate the result. The final result is -87.728056.

From Wikipedia. Here's a Javascript widget that does the same thing.




回答2:


It depends on your source format. If it's already split up into degrees (d), minutes (m), and seconds (s), your algorithm is:

(assuming d is can be positive or negative)

dd = Math.signum(d) * (Math.abs(d) + (m / 60.0) + (s / 3600.0));

If it's smooshed together into a string, the usual format is:

"ddd.mmss"

So parse out using a regular expression or String.substring() to get m and s.

Converting back is:

d = (int)dd;  // Truncate the decimals
t1 = (dd - d) * 60;
m = (int)t1;
s = (t1 - m) * 60;



回答3:


**begin  23°26’49”**
degrees = 23
minutes = 26
seconds = 49
decimal = ((minutes * 60)+seconds) / (60*60))
answer = degrees + decimal
**finish  23.44694444**


来源:https://stackoverflow.com/questions/8263959/how-to-convert-between-degrees-minutes-seconds-to-decimal-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!