-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemoveStationaryMapper.java
39 lines (28 loc) · 1.14 KB
/
RemoveStationaryMapper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package clean;
import gensegments.FlightSegment;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.log4j.Logger;
import java.io.IOException;
public class RemoveStationaryMapper
extends Mapper<Text, FlightSegment, Text, Text> {
private final Text outValue = new Text();
@Override
public void map(Text key, FlightSegment value, Context context)
throws IOException, InterruptedException {
String line = value.toString();
String[] coords = line.split(",");
double lat1 = Double.parseDouble(coords[0]);
double lon1 = Double.parseDouble(coords[1]);
double lat2 = Double.parseDouble(coords[2]);
double lon2 = Double.parseDouble(coords[3]);
// calculate distance between two points (distance formula)
double distance = Math.sqrt(Math.pow(lat1 - lat2, 2) + Math.pow(lon1 - lon2, 2));
if (lat1 == lat2 && lon1 == lon2) {
// start point is the same as end point, so don't write to output
return;
}
outValue.set(line + "\t" + distance);
context.write(key, outValue);
}
}