Java Degree Convert to toDecimalDegrees(String picaValue)

Here you can find the source of toDecimalDegrees(String picaValue)

Description

Converts coordinates in pica format to decimal degree (as used by google maps).

License

Open Source License

Return

the decimal degree representation of the coordinates

Declaration

public static double toDecimalDegrees(String picaValue) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*w  w w  .j  a v a 2s. c o  m*/
     * Converts coordinates to decimal degree (as used by google maps).
     * 
     */
    public static double toDecimalDegrees(int degree, int minutes,
            double seconds) {
        return (((seconds / 60) + minutes) / 60) + degree;
    }

    /**
     * Converts coordinates in pica format to decimal degree (as used by google maps).
     *
     * @return the decimal degree representation of the coordinates
     */
    public static double toDecimalDegrees(String picaValue) {
        if (picaValue == null || picaValue.length() == 0
                || (!isValid(picaValue))) {
            return 0d;
        }
        String[] strings = picaValue.split(" ");
        if (strings.length < 3) {
            return 0d;
        }

        int degree = Integer.valueOf(strings[1]);
        int minutes = Integer.valueOf(strings[2]);
        double seconds = 0d;

        if (strings.length >= 4) {
            seconds = Double.valueOf(strings[3]);
        }

        int factor = "W".equals(strings[0]) || "S".equals(strings[0]) ? -1
                : 1;
        return ((((seconds / 60) + minutes) / 60) + degree) * factor;
    }

    /**
     * @param picaValue
     * @return
     */
    private static boolean isValid(String picaValue) {
        String regex = "[EWSN]{1}\\s[0-9]{3}\\s[0-9]{2}(\\s[0-9]*)*";
        return picaValue.matches(regex);
    }
}

Related

  1. degreesToMetres(double degrees)
  2. degreesToPercent(float n)
  3. degreesToRA(double val)
  4. degreesToSexigessimal(double ra, double dec)
  5. degreesToString(final double value, final char positiveChar, final char negativeChar)
  6. toDegrees(double degrees, int nDecimals, boolean longitude)