Search in sources :

Example 11 with BoundingBox

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

the class MCIndexPointSnapper method snap.

/**
 * Snaps (nodes) all interacting segments to this hot pixel.
 * The hot pixel may represent a vertex of an edge,
 * in which case this routine uses the optimization
 * of not noding the vertex itself
 *
 * @param hotPixel the hot pixel to snap to
 * @param parentEdge the edge containing the vertex, if applicable, or <code>null</code>
 * @param hotPixelVertexIndex the index of the hotPixel vertex, if applicable, or -1
 * @return <code>true</code> if a node was added for this pixel
 */
public boolean snap(final HotPixel hotPixel, final SegmentString parentEdge, final int hotPixelVertexIndex) {
    final BoundingBox pixelEnv = hotPixel.getSafeEnvelope();
    final HotPixelSnapAction hotPixelSnapAction = new HotPixelSnapAction(hotPixel, parentEdge, hotPixelVertexIndex);
    this.index.query(pixelEnv, (item) -> {
        final MonotoneChain testChain = (MonotoneChain) item;
        testChain.select(pixelEnv, hotPixelSnapAction);
    });
    return hotPixelSnapAction.isNodeAdded();
}
Also used : MonotoneChain(com.revolsys.geometry.index.chain.MonotoneChain) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 12 with BoundingBox

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

the class Buffer method precisionScaleFactor.

/**
 * Compute a scale factor to limit the precision of
 * a given combination of Geometry and buffer distance.
 * The scale factor is determined by
 * the number of digits of precision in the (geometry + buffer distance),
 * limited by the supplied <code>maxPrecisionDigits</code> value.
 * <p>
 * The scale factor is based on the absolute magnitude of the (geometry + buffer distance).
 * since this determines the number of digits of precision which must be handled.
 *
 * @param geometry the Geometry being buffered
 * @param distance the buffer distance
 * @param maxPrecisionDigits the max # of digits that should be allowed by
 *          the precision determined by the computed scale factor
 *
 * @return a scale factor for the buffer computation
 */
private static double precisionScaleFactor(final Geometry geometry, final double distance, final int maxPrecisionDigits) {
    final BoundingBox boundingBox = geometry.getBoundingBox();
    final double envMax = MathUtil.max(Math.abs(boundingBox.getMaxX()), Math.abs(boundingBox.getMaxY()), Math.abs(boundingBox.getMinX()), Math.abs(boundingBox.getMinY()));
    final double expandByDistance = distance > 0.0 ? distance : 0.0;
    final double bufEnvMax = envMax + 2 * expandByDistance;
    // the smallest power of 10 greater than the buffer envelope
    final int bufEnvPrecisionDigits = (int) (Math.log(bufEnvMax) / Math.log(10) + 1.0);
    final int minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;
    final double scaleFactor = Math.pow(10.0, minUnitLog10);
    return scaleFactor;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point)

Example 13 with BoundingBox

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

the class RectangleIntersectsSegmentVisitor method visit.

@Override
protected void visit(final Geometry geom) {
    /**
     * It may be the case that the rectangle and the
     * envelope of the geometry component are disjoint,
     * so it is worth checking this simple condition.
     */
    final BoundingBox elementEnv = geom.getBoundingBox();
    if (!this.rectEnv.intersects(elementEnv)) {
        return;
    }
    // check segment intersections
    // get all lines from geometry component
    // (there may be more than one if it's a multi-ring polygon)
    final List lines = geom.getGeometryComponents(LineString.class);
    checkIntersectionWithLineStrings(lines);
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) List(java.util.List)

Example 14 with BoundingBox

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

the class RectangleIntersectsSegmentVisitor method rectangleIntersects.

/**
 * Tests whether a rectangle intersects a given geometry.
 *
 * @param rectangle
 *          a rectangular Polygon
 * @param b
 *          a Geometry of any type
 * @return true if the geometries intersect
 */
public static boolean rectangleIntersects(final Polygon rectangle, final Geometry geom) {
    final BoundingBox boundingBox = rectangle.getBoundingBox();
    if (boundingBox.intersects(geom.getBoundingBox())) {
        /**
         * Test if rectangle envelope intersects any component envelope.
         * This handles Point components as well
         */
        final EnvelopeIntersectsVisitor visitor = new EnvelopeIntersectsVisitor(boundingBox);
        visitor.applyTo(geom);
        if (visitor.intersects()) {
            return true;
        }
        /**
         * Test if any rectangle vertex is contained in the target geometry
         */
        final GeometryContainsPointVisitor ecpVisitor = new GeometryContainsPointVisitor(rectangle);
        ecpVisitor.applyTo(geom);
        if (ecpVisitor.containsPoint()) {
            return true;
        }
        /**
         * Test if any target geometry line segment intersects the rectangle
         */
        final RectangleIntersectsSegmentVisitor riVisitor = new RectangleIntersectsSegmentVisitor(rectangle);
        riVisitor.applyTo(geom);
        if (riVisitor.intersects()) {
            return true;
        }
    }
    return false;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 15 with BoundingBox

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

the class PolygonBuilder method findEdgeRingContaining.

/**
 * Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any.
 * The innermost enclosing ring is the <i>smallest</i> enclosing ring.
 * The algorithm used depends on the fact that:
 * <br>
 *  ring A contains ring B iff envelope(ring A) contains envelope(ring B)
 * <br>
 * This routine is only safe to use if the chosen point of the hole
 * is known to be properly contained in a shell
 * (which is guaranteed to be the case if the hole does not touch its shell)
 *
 * @return containing EdgeRing, if there is one
 * or null if no containing EdgeRing is found
 */
private EdgeRing findEdgeRingContaining(final EdgeRing testEr, final List<EdgeRing> shellList) {
    final LinearRing testRing = testEr.getLinearRing();
    final BoundingBox testEnv = testRing.getBoundingBox();
    final double testX = testRing.getX(0);
    final double testY = testRing.getY(0);
    EdgeRing minShell = null;
    BoundingBox minEnv = null;
    for (final EdgeRing tryShell : shellList) {
        final LinearRing tryRing = tryShell.getLinearRing();
        final BoundingBox tryEnv = tryRing.getBoundingBox();
        if (minShell != null) {
            minEnv = minShell.getLinearRing().getBoundingBox();
        }
        boolean isContained = false;
        if (tryEnv.covers(testEnv) && tryRing.isPointInRing(testX, testY)) {
            isContained = true;
        }
        // ring
        if (isContained) {
            if (minShell == null || minEnv.covers(tryEnv)) {
                minShell = tryShell;
            }
        }
    }
    return minShell;
}
Also used : EdgeRing(com.revolsys.geometry.geomgraph.EdgeRing) BoundingBox(com.revolsys.geometry.model.BoundingBox) LinearRing(com.revolsys.geometry.model.LinearRing)

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