Skip to content

Commit

Permalink
feat: adds generic conversion methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ioxua committed Jan 12, 2021
1 parent f7753ed commit a2c742f
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ public static DecimalDegreesCoordinates toDecimalDegree(DegreesMinutesSecondsCoo
return toDatum(new DecimalDegreesCoordinates(fromCoordinates), toDatum);
}

public static DecimalDegreesCoordinates toDecimalDegree(Coordinates fromCoordinates, Datum toDatum) {
if (fromCoordinates instanceof UTMCoordinates) {
return toDecimalDegree((UTMCoordinates) fromCoordinates, toDatum);
} else if (fromCoordinates instanceof DegreesMinutesSecondsCoordinates) {
return toDecimalDegree((DegreesMinutesSecondsCoordinates) fromCoordinates, toDatum);
} else if (fromCoordinates instanceof DecimalDegreesCoordinates) {
if (fromCoordinates.getDatum().isEqual(toDatum)) {
return (DecimalDegreesCoordinates) fromCoordinates;
}

return toDatum((DecimalDegreesCoordinates) fromCoordinates, toDatum);
}

throw new IllegalArgumentException("The passed coordinate is an unknown implementation of Coordinates: [" +
fromCoordinates.getClass().getName() + "]");
}

public static DecimalDegreesCoordinates toDD(UTMCoordinates fromCoordinates) {
return toDecimalDegree(fromCoordinates);
}
Expand All @@ -37,6 +54,8 @@ public static DecimalDegreesCoordinates toDD(DegreesMinutesSecondsCoordinates fr
return toDecimalDegree(fromCoordinates, toDatum);
}

// ************************************************************************

public static UTMCoordinates toUTM(DecimalDegreesCoordinates fromCoordinates) {
return new UTMCoordinates(fromCoordinates);
}
Expand All @@ -53,6 +72,24 @@ public static UTMCoordinates toUTM(DegreesMinutesSecondsCoordinates fromCoordina
return toDatum(new UTMCoordinates(new DecimalDegreesCoordinates(fromCoordinates)), toDatum);
}

public static UTMCoordinates toUTM(Coordinates fromCoordinates, Datum toDatum) {
if (fromCoordinates instanceof DegreesMinutesSecondsCoordinates) {
return toUTM((DegreesMinutesSecondsCoordinates) fromCoordinates, toDatum);
} else if (fromCoordinates instanceof DecimalDegreesCoordinates) {
return toUTM((DecimalDegreesCoordinates) fromCoordinates, toDatum);
} else if (fromCoordinates instanceof UTMCoordinates) {
if (fromCoordinates.getDatum().isEqual(toDatum)) {
return (UTMCoordinates) fromCoordinates;
}
return toDatum((UTMCoordinates) fromCoordinates, toDatum);
}

throw new IllegalArgumentException("The passed coordinate is an unknown implementation of Coordinates: [" +
fromCoordinates.getClass().getName() + "]");
}

// ************************************************************************

public static DegreesMinutesSecondsCoordinates toDegreesMinutesSeconds(UTMCoordinates fromCoordinates) {
return new DegreesMinutesSecondsCoordinates(new DecimalDegreesCoordinates(fromCoordinates));
}
Expand All @@ -71,6 +108,22 @@ public static DegreesMinutesSecondsCoordinates toDegreesMinutesSeconds(DecimalDe
return toDatum(new DegreesMinutesSecondsCoordinates(fromCoordinates), toDatum);
}

public static DegreesMinutesSecondsCoordinates toDegreesMinutesSeconds(Coordinates fromCoordinates, Datum toDatum) {
if (fromCoordinates instanceof UTMCoordinates) {
return toDegreesMinutesSeconds((UTMCoordinates) fromCoordinates, toDatum);
} else if (fromCoordinates instanceof DecimalDegreesCoordinates) {
return toDegreesMinutesSeconds((DecimalDegreesCoordinates) fromCoordinates, toDatum);
} else if (fromCoordinates instanceof DegreesMinutesSecondsCoordinates) {
if (fromCoordinates.getDatum().isEqual(toDatum)) {
return (DegreesMinutesSecondsCoordinates) fromCoordinates;
}
return toDatum((DegreesMinutesSecondsCoordinates) fromCoordinates, toDatum);
}

throw new IllegalArgumentException("The passed coordinate is an unknown implementation of Coordinates: [" +
fromCoordinates.getClass().getName() + "]");
}

public static DegreesMinutesSecondsCoordinates toDMS(UTMCoordinates fromCoordinates) {
return toDegreesMinutesSeconds(fromCoordinates);
}
Expand Down Expand Up @@ -101,6 +154,19 @@ public static DegreesMinutesSecondsCoordinates toDatum(DegreesMinutesSecondsCoor
return new DegreesMinutesSecondsCoordinates(new DecimalDegreesCoordinates(coordinates).convertDatum(datum));
}

public static Coordinates toDatum(Coordinates coordinates, Datum datum) {
if (coordinates instanceof UTMCoordinates) {
return toDatum((UTMCoordinates) coordinates, datum);
} else if (coordinates instanceof DecimalDegreesCoordinates) {
return toDatum((DecimalDegreesCoordinates) coordinates, datum);
} else if (coordinates instanceof DegreesMinutesSecondsCoordinates) {
return toDatum((DegreesMinutesSecondsCoordinates) coordinates, datum);
}

throw new IllegalArgumentException("The passed coordinate is an unknown implementation of Coordinates: [" +
coordinates.getClass().getName() + "]");
}

// ************************************************************************

public static UTMCoordinates toHemisphere(UTMCoordinates coordinates, Hemisphere hemisphere) {
Expand Down

0 comments on commit a2c742f

Please sign in to comment.