Commit 38eabe65 authored by Matija Obreza's avatar Matija Obreza

Milko build

parent 64076cb4
......@@ -24,8 +24,8 @@ import org.apache.log4j.Logger;
public class GeoUtils {
private static final Logger _log = Logger.getLogger(GeoUtils.class);
private static final Pattern LATITUDE = Pattern.compile("([\\d\\- ]{2})([\\d\\- ]{2})([\\d\\- ]{2})(N|S)");
private static final Pattern LONGITUDE = Pattern.compile("([\\d\\- ]{3})([\\d\\- ]{2})([\\d\\- ]{2})(E|W)");
private static final Pattern LATITUDE = Pattern.compile("([\\d\\- ]{2})([\\d\\- ]{2})([\\d\\- ]{2})(N|S)", Pattern.CASE_INSENSITIVE);
private static final Pattern LONGITUDE = Pattern.compile("([\\d\\- ]{3})([\\d\\- ]{2})([\\d\\- ]{2})(E|W)", Pattern.CASE_INSENSITIVE);
/**
* Convert DDMMSS[NS] to decimal latitude
......@@ -46,7 +46,7 @@ public class GeoUtils {
Matcher m = LATITUDE.matcher(str.replace('-', '0').replace(' ', '0'));
if (m.matches()) {
_log.trace("Latitude " + str + " matches format DDMMSS[EW]");
_log.trace("Latitude " + str + " matches format DDMMSS[NS]");
String deg = m.group(1);
String min = m.group(2);
String sec = m.group(3);
......@@ -55,12 +55,12 @@ public class GeoUtils {
double latitude = Double.parseDouble(deg);
latitude += Double.parseDouble(min) / 60.0;
latitude += Double.parseDouble(sec) / 60.0 / 60.0;
latitude *= compass.equals("N") ? 1.0 : -1.0;
latitude *= compass.toUpperCase().equals("N") ? 1.0 : -1.0;
latitude = Math.round(latitude * 100000.0) / 100000.0;
return latitude;
} else {
_log.error("Latitude " + str + " does not match format DDMMSS[EW]");
throw new CoordinateConversionException("Latitude " + str + " does not match format DDMMSS[EW]");
throw new CoordinateConversionException("Latitude " + str + " does not match format DDMMSS[NS]");
}
}
......@@ -93,7 +93,7 @@ public class GeoUtils {
double longitude = Double.parseDouble(deg);
longitude += Double.parseDouble(min) / 60.0;
longitude += Double.parseDouble(sec) / 60.0 / 60.0;
longitude *= compass.equals("E") ? 1.0 : -1.0;
longitude *= compass.toUpperCase().equals("E") ? 1.0 : -1.0;
longitude = Math.round(longitude * 100000.0) / 100000.0;
return longitude;
} else {
......
......@@ -15,6 +15,7 @@
*/
package org.genesys2.anno.util;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import org.junit.Test;
......@@ -29,7 +30,7 @@ public class GeoUtilsTest {
assertTrue(GeoUtils.toDecimalLatitude("000000N") == 0.0);
assertTrue(GeoUtils.toDecimalLatitude("000000S") == -0.0);
assertTrue(GeoUtils.toDecimalLatitude("100000N") == 10.0);
assertThat(GeoUtils.toDecimalLatitude("100000N"), is(10.0));
assertTrue(GeoUtils.toDecimalLatitude("100---N") == 10.0);
assertTrue(GeoUtils.toDecimalLatitude("100000S") == -10.0);
assertTrue(GeoUtils.toDecimalLatitude("000001N") == 0.00028);
......@@ -37,7 +38,7 @@ public class GeoUtilsTest {
assertTrue(GeoUtils.toDecimalLatitude("000010N") == 0.00278);
assertTrue(GeoUtils.toDecimalLatitude("000010S") == -0.00278);
}
@Test
public void testLongitude() throws CoordinateConversionException {
assertTrue(GeoUtils.toDecimalLongitude(null) == null);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment