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);
}
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);
}
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();
}
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);
}
}
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());
}
Aggregations