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