Search in sources :

Example 1 with Bounds

use of au.gov.amsa.geo.model.Bounds in project risky by amsa-code.

the class DistanceTravelledCalculatorTest method manualTestCase.

@Test
public void manualTestCase() {
    Position a = new Position(-30.8, 140.2);
    Position b = new Position(-31.7, 142.6);
    System.out.println(toPos(a).getBearingDegrees(toPos(b)));
    Options options = Options.builder().originLat(0).originLon(0).cellSizeDegrees(1.0).bounds(new Bounds(0, 100, -60, 175)).build();
    Observable<CellAndDistance> list = DistanceTravelledCalculator.getCellDistances(a, b, options);
    System.out.println("totalBearing=" + toPos(a).getBearingDegrees(toPos(b)));
    LongitudePair gcIntercept = toPos(a).getLongitudeOnGreatCircle(toPos(b), -31.0);
    System.out.println("gc long=" + gcIntercept);
    au.gov.amsa.util.navigation.Position nextPos = au.gov.amsa.util.navigation.Position.create(-31.0, gcIntercept.getLon2());
    System.out.println("bearingToFinal=" + nextPos.getBearingDegrees(toPos(b)));
    System.out.println("nextLat = " + nextPos.getLatitudeOnGreatCircle(toPos(b), 141.0));
    double totalNm = 0;
    for (CellAndDistance value : list.toList().toBlocking().single()) {
        System.out.println(value);
        totalNm += value.getDistanceNm();
    }
    assertEquals(toPos(a).getDistanceToKm(toPos(b)) / 1.852, totalNm, 0.2);
}
Also used : Options(au.gov.amsa.geo.model.Options) LongitudePair(au.gov.amsa.util.navigation.Position.LongitudePair) Position(au.gov.amsa.geo.model.Position) Bounds(au.gov.amsa.geo.model.Bounds) Test(org.junit.Test)

Example 2 with Bounds

use of au.gov.amsa.geo.model.Bounds in project risky by amsa-code.

the class DistanceTravelledCalculator method partition.

/**
 * Returns a sequence of {@link Options} that are same as the source apart
 * from the {@link Bounds} which are partitioned according to horizontal and
 * vertical parameters. For map-reduce purposes we need to be able to
 * partition the bounds of Options. Passing horizontal=1 and vertical=1 will
 * return one item only being a copy of the source {@link Options}.
 *
 * @param options
 * @param horizontal
 *            number of regions (with longitude)
 * @param vertical
 *            number of regions (with latitude)
 * @return
 */
public static Observable<Options> partition(final Options options, final int horizontal, final int vertical) {
    List<Options> list = new ArrayList<>();
    Bounds bounds = options.getBounds();
    double h = bounds.getWidthDegrees() / horizontal;
    double v = bounds.getHeightDegrees() / vertical;
    for (int i = 0; i < horizontal; i++) {
        for (int j = 0; j < vertical; j++) {
            double lat = bounds.getTopLeftLat() - j * v;
            double lon = bounds.getTopLeftLon() + i * h;
            Bounds b = new Bounds(lat, lon, lat - v, lon + h);
            list.add(options.buildFrom().bounds(b).filterBounds(b.expand(7, 7)).build());
        }
    }
    return Observable.from(list);
}
Also used : SegmentOptions(au.gov.amsa.geo.model.SegmentOptions) Options(au.gov.amsa.geo.model.Options) Bounds(au.gov.amsa.geo.model.Bounds) ArrayList(java.util.ArrayList)

Example 3 with Bounds

use of au.gov.amsa.geo.model.Bounds in project risky by amsa-code.

the class OperatorCellValuesToBytes method toBytes.

private static byte[] toBytes(Options options) {
    ByteBuffer bb = ByteBuffer.allocate(40);
    Bounds b = options.getBounds();
    bb.putDouble(options.getCellSizeDegreesAsDouble());
    bb.putDouble(b.getTopLeftLat());
    bb.putDouble(b.getTopLeftLon());
    bb.putDouble(b.getBottomRightLat());
    bb.putDouble(b.getBottomRightLon());
    return bb.array();
}
Also used : Bounds(au.gov.amsa.geo.model.Bounds) ByteBuffer(java.nio.ByteBuffer)

Example 4 with Bounds

use of au.gov.amsa.geo.model.Bounds in project risky by amsa-code.

the class DistanceTravelledCalculator method saveCalculationResultAsText.

public static void saveCalculationResultAsText(Options options, CalculationResult calculationResult, String filename) {
    try {
        final PrintWriter out = new PrintWriter(filename);
        Bounds b = options.getBounds();
        out.println("#originLat, originLon, cellSizeDegrees, topLefLat, topLeftLon, bottomRightLat, bottomRightLon");
        out.format("%s\t%s\t%s\t%s\t%s\t%s\t%s\n", options.getOriginLat(), options.getOriginLon(), options.getCellSizeDegrees(), b.getTopLeftLat(), b.getTopLeftLon(), b.getBottomRightLat(), b.getBottomRightLon());
        out.println("#centreLat, centreLon, distanceNmPerNm2");
        calculationResult.getCells().subscribe(new Observer<CellValue>() {

            @Override
            public void onCompleted() {
                out.close();
            }

            @Override
            public void onError(Throwable e) {
                out.close();
            }

            @Override
            public void onNext(CellValue cell) {
                out.format("%s\t%s\t%s\n", cell.getCentreLat(), cell.getCentreLon(), cell.getValue());
            }
        });
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : Bounds(au.gov.amsa.geo.model.Bounds) FileNotFoundException(java.io.FileNotFoundException) CellValue(au.gov.amsa.geo.model.CellValue) PrintWriter(java.io.PrintWriter)

Example 5 with Bounds

use of au.gov.amsa.geo.model.Bounds in project risky by amsa-code.

the class DistanceTravelledCalculatorTest method testGetCellDistances.

@Test
public void testGetCellDistances() {
    Options options = Options.builder().originLat(0).originLon(0).cellSizeDegrees(0.1).bounds(new Bounds(0, 100, -60, 175)).build();
    Observable<CellAndDistance> list = DistanceTravelledCalculator.getCellDistances(f1, f3, options);
    System.out.println(list.toList().toBlocking().single());
}
Also used : Options(au.gov.amsa.geo.model.Options) Bounds(au.gov.amsa.geo.model.Bounds) Test(org.junit.Test)

Aggregations

Bounds (au.gov.amsa.geo.model.Bounds)7 Options (au.gov.amsa.geo.model.Options)4 Test (org.junit.Test)4 CellValue (au.gov.amsa.geo.model.CellValue)1 Position (au.gov.amsa.geo.model.Position)1 SegmentOptions (au.gov.amsa.geo.model.SegmentOptions)1 LongitudePair (au.gov.amsa.util.navigation.Position.LongitudePair)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1