Commit 0347b867 authored by Matija Obreza's avatar Matija Obreza
Browse files

First Longitude, then Latitude

parent 91299346
......@@ -24,9 +24,9 @@ public class CountryCLI {
Pattern pattern = Pattern.compile("^(\\w{3})[\\s,]+(\\-?\\d*\\.?\\d*)[\\s,]+(\\-?\\d*\\.?\\d*)$");
System.err.println("Expects input rows in format: Latitude\tLongitude");
System.err.println("Expects input rows in format: Longitude\tLatitude");
System.err.println("Enter 'q' to quit.");
System.out.println("OrigCty\tLatitude\tLongitude\tResult");
System.out.println("OrigCty\tLongitude\tLatitude\tResult");
String input = null;
do {
input = br.readLine();
......@@ -37,10 +37,10 @@ public class CountryCLI {
Matcher matcher = pattern.matcher(input);
if (matcher.find()) {
String origCty = matcher.group(1).trim();
float latitude = Float.parseFloat(matcher.group(2).replace(",", "."));
float longitude = Float.parseFloat(matcher.group(3).replace(",", "."));
float longitude = Float.parseFloat(matcher.group(2).replace(",", "."));
float latitude = Float.parseFloat(matcher.group(3).replace(",", "."));
System.out.println(latitude + ", " + longitude + ", "
System.out.println(longitude + ", " + latitude + ", "
+ countryOfOriginService.getCountries(longitude, latitude, origCty, ALLOWED_DISTANCE_MARGIN));
} else {
......@@ -53,9 +53,9 @@ public class CountryCLI {
}
private static void doCSV(String[] arg) throws IOException {
int columnOrigCty = 5;
int columnLatitude = 4;
int columnLongitude = 3;
int columnLatitude = 4;
int columnOrigCty = 5;
CSVWriter writer = new CSVWriter(new OutputStreamWriter(System.out), ',', '"', '\\', "\n");
CSVReader reader = new CSVReader(new InputStreamReader(System.in), ',', '"', '\\', 0, false);
......
......@@ -26,9 +26,9 @@ public class LandOrSeaCLI {
Pattern pattern = Pattern.compile("^(\\-?\\d*\\.?\\d*)[ \\t,]+(\\-?\\d*\\.?\\d*)$");
System.err.println("Expects input rows in format: Latitude\tLongitude");
System.err.println("Expects input rows in format: Longitude\tLatitude");
System.err.println("Enter 'q' to quit.");
System.out.println("Latitude\tLongitude\tResult");
System.out.println("Longitude\tLatitude\tResult");
String input = null;
do {
input = br.readLine();
......@@ -38,10 +38,10 @@ public class LandOrSeaCLI {
Matcher matcher = pattern.matcher(input);
if (matcher.find()) {
float latitude = Float.parseFloat(matcher.group(1).replace(",", "."));
float longitude = Float.parseFloat(matcher.group(2).replace(",", "."));
float longitude = Float.parseFloat(matcher.group(1).replace(",", "."));
float latitude = Float.parseFloat(matcher.group(2).replace(",", "."));
System.out.println(latitude + ", " + longitude + ", "
System.out.println(longitude + ", " + latitude + ", "
+ landOrSeaService.classifyLocation(longitude, latitude, ALLOWED_DISTANCE_MARGIN));
} else {
......@@ -54,8 +54,8 @@ public class LandOrSeaCLI {
}
private static void doCSV(String[] arg) throws IOException {
int columnLatitude = 4;
int columnLongitude = 3;
int columnLatitude = 4;
CSVWriter writer = new CSVWriter(new OutputStreamWriter(System.out), ',', '"', '\\', "\n");
CSVReader reader = new CSVReader(new InputStreamReader(System.in), ',', '"', '\\', 0, false);
......@@ -75,8 +75,8 @@ public class LandOrSeaCLI {
String[] writeLine = Arrays.copyOf(nextLine, nextLine.length + 1);
try {
float latitude = Float.parseFloat(nextLine[columnLatitude].trim());
float longitude = Float.parseFloat(nextLine[columnLongitude].trim());
float latitude = Float.parseFloat(nextLine[columnLatitude].trim());
try {
writeLine[writeLine.length - 1] = landOrSeaService.classifyLocation(longitude, latitude,
......
......@@ -63,21 +63,20 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
.build(new CacheLoader<LonLatCacheKey, String>() {
public String load(LonLatCacheKey key) throws Exception {
// System.err.println("Loading");
return _classifyLocation(key.getLongitude(), key.getLatitude(),
key.getAllowedDistanceMargin());
return _classifyLocation(key.getLongitude(), key.getLatitude(), key.getAllowedDistanceMargin());
}
});
}
public String classifyLocation(float longitude, float latitude, int allowedDistanceFromLand) throws Exception {
public String classifyLocation(float longitude, float latitude, int allowedDistanceMargin) throws Exception {
try {
return classifierCache.get(new LonLatCacheKey(longitude, latitude, allowedDistanceFromLand));
return classifierCache.get(new LonLatCacheKey(longitude, latitude, allowedDistanceMargin));
} catch (ExecutionException e) {
throw new Exception(e.getCause());
}
}
private String _classifyLocation(float longitude, float latitude, int allowedDistanceFromLand) throws Exception {
private String _classifyLocation(float longitude, float latitude, int allowedDistanceMargin) throws Exception {
Point point = geometryFactory.createPoint(new Coordinate(longitude, latitude));
......@@ -88,7 +87,7 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
// Create a buffer and check for Land
Filter filterBuffered = ff.intersects(ff.property("the_geom"),
ff.literal(ShapefileUtils.getPointBuffer(point, allowedDistanceFromLand)));
ff.literal(ShapefileUtils.getPointBuffer(point, allowedDistanceMargin)));
if (sourceLand.getFeatures(filterBuffered).size() > 0) {
return "Coastal";
......@@ -107,8 +106,8 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
return "Land";
// }
} else {
throw new Exception("Can't figure out the result for " + longitude + "," + latitude + " with distance="
+ allowedDistanceFromLand);
throw new Exception("Can't figure out the result for (" + longitude + ", " + latitude
+ ") with distance=" + allowedDistanceMargin);
}
} catch (Exception e) {
......
......@@ -58,14 +58,14 @@ public class LonLatCacheKey implements Serializable {
return true;
}
public float getLatitude() {
return latitude;
}
public float getLongitude() {
return longitude;
}
public float getLatitude() {
return latitude;
}
public int getAllowedDistanceMargin() {
return allowedDistanceMargin;
}
......
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