Skip to content

Commit

Permalink
fix: fix issue with datum conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
leluque committed Mar 8, 2021
1 parent 4221eba commit 99241ce
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 74 deletions.
15 changes: 2 additions & 13 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,14 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand All @@ -42,6 +31,7 @@
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
Expand All @@ -51,6 +41,5 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
6 changes: 3 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.source=1.8
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ 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 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 @@ -54,7 +54,7 @@ public static DecimalDegreesCoordinates toDD(DegreesMinutesSecondsCoordinates fr
return toDecimalDegree(fromCoordinates, toDatum);
}

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

public static UTMCoordinates toUTM(DecimalDegreesCoordinates fromCoordinates) {
return new UTMCoordinates(fromCoordinates);
Expand All @@ -72,23 +72,23 @@ 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);
}
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() + "]");
}
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 @@ -108,21 +108,21 @@ 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);
}
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() + "]");
}
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 All @@ -143,29 +143,38 @@ public static DegreesMinutesSecondsCoordinates toDMS(DecimalDegreesCoordinates f
// ************************************************************************

public static UTMCoordinates toDatum(UTMCoordinates coordinates, Datum datum) {
if (coordinates.getDatum() == datum) {
return coordinates;
}
return new UTMCoordinates(new DecimalDegreesCoordinates(coordinates).convertDatum(datum));
}

public static DecimalDegreesCoordinates toDatum(DecimalDegreesCoordinates coordinates, Datum datum) {
if (coordinates.getDatum() == datum) {
return coordinates;
}
return coordinates.convertDatum(datum);
}

public static DegreesMinutesSecondsCoordinates toDatum(DegreesMinutesSecondsCoordinates coordinates, Datum datum) {
if (coordinates.getDatum() == datum) {
return coordinates;
}
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);
}
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() + "]");
}
throw new IllegalArgumentException("The passed coordinate is an unknown implementation of Coordinates: ["
+ coordinates.getClass().getName() + "]");
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,25 @@ public void testDDToDMS() {
DecimalDegreesCoordinates coordinates = new DecimalDegreesCoordinates(-46.1795700000, -23.5151100000,
Datums.SAD69);
assertEquals("46° 10' 46.4520\" S 23° 30' 54.3960\" W",
CoordinatesConverter.toDMS(coordinates).toString());
CoordinatesConverter.toDMS(coordinates).toString().replace(",", "."));
}

@Test
public void testDDToDMS1() {
DecimalDegreesCoordinates coordinates = new DecimalDegreesCoordinates(-7, -37, Datums.SAD69);
DegreesMinutesSecondsCoordinates degreesMinutesSecondsCoordinates = CoordinatesConverter.toDMS(coordinates);
assertEquals("7° 0' 0.0000\" S 37° 0' 0.0000\" W",
degreesMinutesSecondsCoordinates.toString().replace(",", "."));
System.out.println(CoordinatesConverter.toDD(degreesMinutesSecondsCoordinates).toString());
}

@Test
public void testDMSToDD() {
DegreesMinutesSecondsCoordinates degreesMinutesSecondsCoordinates = new DegreesMinutesSecondsCoordinates(
Location.SOUTH, 7, 0, 0, Location.WEST, 37, 0, 0, Datums.WGS84);
System.out.println(CoordinatesConverter.toDD(degreesMinutesSecondsCoordinates).toString());
assertEquals("-7.0000000000 -37.0000000000",
CoordinatesConverter.toDD(degreesMinutesSecondsCoordinates).toString().replace(",", "."));
}

@Test
Expand Down Expand Up @@ -49,5 +67,13 @@ public void testDDToUTMSIRGAS2000() {
assertEquals(305861.6300, utmCoordinates.getX(), 0.01);
assertEquals(4882853.4451, utmCoordinates.getY(), 0.01);
}


@Test
public void testUTMToDMS() {
UTMCoordinates utmCoordinates = CoordinatesConverter.toUTM(new DecimalDegreesCoordinates(-7, -37, Datums.WGS84));
DegreesMinutesSecondsCoordinates degreesMinutesSecondsCoordinates = CoordinatesConverter.toDegreesMinutesSeconds(utmCoordinates);
System.out.println(degreesMinutesSecondsCoordinates.toString());
}

}

0 comments on commit 99241ce

Please sign in to comment.