Search in sources :

Example 1 with PointOnGeometryLocator

use of com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator in project com.revolsys.open by revolsys.

the class PreparedPolygon method intersects.

@Override
public boolean intersects(final Geometry geometry) {
    if (envelopesIntersect(geometry)) {
        if (this.isRectangle) {
            return RectangleIntersects.rectangleIntersects(this, geometry);
        } else {
            final PointOnGeometryLocator pointLocator = getPointLocator();
            /**
             * Do point-in-poly tests first, since they are cheaper and may result in a
             * quick positive result.
             *
             * If a point of any test components lie in target, result is true
             */
            final boolean isInPrepGeomArea = AbstractPreparedPolygonContains.isAnyTestComponentInTarget(pointLocator, geometry);
            if (isInPrepGeomArea) {
                return true;
            }
            /**
             * If input contains only points, then at
             * this point it is known that none of them are contained in the target
             */
            if (geometry.getDimension() == 0) {
                return false;
            } else {
                /**
                 * If any segments intersect, result is true
                 */
                final List<NodedSegmentString> lineSegStr = SegmentStringUtil.extractSegmentStrings(geometry);
                // (i.e. NOT for point inputs)
                if (lineSegStr.size() > 0) {
                    final boolean segsIntersect = getIntersectionFinder().intersects(lineSegStr);
                    if (segsIntersect) {
                        return true;
                    }
                }
                /**
                 * If the test has dimension = 2 as well, it is necessary to test for proper
                 * inclusion of the target. Since no segments intersect, it is sufficient to
                 * test representative points.
                 */
                if (geometry.getDimension() == 2) {
                    // TODO: generalize this to handle GeometryCollections
                    final boolean isPrepGeomInArea = AbstractPreparedPolygonContains.isAnyTargetComponentInAreaTest(geometry, this);
                    if (isPrepGeomInArea) {
                        return true;
                    }
                }
                return false;
            }
        }
    } else {
        return false;
    }
}
Also used : NodedSegmentString(com.revolsys.geometry.noding.NodedSegmentString) PointOnGeometryLocator(com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator)

Example 2 with PointOnGeometryLocator

use of com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator in project com.revolsys.open by revolsys.

the class PreparedLinearRing method isPointInRing.

@Override
public boolean isPointInRing(final double x, final double y) {
    final PointOnGeometryLocator pointLocator = getPointLocator();
    final Location location = pointLocator.locate(x, y);
    return location != Location.EXTERIOR;
}
Also used : PointOnGeometryLocator(com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator) Location(com.revolsys.geometry.model.Location)

Example 3 with PointOnGeometryLocator

use of com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator in project com.revolsys.open by revolsys.

the class PointInAreaPerfTest method run.

public void run() {
    final GeometryFactory geomFactory = GeometryFactory.DEFAULT_3D;
    final SineStarFactory ssFact = new SineStarFactory();
    ssFact.setSize(1000.0);
    ssFact.setNumPoints(2000);
    ssFact.setArmLengthRatio(0.1);
    ssFact.setNumArms(100);
    final Geometry area = ssFact.newSineStar();
    // System.out.println(area);
    final Stopwatch sw = new Stopwatch();
    final PointOnGeometryLocator pia = new MCIndexedPointInAreaLocator(area);
    // PointInAreaLocator pia = new IntervalIndexedPointInAreaLocator(area);
    // PointInAreaLocator pia = new SimplePointInAreaLocator(area);
    final PointInAreaPerfTester perfTester = new PointInAreaPerfTester(geomFactory, area);
    perfTester.setNumPoints(50000);
    perfTester.setPIA(pia);
    perfTester.run();
// System.out.println("Overall time: " + sw.getTimeString());
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) PointOnGeometryLocator(com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator) SineStarFactory(com.revolsys.geometry.model.util.SineStarFactory) Stopwatch(com.revolsys.geometry.util.Stopwatch)

Example 4 with PointOnGeometryLocator

use of com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator in project com.revolsys.open by revolsys.

the class IndexedPointInAreaStressTest method testGrid.

public void testGrid() {
    // Use fixed PM to try and get at least some points hitting the boundary
    final GeometryFactory geomFactory = GeometryFactory.fixed2d(0, 1.0, 1.0);
    // GeometryFactoryI geomFactory = new GeometryFactoryI();
    final PerturbedGridPolygonBuilder gridBuilder = new PerturbedGridPolygonBuilder(geomFactory);
    gridBuilder.setNumLines(20);
    gridBuilder.setLineWidth(10.0);
    gridBuilder.setSeed(1185072199562L);
    final Geometry area = gridBuilder.getGeometry();
    // PointInAreaLocator pia = new
    // GeometryFactoryIndexedPointInAreaLocator(area);
    final PointOnGeometryLocator pia = new IndexedPointInAreaLocator(area);
    final PointInAreaStressTester gridTester = new PointInAreaStressTester(geomFactory, area);
    gridTester.setNumPoints(100000);
    gridTester.setPIA(pia);
    final boolean isCorrect = gridTester.run();
    assertTrue(isCorrect);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) IndexedPointInAreaLocator(com.revolsys.geometry.algorithm.locate.IndexedPointInAreaLocator) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) PointInAreaStressTester(com.revolsys.geometry.test.old.perf.algorithm.PointInAreaStressTester) PointOnGeometryLocator(com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator)

Aggregations

PointOnGeometryLocator (com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator)4 Geometry (com.revolsys.geometry.model.Geometry)2 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)2 IndexedPointInAreaLocator (com.revolsys.geometry.algorithm.locate.IndexedPointInAreaLocator)1 Location (com.revolsys.geometry.model.Location)1 SineStarFactory (com.revolsys.geometry.model.util.SineStarFactory)1 NodedSegmentString (com.revolsys.geometry.noding.NodedSegmentString)1 PointInAreaStressTester (com.revolsys.geometry.test.old.perf.algorithm.PointInAreaStressTester)1 Stopwatch (com.revolsys.geometry.util.Stopwatch)1