Skip to content

Instantly share code, notes, and snippets.

@zydeco
Created October 8, 2014 20:39
Show Gist options
  • Save zydeco/59958820bb8c3a5e14ba to your computer and use it in GitHub Desktop.
Save zydeco/59958820bb8c3a5e14ba to your computer and use it in GitHub Desktop.
GeoUtmTest
package geoutmtest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import org.yaml.snakeyaml.Yaml;
import uk.me.jstott.jcoord.LatLng;
import uk.me.jstott.jcoord.UTMRef;
public class GeoUtmTest {
public static void main(String[] args) throws FileNotFoundException {
String path = "testdata.yaml";
InputStream input = new FileInputStream(new File(path));
Yaml yaml = new Yaml();
List<Map> testdata = (List) yaml.load(input);
int failures = 0;
for(Map<String,String> data : testdata) {
String ellipsoid = data.get(":ellipsoid");
if (!ellipsoid.equals("WGS-84")) continue;
String zone = data.get(":zone");
LatLng loc = new LatLng(Double.valueOf(data.get(":latitude")), Double.valueOf(data.get(":longitude")));
int lngZone = Integer.valueOf(zone.substring(0, zone.length()-1));
char latZone = zone.charAt(zone.length()-1);
UTMRef utm = new UTMRef(lngZone, latZone, Double.valueOf(data.get(":easting")), Double.valueOf(data.get(":northing")));
LatLng loc2 = utm.toLatLng();
UTMRef utm2 = loc.toUTMRef();
if (Math.abs(utm.getEasting() - utm2.getEasting()) > 0.01 ||
Math.abs(utm.getNorthing() - utm2.getNorthing()) > 0.01) {
System.out.println("FAIL!");
System.out.println(utm);
System.out.println(" is not within 0.01 of ");
System.out.println(utm2);
failures++;
}
if (Math.abs(loc.getLatitude() - loc2.getLatitude()) > 0.0001 ||
Math.abs(loc.getLongitude() - loc2.getLongitude()) > 0.0001) {
System.out.println("FAIL!");
System.out.println(loc);
System.out.println(" is not within 0.0001 of ");
System.out.println(loc2);
failures++;
}
}
System.out.println("finished with " + failures + " failures");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment