Search in sources :

Example 1 with Point

use of com.revolsys.geometry.model.Point 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 2 with Point

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

the class GriddedElevationModel method setElevationsNullFast.

default void setElevationsNullFast(final Iterable<? extends Point> points) {
    for (final Point point : points) {
        final double x = point.getX();
        final double y = point.getY();
        final int gridX = getGridCellX(x);
        final int gridY = getGridCellY(y);
        setElevationNull(gridX, gridY);
    }
}
Also used : Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 3 with Point

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

the class EsriAsciiGriddedElevationModelReader method getNext.

@Override
protected Point getNext() throws NoSuchElementException {
    try {
        while (this.gridY >= 0) {
            while (this.gridX < this.width) {
                if (this.elevation != this.noDataValue) {
                    final Point point = this.geometryFactory.point(this.x + this.gridX * this.gridCellSize, this.y + this.gridY * this.gridCellSize, this.elevation);
                    this.elevation = Readers.readDouble(this.reader);
                    this.gridX++;
                    return point;
                } else {
                    this.elevation = Readers.readDouble(this.reader);
                    this.gridX++;
                }
            }
            this.gridX = 0;
            this.gridY--;
        }
    } catch (final Exception e) {
        throw Exceptions.wrap("Error reading: " + this.resource, e);
    }
    throw new NoSuchElementException();
}
Also used : Point(com.revolsys.geometry.model.Point) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with Point

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

the class QuadEdgeSubdivision method fetchTriangleToVisit.

/**
 * Stores the edges for a visited triangle. Also pushes sym (neighbour) edges
 * on stack to visit later.
 *
 * @param edge
 * @param edgeStack
 * @return the visited triangle edges
 * or null if the triangle should not be visited (for instance, if it is
 *         outer)
 */
private boolean fetchTriangleToVisit(final QuadEdge edge, final List<QuadEdge> edgeStack, final short visitIndex, final double[] coordinates) {
    QuadEdge currentEdge = edge;
    boolean isFrame = false;
    int offset = 0;
    do {
        final Point fromPoint = currentEdge.getFromPoint();
        final double fromX = fromPoint.getX();
        final double fromY = fromPoint.getY();
        coordinates[offset++] = fromX;
        coordinates[offset++] = fromY;
        coordinates[offset++] = fromPoint.getZ();
        if (isFrameCoordinate(fromX, fromY)) {
            isFrame = true;
        }
        // push sym edges to visit next
        final QuadEdge sym = currentEdge.sym();
        if (!sym.isVisited(visitIndex)) {
            edgeStack.add(sym);
        }
        currentEdge.setVisited(visitIndex);
        currentEdge = currentEdge.getLeftNext();
    } while (currentEdge != edge);
    if (isFrame) {
        return false;
    } else {
        return true;
    }
}
Also used : Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 5 with Point

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

the class QuadEdgeSubdivision method findQuadEdge.

/**
 * <p>Locates an edge of a triangle which contains a location
 * specified by a point with x, y coordinates.</p>
 *
 * <p>The point is either on the edge or it is contained in a triangle that the edge is part of.</p>
 *
 * This locate algorithm relies on the subdivision being Delaunay. For
 * non-Delaunay subdivisions, this may loop for ever.
 *
 * @param x The point's x coordinate.
 * @param y The point's y coordinate.
 * @returns The QuadEdge which is part of a triangle that intersects the point.
 * @throws LocateFailureException  if the location algorithm fails to converge in a reasonable number of iterations
 */
public QuadEdge findQuadEdge(final double x, final double y) {
    QuadEdge currentEdge = this.lastEdge;
    final int maxIterations = this.edgeCount;
    for (int interationCount = 1; interationCount < maxIterations; interationCount++) {
        final Point fromPoint = currentEdge.getFromPoint();
        final double x1 = fromPoint.getX();
        final double y1 = fromPoint.getY();
        if (x == x1 && y == y1) {
            this.lastEdge = currentEdge;
            return currentEdge;
        } else {
            final Point toPoint = currentEdge.getToPoint();
            final double x2 = toPoint.getX();
            final double y2 = toPoint.getY();
            if (x == x2 && y == y2) {
                this.lastEdge = currentEdge;
                return currentEdge;
            } else if (Side.getSide(x1, y1, x2, y2, x, y) == Side.RIGHT) {
                currentEdge = currentEdge.sym();
            } else {
                final QuadEdge fromNextEdge = currentEdge.getFromNextEdge();
                final Point fromNextEdgeToPoint = fromNextEdge.getToPoint();
                final double fromNextEdgeX2 = fromNextEdgeToPoint.getX();
                final double fromNextEdgeY2 = fromNextEdgeToPoint.getY();
                if (Side.getSide(x1, y1, fromNextEdgeX2, fromNextEdgeY2, x, y) == Side.LEFT) {
                    currentEdge = fromNextEdge;
                } else {
                    final QuadEdge toNextEdge = currentEdge.getToNextEdge();
                    final Point toNextEdgeFromPoint = toNextEdge.getFromPoint();
                    final double toNextEdgeX1 = toNextEdgeFromPoint.getX();
                    final double toNextEdgeY1 = toNextEdgeFromPoint.getY();
                    if (Side.getSide(toNextEdgeX1, toNextEdgeY1, x2, y2, x, y) == Side.LEFT) {
                        currentEdge = toNextEdge;
                    } else {
                        // contained in triangle for edge
                        this.lastEdge = currentEdge;
                        return currentEdge;
                    }
                }
            }
        }
    }
    return null;
}
Also used : Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Aggregations

Point (com.revolsys.geometry.model.Point)669 LineString (com.revolsys.geometry.model.LineString)130 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)103 Geometry (com.revolsys.geometry.model.Geometry)95 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)90 ArrayList (java.util.ArrayList)79 BoundingBox (com.revolsys.geometry.model.BoundingBox)51 Polygon (com.revolsys.geometry.model.Polygon)42 LineSegment (com.revolsys.geometry.model.segment.LineSegment)34 List (java.util.List)28 LinearRing (com.revolsys.geometry.model.LinearRing)26 PointDouble (com.revolsys.geometry.model.impl.PointDouble)22 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)19 Edge (com.revolsys.geometry.graph.Edge)18 Test (org.junit.Test)17 Punctual (com.revolsys.geometry.model.Punctual)16 Segment (com.revolsys.geometry.model.segment.Segment)15 Vertex (com.revolsys.geometry.model.vertex.Vertex)15 Record (com.revolsys.record.Record)15 Lineal (com.revolsys.geometry.model.Lineal)14