Search in sources :

Example 1 with BoundingBox

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

the class IntArrayScaleTriangulatedIrregularNetwork method getTriangleSpatialIndex.

public QuadTree<Triangle> getTriangleSpatialIndex() {
    if (this.triangleSpatialIndex == null) {
        final QuadTree<Triangle> index = new QuadTree<>(this.geometryFactory);
        forEachTriangle((x1, y1, z1, x2, y2, z2, x3, y3, z3) -> {
            final Triangle triangle = new TriangleDoubleXYZ(x1, y1, z1, x2, y2, z2, x3, y3, z3);
            final BoundingBox boundingBox = triangle.getBoundingBox();
            index.insertItem(boundingBox, triangle);
        });
        this.triangleSpatialIndex = index;
    }
    return this.triangleSpatialIndex;
}
Also used : IdObjectQuadTree(com.revolsys.geometry.index.quadtree.IdObjectQuadTree) QuadTree(com.revolsys.geometry.index.quadtree.QuadTree) BaseBoundingBox(com.revolsys.geometry.model.impl.BaseBoundingBox) BoundingBox(com.revolsys.geometry.model.BoundingBox) AbstractTriangle(com.revolsys.geometry.model.impl.AbstractTriangle) Triangle(com.revolsys.geometry.model.Triangle) TriangleDoubleXYZ(com.revolsys.geometry.model.impl.TriangleDoubleXYZ)

Example 2 with BoundingBox

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

the class TriangulatedIrregularNetwork method getTriangles.

default List<Triangle> getTriangles(final LineSegment segment) {
    final BoundingBox boundingBox = segment.getBoundingBox();
    final List<Triangle> triangles = new ArrayList<>();
    forEachTriangle(boundingBox, triangles::add);
    return triangles;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) Triangle(com.revolsys.geometry.model.Triangle) ArrayList(java.util.ArrayList)

Example 3 with BoundingBox

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

the class GriddedElevationModel method forEachPointFinite.

