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

后端 未结 3 1041
陌清茗
陌清茗 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: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;
    

提交回复
热议问题