use of au.gov.amsa.geo.model.Position 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.Position in project risky by amsa-code.
the class OperatorSumCellValues method call.
// private final AtomicLong count = new AtomicLong();
@Override
public Subscriber<? super CellValue> call(final Subscriber<? super CellValue> child) {
Subscriber<CellValue> parent = Subscribers.from(new Observer<CellValue>() {
@Override
public void onCompleted() {
// MapDb.INSTANCE.getDb().commit();
try {
log.info("starting to emit map values");
synchronized (map) {
for (Entry<Position, Double> entry : map.entrySet()) {
CellValue cv = new CellValue(entry.getKey().lat(), entry.getKey().lon(), entry.getValue().doubleValue());
child.onNext(cv);
}
}
child.onCompleted();
} catch (Throwable t) {
onError(t);
}
}
@Override
public void onError(Throwable e) {
child.onError(e);
}
@Override
public void onNext(CellValue cv) {
Position position = new Position((float) cv.getCentreLat(), (float) cv.getCentreLon());
Double val = map.putIfAbsent(position, cv.getValue());
if (val != null)
map.put(position, val + cv.getValue());
}
});
child.add(parent);
return parent;
}
use of au.gov.amsa.geo.model.Position in project risky by amsa-code.
the class Renderer method paintMap.
public static void paintMap(final Graphics2D g, Bounds b, final double cellSizeDegrees, double numberStandardDeviationsForHighValue, final int w, final int h, Observable<CellValue> cells, final boolean addLegend, final Func1<Position, Point> locator) {
final Statistics metrics = getStatistics(cells);
final double maxNmForColour = metrics.mean + numberStandardDeviationsForHighValue * metrics.sd;
final double minSaturation = 0.05;
cells.observeOn(Schedulers.immediate()).subscribeOn(Schedulers.immediate()).doOnNext(new Action1<CellValue>() {
@Override
public void call(CellValue cell) {
double topLeftLat = cell.getCentreLat() + cellSizeDegrees / 2;
double topLeftLon = cell.getCentreLon() - cellSizeDegrees / 2;
double bottomRightLat = cell.getCentreLat() - cellSizeDegrees / 2;
double bottomRightLon = cell.getCentreLon() + cellSizeDegrees / 2;
Point topLeft = locator.call(new Position(topLeftLat, topLeftLon));
Point bottomRight = locator.call(new Position(bottomRightLat, bottomRightLon));
double d = cell.getValue();
double prop = Math.min(d, maxNmForColour) / maxNmForColour;
Color color = toColor(minSaturation, prop);
g.setColor(color);
g.fillRect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
}
}).count().toBlocking().single();
if (addLegend)
paintLegend(g, cellSizeDegrees, metrics, maxNmForColour, minSaturation, w, h);
}
use of au.gov.amsa.geo.model.Position in project risky by amsa-code.
the class Renderer method epsg4326Locator.
private static Func1<Position, Point> epsg4326Locator(Bounds b, int w, int h) {
ProjectorBounds projectorBounds = new ProjectorBounds(FeatureUtil.EPSG_4326, b.getTopLeftLon(), b.getBottomRightLat(), b.getBottomRightLon(), b.getTopLeftLat());
ProjectorTarget projectorTarget = new ProjectorTarget(w, h);
final Projector projector = new Projector(projectorBounds, projectorTarget);
return new Func1<Position, Point>() {
@Override
public Point call(Position p) {
return projector.toPoint(p.lat(), p.lon());
}
};
}
use of au.gov.amsa.geo.model.Position in project risky by amsa-code.
the class FeatureUtil method convertToLatLon.
public static Position convertToLatLon(double x, double y, String srsName) {
GeometryFactory geometryFactory = new GeometryFactory();
Coordinate coordinate = new Coordinate(x, y);
Point point = geometryFactory.createPoint(coordinate);
try {
if (!srsName.equals(EPSG_4326)) {
MathTransform transform = CRS.findMathTransform(getCrs(EPSG_4326), getCrs(srsName));
point = (Point) JTS.transform(point, transform.inverse());
}
return new Position(point.getY(), point.getX());
} catch (NoSuchAuthorityCodeException e) {
throw new RuntimeException(e);
} catch (FactoryException e) {
throw new RuntimeException(e);
} catch (MismatchedDimensionException e) {
throw new RuntimeException(e);
} catch (TransformException e) {
throw new RuntimeException(e);
}
}
Aggregations