use of au.gov.amsa.geo.Eez in project risky by amsa-code.
the class DistanceTravelledInEezMain method main.
public static void main(String[] args) throws FileNotFoundException, IOException {
System.out.println("running");
File tracks = new File("/home/dxm/combinedSortedTracks");
long t = System.currentTimeMillis();
List<File> files = Arrays.asList(tracks.listFiles());
files.sort((a, b) -> a.getName().compareTo(b.getName()));
try (PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream("target/output.csv")))) {
out.println(Vessel.headings());
//
Observable.from(//
files).filter(//
x -> x.getName().endsWith(".track.gz")).filter(//
x -> x.getName().startsWith("2017")).flatMap(file -> {
log.info(file);
// Note that the Shapefile objects are not thread-safe so we make new one for
// each file to enable parallel processing
// used for intersections with eez boundary
Shapefile eezLine = Eez.loadEezLine();
// used for contains tests
Shapefile eezPolygon = Eez.loadEezPolygon();
long startTime = Util.getStartTime(file);
long endTime = startTime + TimeUnit.HOURS.toMillis(24);
return //
BinaryFixes.from(file, true, //
BinaryFixesFormat.WITH_MMSI).subscribeOn(//
Schedulers.computation()).filter(//
f -> MmsiValidator2.INSTANCE.isValid(f.mmsi())).filter(//
f -> f.time() >= startTime && f.time() <= endTime).groupBy(//
fix -> fix.mmsi()).flatMap(o -> calculateDistance(file, eezLine, eezPolygon, o));
}, //
Runtime.getRuntime().availableProcessors()).filter(//
x -> x.state.fix != null).toBlocking().forEach(x -> out.println(x.line()));
}
System.out.println((System.currentTimeMillis() - t) + "ms");
}
Aggregations