Search in sources :

Example 1 with Eez

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");
}
Also used : Arrays(java.util.Arrays) Downsample(au.gov.amsa.risky.format.Downsample) Date(java.util.Date) SegmentOptions(au.gov.amsa.geo.model.SegmentOptions) OperatorEffectiveSpeedChecker(au.gov.amsa.geo.distance.OperatorEffectiveSpeedChecker) SimpleDateFormat(java.text.SimpleDateFormat) ShapefileUtil(au.gov.amsa.geo.ShapefileUtil) BufferedOutputStream(java.io.BufferedOutputStream) TimedPosition(au.gov.amsa.geo.TimedPosition) Observable(rx.Observable) Logger(org.apache.log4j.Logger) BinaryFixes(au.gov.amsa.risky.format.BinaryFixes) Fix(au.gov.amsa.risky.format.Fix) Schedulers(rx.schedulers.Schedulers) Eez(au.gov.amsa.geo.Eez) ParseException(java.text.ParseException) PrintStream(java.io.PrintStream) TimeZone(java.util.TimeZone) DecimalFormat(java.text.DecimalFormat) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) BinaryFixesFormat(au.gov.amsa.risky.format.BinaryFixesFormat) TimeUnit(java.util.concurrent.TimeUnit) Position(com.github.davidmoten.grumpy.core.Position) List(java.util.List) GroupedObservable(rx.observables.GroupedObservable) Shapefile(au.gov.amsa.gt.Shapefile) MmsiValidator2(au.gov.amsa.util.identity.MmsiValidator2) PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) Shapefile(au.gov.amsa.gt.Shapefile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

Eez (au.gov.amsa.geo.Eez)1 ShapefileUtil (au.gov.amsa.geo.ShapefileUtil)1 TimedPosition (au.gov.amsa.geo.TimedPosition)1 OperatorEffectiveSpeedChecker (au.gov.amsa.geo.distance.OperatorEffectiveSpeedChecker)1 SegmentOptions (au.gov.amsa.geo.model.SegmentOptions)1 Shapefile (au.gov.amsa.gt.Shapefile)1 BinaryFixes (au.gov.amsa.risky.format.BinaryFixes)1 BinaryFixesFormat (au.gov.amsa.risky.format.BinaryFixesFormat)1 Downsample (au.gov.amsa.risky.format.Downsample)1 Fix (au.gov.amsa.risky.format.Fix)1 MmsiValidator2 (au.gov.amsa.util.identity.MmsiValidator2)1 Position (com.github.davidmoten.grumpy.core.Position)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 DecimalFormat (java.text.DecimalFormat)1 ParseException (java.text.ParseException)1