Search in sources :

Example 1 with Projector

use of com.github.davidmoten.grumpy.projection.Projector in project risky by amsa-code.

the class DriftingLayer method render.

@Override
public void render(Graphics2D g, WmsRequest request) {
    log.info("request=" + request);
    log.info("drawing " + queue.size() + " positions");
    final Projector projector = WmsUtil.getProjector(request);
    Position a = projector.toPosition(0, 0);
    Position b = projector.toPosition(request.getWidth(), request.getHeight());
    Rectangle r = Geometries.rectangle(a.getLon(), b.getLat(), b.getLon(), a.getLat());
    Optional<VesselPosition> last = Optional.empty();
    Optional<Point> lastPoint = Optional.empty();
    // Iterable<VesselPosition> positions = tree
    // .search(r)
    // .map(new Func1<Entry<VesselPosition,
    // com.github.davidmoten.rtree.geometry.Point>, VesselPosition>() {
    // 
    // @Override
    // public VesselPosition call(
    // Entry<VesselPosition, com.github.davidmoten.rtree.geometry.Point>
    // entry) {
    // return entry.value();
    // }
    // 
    // }).toBlocking().toIterable();
    ConcurrentLinkedQueue<VesselPosition> positions = queue;
    Point startPoint = null;
    for (VesselPosition p : positions) {
        // expecting positions to be in mmsi, time order
        Point point = projector.toPoint(p.lat(), p.lon());
        if (last.isPresent() && p.id().equals(last.get().id()) && p.data().isPresent() && !p.data().get().equals(p.time()) && isOkMovement(p, last.get())) {
            // join the last position with this one with a line
            g.setColor(Color.gray);
            g.drawLine(lastPoint.get().x, lastPoint.get().y, point.x, point.y);
        }
        if (p.data().get().equals(p.time()) || (last.isPresent() && !isOkMovement(p, last.get()))) {
            g.setColor(Color.red);
            g.drawRect(point.x, point.y, 1, 1);
            startPoint = point;
        } else if (startPoint != null) {
            // draw intermediate point
            g.setColor(Color.darkGray);
            g.drawRect(point.x, point.y, 1, 1);
            // redraw startPoint so that a slightly moving drift doesn't
            // overdraw the startPoint with the color of an intermediate
            // point
            g.setColor(Color.red);
            g.drawRect(startPoint.x, startPoint.y, 1, 1);
        }
        last = Optional.of(p);
        lastPoint = Optional.of(point);
    }
    log.info("drawn");
}
Also used : Projector(com.github.davidmoten.grumpy.projection.Projector) VesselPosition(au.gov.amsa.navigation.VesselPosition) Position(com.github.davidmoten.grumpy.core.Position) Rectangle(com.github.davidmoten.rtree.geometry.Rectangle) Point(java.awt.Point) VesselPosition(au.gov.amsa.navigation.VesselPosition)

Example 2 with Projector

use of com.github.davidmoten.grumpy.projection.Projector in project risky by amsa-code.

the class DriftingLayer method getInfo.

@Override
public String getInfo(Date time, WmsRequest request, final Point point, String mimeType) {
    final int HOTSPOT_SIZE = 5;
    final Projector projector = WmsUtil.getProjector(request);
    final StringBuilder response = new StringBuilder();
    response.append("<html>");
    Observable.from(queue).filter(new Func1<VesselPosition, Boolean>() {

        @Override
        public Boolean call(VesselPosition p) {
            Point pt = projector.toPoint(p.lat(), p.lon());
            return Math.abs(point.x - pt.x) <= HOTSPOT_SIZE && Math.abs(point.y - pt.y) <= HOTSPOT_SIZE;
        }
    }).doOnNext(new Action1<VesselPosition>() {

        @Override
        public void call(VesselPosition p) {
            response.append("<p>");
            response.append("<a href=\"https://www.fleetmon.com/en/vessels?s=" + p.id().uniqueId() + "\">mmsi=" + p.id().uniqueId() + "</a>, time=" + new Date(p.time()));
            if (p.shipType().isPresent()) {
                response.append(", ");
                response.append(ShipTypeDecoder.getShipType(p.shipType().get()));
            }
            response.append("</p>");
            response.append("<p>");
            response.append(p.toString());
            response.append("</p>");
        }
    }).subscribe();
    response.append("</html>");
    return response.toString();
}
Also used : Projector(com.github.davidmoten.grumpy.projection.Projector) Action1(rx.functions.Action1) Point(java.awt.Point) VesselPosition(au.gov.amsa.navigation.VesselPosition) Point(java.awt.Point) Date(java.util.Date)

Aggregations

VesselPosition (au.gov.amsa.navigation.VesselPosition)2 Projector (com.github.davidmoten.grumpy.projection.Projector)2 Point (java.awt.Point)2 Position (com.github.davidmoten.grumpy.core.Position)1 Rectangle (com.github.davidmoten.rtree.geometry.Rectangle)1 Date (java.util.Date)1 Action1 (rx.functions.Action1)1