Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: Convert degrees minutes seconds to decimal degrees

  1. #1
    Join Date
    Nov 2016
    Posts
    6

    Default Convert degrees minutes seconds to decimal degrees

    Hello

    What is the most efficient way to convert a value in degrees minutes & seconds to decimal degrees ?
    For example:

    135°49'54" --> 137.83166667

    I can use a series of split strings & , split & replace to separate into separate degrees, minutes & seconds & from there, the maths is easy
    But I suspect there is a better way
    Note- the length of the degrees values varies, sometimes 2 digits, so I can't use Strings Cut

    thanks


    Andrew

  2. #2
    Join Date
    Nov 2016
    Posts
    6

    Default

    To partially answer my question (I'm not sure if it efficient, but it works)

    Step 1. Use java expressions to extract degrees, minutes & seconds values

    degrees: bearing.substring(0,(bearing.indexOf("°")))
    minutes: bearing.substring((bearing.indexOf("°"))+1,(bearing.indexOf("'")))
    seconds: bearing.substring((bearing.indexOf("'"))+1,bearing.indexOf('"'))

    Step 2- use java expression to calculate the decimal value
    degrees + ((minutes/60) +(seconds/3600))

    If anyone has a better way, I'd be interested to see it


    Andrew

  3. #3
    Join Date
    Aug 2016
    Posts
    279

    Default

    That looks good.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2017 Pentaho Corporation. All Rights Reserved.