Search in sources :

Example 36 with BoundingBox

use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.

the class Gdal method loadSettings.

public static long loadSettings(final Dataset dataset, final Resource resource) {
    final Resource settingsFile = resource.newResourceAddExtension("rgobject");
    if (settingsFile.exists()) {
        try {
            final Map<String, Object> settings = Json.toMap(settingsFile);
            final String boundingBoxWkt = (String) settings.get("boundingBox");
            if (Property.hasValue(boundingBoxWkt)) {
                final BoundingBox boundingBox = BoundingBox.newBoundingBox(boundingBoxWkt);
                if (!boundingBox.isEmpty()) {
                    setSpatialReference(dataset, boundingBox.getGeometryFactory());
                    final double x = boundingBox.getMinX();
                    final double width = boundingBox.getWidth();
                    final int imageWidth = dataset.getRasterXSize();
                    final double y = boundingBox.getMaxY();
                    final double height = boundingBox.getHeight();
                    final int imageHeight = dataset.getRasterYSize();
                    final double[] transform = new double[] { x, width / imageWidth, 0, y, 0, -height / imageHeight };
                    dataset.SetGeoTransform(transform);
                }
            }
            return settingsFile.getLastModified();
        } catch (final Throwable e) {
            Logs.error(Gdal.class, "Unable to load:" + settingsFile, e);
            return -1;
        }
    } else {
        return -1;
    }
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) PathResource(com.revolsys.spring.resource.PathResource) Resource(com.revolsys.spring.resource.Resource)

Example 37 with BoundingBox

use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.

the class GdalImage method drawImage.

@Override
public void drawImage(final Graphics2D graphics, final BoundingBox viewBoundingBox, final int viewWidth, final int viewHeight, final boolean useTransform, final Object interpolationMethod) {
    try {
        final Dataset dataset = getDataset();
        final BoundingBox imageBoundingBox = getBoundingBox();
        final BoundingBox clipBoundingBox = viewBoundingBox.intersection(imageBoundingBox);
        final double scaleFactor = viewWidth / viewBoundingBox.getWidth();
        final double clipModelWidth = clipBoundingBox.getWidth();
        final int targetWidth = (int) Math.ceil(clipModelWidth * scaleFactor);
        final double clipModelHeight = clipBoundingBox.getHeight();
        final int targetHeight = (int) Math.ceil(clipModelHeight * scaleFactor);
        int bestOverviewIdx = -1;
        int srcWidth = getImageWidth();
        final double clipResolution = Math.abs(clipBoundingBox.getHeight() / targetHeight);
        final List<Dimension> overviewSizes = getOverviewSizes();
        for (int i = 0; i < overviewSizes.size(); i++) {
            final Dimension overviewSize = overviewSizes.get(i);
            final int width = overviewSize.width;
            final int height = overviewSize.height;
            if (0 != height && 0 != width) {
                final double overviewResolution = Math.abs(imageBoundingBox.getHeight() / height);
                if (overviewResolution <= clipResolution) {
                    bestOverviewIdx = i;
                    srcWidth = width;
                }
            }
        }
        final double scale = srcWidth / imageBoundingBox.getWidth();
        final int clipXoff = (int) Math.floor((clipBoundingBox.getMinX() - imageBoundingBox.getMinX()) * scale);
        final int clipYoff = (int) Math.floor((imageBoundingBox.getMaxY() - clipBoundingBox.getMaxY()) * scale);
        final int clipWidth = (int) Math.ceil(clipModelWidth * scale);
        final int clipHeight = (int) Math.ceil(clipModelHeight * scale);
        final BufferedImage bufferedImage = Gdal.getBufferedImage(dataset, bestOverviewIdx, clipXoff, clipYoff, clipWidth, clipHeight, targetWidth, targetHeight);
        super.drawRenderedImage(bufferedImage, clipBoundingBox, graphics, viewBoundingBox, viewWidth, useTransform, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    } catch (final Throwable e) {
        e.printStackTrace();
    }
}
Also used : Dataset(org.gdal.gdal.Dataset) BoundingBox(com.revolsys.geometry.model.BoundingBox) Dimension(java.awt.Dimension) BufferedImage(java.awt.image.BufferedImage)

Example 38 with BoundingBox

use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.

the class PointCloud method newGriddedElevationModel.

default GriddedElevationModel newGriddedElevationModel(final Map<String, ? extends Object> properties) {
    final TriangulatedIrregularNetwork tin = newTriangulatedIrregularNetwork();
    final BoundingBox boundingBox = getBoundingBox();
    final int minX = (int) Math.floor(boundingBox.getMinX());
    final int minY = (int) Math.floor(boundingBox.getMinY());
    final int maxX = (int) Math.ceil(boundingBox.getMaxX());
    final int maxY = (int) Math.ceil(boundingBox.getMaxY());
    final int width = maxX - minX;
    final int height = maxY - minY;
    final IntArrayScaleGriddedElevationModel elevationModel = new IntArrayScaleGriddedElevationModel(getGeometryFactory().convertAxisCountAndScales(3, 1000.0, 1000.0, 1000.0), minX, minY, width, height, 1);
    tin.forEachTriangle(elevationModel::setElevationsForTriangle);
    return null;
}
Also used : TriangulatedIrregularNetwork(com.revolsys.elevation.tin.TriangulatedIrregularNetwork) BoundingBox(com.revolsys.geometry.model.BoundingBox) IntArrayScaleGriddedElevationModel(com.revolsys.elevation.gridded.IntArrayScaleGriddedElevationModel) Point(com.revolsys.geometry.model.Point)

Example 39 with BoundingBox

use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method loadArea.

private static void loadArea() {
    try (ChannelReader reader = newChannelReader("area")) {
        while (true) {
            final int code = reader.getInt();
            final String name = reader.getStringUtf8ByteCount();
            final double minX = reader.getDouble();
            final double minY = reader.getDouble();
            final double maxX = reader.getDouble();
            final double maxY = reader.getDouble();
            final boolean deprecated = readBoolean(reader);
            final Authority authority = new EpsgAuthority(code);
            BoundingBox boundingBox;
            if (Double.isFinite(minX) || Double.isFinite(minX) || Double.isFinite(minX) || Double.isFinite(minX)) {
                boundingBox = new BoundingBoxDoubleXY(minX, minY, maxX, maxY);
            } else {
                boundingBox = BoundingBox.empty();
            }
            final Area area = new Area(name, boundingBox, authority, deprecated);
            AREA_BY_ID.put(code, area);
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            throw e;
        }
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) Authority(com.revolsys.geometry.cs.Authority) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY) NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) Area(com.revolsys.geometry.cs.Area) ChannelReader(com.revolsys.io.channels.ChannelReader) BoundingBox(com.revolsys.geometry.model.BoundingBox) EOFException(java.io.EOFException)

