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

后端 未结 3 1040
陌清茗
陌清茗 2020-12-01 12:39

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

相关标签:
3条回答
  • 2020-12-01 13:22
    **begin  23°26’49”**
    degrees = 23
    minutes = 26
    seconds = 49
    decimal = ((minutes * 60)+seconds) / (60*60))
    answer = degrees + decimal
    **finish  23.44694444**
    
    0 讨论(0)
  • 2020-12-01 13:30

    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.

    0 讨论(0)
  • 2020-12-01 13:30

    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:

    "ffffd.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;
    
    0 讨论(0)
提交回复
热议问题