default void forEachPointFinite(final BoundingBox boundingBox, final Consumer<Point> action) {
    final GeometryFactory targetGeometryFactory = boundingBox.getGeometryFactory();
    final GeometryFactory geometryFactory = getGeometryFactory();
    final CoordinatesOperation projection = geometryFactory.getCoordinatesOperation(targetGeometryFactory);
    final BoundingBox convertexBoundingBox = boundingBox.convert(geometryFactory);
    final double gridCellSize = getGridCellSize();
    final double minY = getGridMinY();
    final double minX = getGridMinX();
    final int gridWidth = getGridWidth();
    final int gridHeight = getGridHeight();
    int startGridX = (int) Math.floor((convertexBoundingBox.getMinX() - minX) / gridCellSize);
    if (startGridX < 0) {
        startGridX = 0;
    }
    int endGridX = (int) Math.ceil((convertexBoundingBox.getMaxX() - minX) / gridCellSize);
    if (endGridX > gridWidth) {
        endGridX = gridWidth;
    }
    int startGridY = (int) Math.floor((convertexBoundingBox.getMinY() - minY) / gridCellSize);
    if (startGridY < 0) {
        startGridY = 0;
    }
    int endGridY = (int) Math.ceil((convertexBoundingBox.getMaxY() - minY) / gridCellSize);
    if (endGridY > gridHeight) {
        endGridY = gridHeight;
    }
    if (projection == null) {
        for (int gridY = startGridY; gridY < endGridY; gridY++) {
            final double y = minY + gridY * gridCellSize;
            for (int gridX = startGridX; gridX < endGridX; gridX++) {
                final double x = minX + gridX * gridCellSize;
                final double z = getElevationFast(gridX, gridY);
                if (Double.isFinite(z)) {
                    if (boundingBox.covers(x, y)) {
                        final Point point = targetGeometryFactory.point(x, y, z);
                        action.accept(point);
                    }
                }
            }
        }
    } else {
        final double[] coordinates = new double[2];
        for (int gridY = startGridY; gridY < endGridY; gridY++) {
            final double y = minY + gridY * gridCellSize;
            for (int gridX = startGridX; gridX < endGridX; gridX++) {
                final double x = minX + gridX * gridCellSize;
                final double z = getElevationFast(gridX, gridY);
                if (Double.isFinite(z)) {
                    coordinates[0] = x;
                    coordinates[1] = y;
                    projection.perform(2, coordinates, 2, coordinates);
                    final double targetX = coordinates[0];
                    final double targetY = coordinates[1];
                    if (boundingBox.covers(targetX, targetY)) {
                        final Point point = targetGeometryFactory.point(targetX, targetY, z);
                        action.accept(point);
                    }
                }
            }
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation) Point(com.revolsys.geometry.model.Point)

Example 4 with BoundingBox

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

the class IntArrayScaleGriddedElevationModel method resample.

@Override
public GriddedElevationModel resample(final int newGridCellSize) {
    final double gridCellSize = getGridCellSize();
    final double cellRatio = gridCellSize / newGridCellSize;
    final int step = (int) Math.round(1 / cellRatio);
    final int gridWidth = getGridWidth();
    final int gridHeight = getGridHeight();
    final int newGridWidth = (int) Math.round(gridWidth * cellRatio);
    final int newGridHeight = (int) Math.round(gridHeight * cellRatio);
    final GeometryFactory geometryFactory = getGeometryFactory();
    final int[] oldElevations = this.elevations;
    final int[] newElevations = new int[newGridWidth * newGridHeight];
    int newIndex = 0;
    for (int gridYMin = 0; gridYMin < gridHeight; gridYMin += step) {
        final int gridYMax = gridYMin + step;
        for (int gridXMin = 0; gridXMin < gridWidth; gridXMin += step) {
            final int gridXMax = gridXMin + step;
            int count = 0;
            long sum = 0;
            for (int gridY = gridYMin; gridY < gridYMax; gridY++) {
                for (int gridX = gridXMin; gridX < gridXMax; gridX++) {
                    final int elevation = oldElevations[gridY * gridWidth + gridX];
                    if (elevation != NULL_VALUE) {
                        count++;
                        sum += elevation;
                    }
                }
            }
            if (count > 0) {
                newElevations[newIndex] = (int) (sum / count);
            } else {
                newElevations[newIndex] = NULL_VALUE;
            }
            newIndex++;
        }
    }
    final BoundingBox boundingBox = getBoundingBox();
    final GriddedElevationModel newDem = new IntArrayScaleGriddedElevationModel(geometryFactory, boundingBox, newGridWidth, newGridHeight, newGridCellSize, newElevations);
    return newDem;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 5 with BoundingBox

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

the class EsriAsciiGriddedElevationModelWriter method write.

@Override
public void write(final GriddedElevationModel model) {
    final String nodataValue = DataTypes.toString(model.getProperty("nodataValue", "-9999"));
    if (this.resource == null) {
        throw new IllegalStateException("Writer is closed");
    } else {
        open(model);
        try {
            final BoundingBox boundingBox = model.getBoundingBox();
            final int width = model.getGridWidth();
            final int height = model.getGridHeight();
            final double cellSize = model.getGridCellSize();
            this.writer.write("NCOLS ");
            this.writer.write(Integers.toString(width));
            this.writer.write('\n');
            this.writer.write("NROWS ");
            this.writer.write(Integers.toString(height));
            this.writer.write('\n');
            this.writer.write("XLLCORNER ");
            this.writer.write(Doubles.toString(boundingBox.getMinX()));
            this.writer.write('\n');
            this.writer.write("YLLCORNER ");
            this.writer.write(Doubles.toString(boundingBox.getMinY()));
            this.writer.write('\n');
            this.writer.write("CELLSIZE ");
            this.writer.write(Doubles.toString(cellSize));
            this.writer.write('\n');
            this.writer.write("NODATA_VALUE ");
            this.writer.write(nodataValue);
            this.writer.write('\n');
            for (int gridY = height - 1; gridY >= 0; gridY--) {
                for (int gridX = 0; gridX < width; gridX++) {
                    final double elevation = model.getElevation(gridX, gridY);
                    if (Double.isFinite(elevation)) {
                        final String elevationString = Doubles.toString(elevation);
                        this.writer.write(elevationString);
                    } else {
                        this.writer.write(nodataValue);
                    }
                    this.writer.write(' ');
                }
                this.writer.write('\n');
            }
            this.writer.write('\n');
        } catch (final Throwable e) {
            throw Exceptions.wrap("Unable to write to: " + this.resource, e);
        } finally {
            close();
        }
    }
}
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