Example 40 with BoundingBox

use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.

the class RayCrossingCounter method locatePointInRing.

public static Location locatePointInRing(final LineString ring, final double x, final double y) {
    final BoundingBox boundingBox = ring.getBoundingBox();
    if (boundingBox.covers(x, y)) {
        final RayCrossingCounter counter = new RayCrossingCounter(x, y);
        ring.findSegment((x1, y1, x2, y2) -> {
            counter.countSegment(x2, y2, x1, y1);
            if (counter.isOnSegment()) {
                return counter.getLocation();
            }
            return null;
        });
        return counter.getLocation();
    } else {
        return Location.EXTERIOR;
    }
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox)

Aggregations

BoundingBox (com.revolsys.geometry.model.BoundingBox)307 Point (com.revolsys.geometry.model.Point)83 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)76 ArrayList (java.util.ArrayList)45 Geometry (com.revolsys.geometry.model.Geometry)41 LineString (com.revolsys.geometry.model.LineString)26 List (java.util.List)26 BoundingBoxDoubleXY (com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)19 Polygon (com.revolsys.geometry.model.Polygon)14 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)14 Project (com.revolsys.swing.map.layer.Project)14 CreateListVisitor (com.revolsys.visitor.CreateListVisitor)12 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)11 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)11 Edge (com.revolsys.geometry.graph.Edge)10 HashMap (java.util.HashMap)10 Record (com.revolsys.record.Record)9 Graphics2D (java.awt.Graphics2D)9 MapEx (com.revolsys.collection.map.MapEx)8 LinearRing (com.revolsys.geometry.model.LinearRing)8