문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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;
**begin  23°26’49”**
degrees = 23
minutes = 26
seconds = 49
decimal = ((minutes * 60)+seconds) / (60*60))
answer = degrees + decimal
**finish  23.44694444**
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top