Search in sources :

Example 1 with Vector

use of org.la4j.Vector in project ddf by codice.

the class OverlayMetacardTransformer method calculateBoundingBox.

public static List<Vector> calculateBoundingBox(List<Vector> boundary) {
    double maxLon = Collections.max(boundary, Comparator.comparing(v -> v.get(0))).get(0);
    double minLon = Collections.min(boundary, Comparator.comparing(v -> v.get(0))).get(0);
    double maxLat = Collections.max(boundary, Comparator.comparing(v -> v.get(1))).get(1);
    double minLat = Collections.min(boundary, Comparator.comparing(v -> v.get(1))).get(1);
    List<Vector> boundingBox = new ArrayList<>();
    boundingBox.add(new BasicVector(new double[] { minLon, maxLat }));
    boundingBox.add(new BasicVector(new double[] { maxLon, minLat }));
    return boundingBox;
}
Also used : ArrayList(java.util.ArrayList) BasicVector(org.la4j.vector.dense.BasicVector) Vector(org.la4j.Vector) BasicVector(org.la4j.vector.dense.BasicVector)

Example 2 with Vector

use of org.la4j.Vector in project ddf by codice.

the class OverlayMetacardTransformer method overlay.

private BinaryContent overlay(Metacard metacard, Map<String, Serializable> arguments) throws CatalogTransformerException {
    final Optional<BufferedImage> bufferedImageOptional = imageSupplier.apply(metacard, arguments);
    final BufferedImage image = bufferedImageOptional.orElseThrow(() -> new CatalogTransformerException("Did not receive an image from the image supplier."));
    List<Vector> boundary = parseBoundary(metacard.getLocation());
    BufferedImage tile = createTileFromImageAndBoundary(image, boundary);
    return createBinaryContent(tile);
}
Also used : CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Vector(org.la4j.Vector) BasicVector(org.la4j.vector.dense.BasicVector) BufferedImage(java.awt.image.BufferedImage)

Example 3 with Vector

use of org.la4j.Vector in project ddf by codice.

the class OverlayMetacardTransformer method createTileFromImageAndBoundary.

private BufferedImage createTileFromImageAndBoundary(BufferedImage image, List<Vector> boundary) {
    /*
         * We transform the image by moving the corners and applying
         * transparency so that it looks right when laid down as a north-up
         * rectangular tile.
         */
    // Scaling by latitude so our x and y axes have roughly equal units.
    double lat = boundary.get(0).get(1);
    boundary.replaceAll(v -> scaleByLatitude(v, lat));
    // We are putting the image into a north-up rectangle, so we need
    // to get the minimum rectangle surrounding the boundary.
    List<Vector> boundingBox = calculateBoundingBox(boundary);
    Vector origin = boundingBox.get(0).copy();
    boundary.replaceAll(v -> v.subtract(origin));
    boundingBox.replaceAll(v -> v.subtract(origin));
    // The image may be stretched in weird ways, but we do our best to preserve
    // the resolution by scaling by the width of the image when going from lon/lat
    // to pixel space.
    double scaleFactor = calculateScaleFactor(boundary, image.getWidth());
    boundary.replaceAll(v -> v.multiply(scaleFactor));
    boundingBox.replaceAll(v -> v.multiply(scaleFactor));
    return createImage(image, boundary, (int) boundingBox.get(1).get(0), (int) -boundingBox.get(1).get(1));
}
Also used : Vector(org.la4j.Vector) BasicVector(org.la4j.vector.dense.BasicVector)

Example 4 with Vector

use of org.la4j.Vector in project ddf by codice.

the class OverlayMetacardTransformer method parseBoundary.

private List<Vector> parseBoundary(String location) throws CatalogTransformerException {
    final Geometry geometry = parseGeometry(location);
    if (!canHandleGeometry(geometry)) {
        throw new CatalogTransformerException("The Image boundary is not a rectangle");
    }
    final Coordinate[] coordinates = geometry.getCoordinates();
    List<Vector> boundary = new ArrayList<>();
    // Using indices rather than for-each because the first coordinate is duplicated.
    for (int i = 0; i < 4; i++) {
        boundary.add(new BasicVector(new double[] { coordinates[i].x, coordinates[i].y }));
    }
    return boundary;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryUtils.parseGeometry(ddf.catalog.transformer.GeometryUtils.parseGeometry) GeometryUtils.canHandleGeometry(ddf.catalog.transformer.GeometryUtils.canHandleGeometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) BasicVector(org.la4j.vector.dense.BasicVector) Vector(org.la4j.Vector) BasicVector(org.la4j.vector.dense.BasicVector)

Aggregations

Vector (org.la4j.Vector)4 BasicVector (org.la4j.vector.dense.BasicVector)4 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)2 ArrayList (java.util.ArrayList)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 GeometryUtils.canHandleGeometry (ddf.catalog.transformer.GeometryUtils.canHandleGeometry)1 GeometryUtils.parseGeometry (ddf.catalog.transformer.GeometryUtils.parseGeometry)1 BufferedImage (java.awt.image.BufferedImage)1