Search in sources :

Example 1 with Position

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);
}
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 Position

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;
}
Also used : Entry(java.util.Map.Entry) Position(au.gov.amsa.geo.model.Position) CellValue(au.gov.amsa.geo.model.CellValue)

Example 3 with Position

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);
}
Also used : Action1(rx.functions.Action1) Position(au.gov.amsa.geo.model.Position) Color(java.awt.Color) CellValue(au.gov.amsa.geo.model.CellValue) Point(java.awt.Point)

Example 4 with Position

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());
        }
    };
}
Also used : Projector(au.gov.amsa.geo.projection.Projector) ProjectorBounds(au.gov.amsa.geo.projection.ProjectorBounds) Position(au.gov.amsa.geo.model.Position) Func1(rx.functions.Func1) ProjectorTarget(au.gov.amsa.geo.projection.ProjectorTarget)

Example 5 with Position

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);
    }
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) MathTransform(org.opengis.referencing.operation.MathTransform) Coordinate(org.locationtech.jts.geom.Coordinate) Position(au.gov.amsa.geo.model.Position) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) Point(org.locationtech.jts.geom.Point) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException)

Aggregations

Position (au.gov.amsa.geo.model.Position)5 CellValue (au.gov.amsa.geo.model.CellValue)2 Bounds (au.gov.amsa.geo.model.Bounds)1 Options (au.gov.amsa.geo.model.Options)1 Projector (au.gov.amsa.geo.projection.Projector)1 ProjectorBounds (au.gov.amsa.geo.projection.ProjectorBounds)1 ProjectorTarget (au.gov.amsa.geo.projection.ProjectorTarget)1 LongitudePair (au.gov.amsa.util.navigation.Position.LongitudePair)1 Color (java.awt.Color)1 Point (java.awt.Point)1 Entry (java.util.Map.Entry)1 Test (org.junit.Test)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)1 Point (org.locationtech.jts.geom.Point)1 MismatchedDimensionException (org.opengis.geometry.MismatchedDimensionException)1 FactoryException (org.opengis.referencing.FactoryException)1 NoSuchAuthorityCodeException (org.opengis.referencing.NoSuchAuthorityCodeException)1 MathTransform (org.opengis.referencing.operation.MathTransform)1 TransformException (org.opengis.referencing.operation.TransformException)1