Search in sources :

Example 6 with BoundingBoxDoubleXY

use of com.revolsys.geometry.model.impl.BoundingBoxDoubleXY in project com.revolsys.open by revolsys.

the class STRtreeTest method testQuery.

public void testQuery() throws Throwable {
    final ArrayList geometries = new ArrayList();
    geometries.add(this.factory.lineString(new Point[] { new PointDoubleXY(0, 0), new PointDoubleXY(10, 10) }));
    geometries.add(this.factory.lineString(new Point[] { new PointDoubleXY(20, 20), new PointDoubleXY(30, 30) }));
    geometries.add(this.factory.lineString(new Point[] { new PointDoubleXY(20, 20), new PointDoubleXY(30, 30) }));
    final STRtreeDemo.TestTree t = new STRtreeDemo.TestTree(4);
    for (final Iterator i = geometries.iterator(); i.hasNext(); ) {
        final Geometry g = (Geometry) i.next();
        t.insertItem(g.getBoundingBox(), new Object());
    }
    t.build();
    try {
        assertEquals(1, t.getItems(new BoundingBoxDoubleXY(5, 5, 6, 6)).size());
        assertEquals(0, t.getItems(new BoundingBoxDoubleXY(20, 0, 30, 10)).size());
        assertEquals(2, t.getItems(new BoundingBoxDoubleXY(25, 25, 26, 26)).size());
        assertEquals(3, t.getItems(new BoundingBoxDoubleXY(0, 0, 100, 100)).size());
    } catch (final Throwable x) {
        STRtreeDemo.printSourceData(geometries, System.out);
        STRtreeDemo.printLevels(t, System.out);
        throw x;
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)

Example 7 with BoundingBoxDoubleXY

use of com.revolsys.geometry.model.impl.BoundingBoxDoubleXY in project com.revolsys.open by revolsys.

the class KdTreeTest method testSinglePoint.

public void testSinglePoint() {
    final KdTree index = new KdTree(GeometryFactory.fixed2d(0, 1000, 1000));
    final KdNode node1 = index.insertPoint(new PointDouble(1, 1));
    final KdNode node2 = index.insertPoint(new PointDouble(1, 1));
    assertTrue("Inserting 2 identical points should create one node", node1 == node2);
    final BoundingBox queryEnv = new BoundingBoxDoubleXY(0, 0, 10, 10);
    final List result = index.getItems(queryEnv);
    assertTrue(result.size() == 1);
    final KdNode node = (KdNode) result.get(0);
    assertTrue(node.getCount() == 2);
    assertTrue(node.isRepeated());
}
Also used : PointDouble(com.revolsys.geometry.model.impl.PointDouble) KdTree(com.revolsys.geometry.index.kdtree.KdTree) BoundingBox(com.revolsys.geometry.model.BoundingBox) KdNode(com.revolsys.geometry.index.kdtree.KdNode) List(java.util.List) BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)

Example 8 with BoundingBoxDoubleXY

use of com.revolsys.geometry.model.impl.BoundingBoxDoubleXY 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 9 with BoundingBoxDoubleXY

use of com.revolsys.geometry.model.impl.BoundingBoxDoubleXY in project com.revolsys.open by revolsys.

the class MCPointInRing method isInside.

@Override
public boolean isInside(final Point pt) {
    this.crossings = 0;
    // test all segments intersected by ray from pt in positive x direction
    final double y = pt.getY();
    final BoundingBox rayEnv = new BoundingBoxDoubleXY(-Double.MAX_VALUE, y, Double.MAX_VALUE, y);
    this.interval.min = y;
    this.interval.max = y;
    final List segs = this.tree.query(this.interval);
    // System.out.println("query size = " + segs.size());
    final MCSelecter mcSelecter = new MCSelecter(pt);
    for (final Iterator i = segs.iterator(); i.hasNext(); ) {
        final MonotoneChain mc = (MonotoneChain) i.next();
        testMonotoneChain(rayEnv, mcSelecter, mc);
    }
    /*
     * p is inside if number of crossings is odd.
     */
    if (this.crossings % 2 == 1) {
        return true;
    }
    return false;
}
Also used : MonotoneChain(com.revolsys.geometry.index.chain.MonotoneChain) BoundingBox(com.revolsys.geometry.model.BoundingBox) Iterator(java.util.Iterator) List(java.util.List) BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)

Example 10 with BoundingBoxDoubleXY

use of com.revolsys.geometry.model.impl.BoundingBoxDoubleXY in project com.revolsys.open by revolsys.

the class GeometricShapeBuilder method getSquareExtent.

public BoundingBox getSquareExtent() {
    final double radius = getRadius();
    final Point centre = getCentre();
    return new BoundingBoxDoubleXY(centre.getX() - radius, centre.getY() - radius, centre.getX() + radius, centre.getY() + radius);
}
Also used : Point(com.revolsys.geometry.model.Point) BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)

Aggregations

BoundingBoxDoubleXY (com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)26 BoundingBox (com.revolsys.geometry.model.BoundingBox)18 ArrayList (java.util.ArrayList)7 List (java.util.List)6 Point (com.revolsys.geometry.model.Point)5 Geometry (com.revolsys.geometry.model.Geometry)4 StrTree (com.revolsys.geometry.index.strtree.StrTree)3 KdNode (com.revolsys.geometry.index.kdtree.KdNode)2 KdTree (com.revolsys.geometry.index.kdtree.KdTree)2 LineString (com.revolsys.geometry.model.LineString)2 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)2 Iterator (java.util.Iterator)2 Lists (com.revolsys.collection.list.Lists)1 MapEx (com.revolsys.collection.map.MapEx)1 ScaledIntegerTriangulatedIrregularNetwork (com.revolsys.elevation.tin.compactbinary.ScaledIntegerTriangulatedIrregularNetwork)1 AsciiTin (com.revolsys.elevation.tin.tin.AsciiTin)1 RayCrossingCounter (com.revolsys.geometry.algorithm.RayCrossingCounter)1 Area (com.revolsys.geometry.cs.Area)1 Authority (com.revolsys.geometry.cs.Authority)1 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)1