Search in sources :

Example 6 with Geometry

use of com.github.davidmoten.rtree2.geometry.Geometry in project rtree2 by davidmoten.

the class RTreeTest method testStandardRTreeSearch.

@Test
public void testStandardRTreeSearch() {
    Rectangle r = rectangle(13.0, 23.0, 50.0, 80.0);
    Point[] points = { point(59.0, 91.0), point(86.0, 14.0), point(36.0, 60.0), point(57.0, 36.0), point(14.0, 37.0) };
    RTree<Integer, Geometry> tree = RTree.create();
    for (int i = 0; i < points.length; i++) {
        Point point = points[i];
        System.out.println("point(" + point.x() + "," + point.y() + "), value=" + (i + 1));
        tree = tree.add(i + 1, point);
    }
    System.out.println(tree.asString());
    System.out.println("searching " + r);
    Set<Integer> set = new HashSet<Integer>(Observable.from(tree.search(r)).map(RTreeTest.<Integer>toValue()).toList().toBlocking().single());
    assertEquals(new HashSet<Integer>(asList(3, 5)), set);
}
Also used : Geometry(com.github.davidmoten.rtree2.geometry.Geometry) HasGeometry(com.github.davidmoten.rtree2.geometry.HasGeometry) Rectangle(com.github.davidmoten.rtree2.geometry.Rectangle) Point(com.github.davidmoten.rtree2.geometry.Point) Geometries.point(com.github.davidmoten.rtree2.geometry.Geometries.point) Point(com.github.davidmoten.rtree2.geometry.Point) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with Geometry

use of com.github.davidmoten.rtree2.geometry.Geometry in project rtree2 by davidmoten.

the class RTreeTest method testVisualizer.

@Test
public void testVisualizer() {
    List<Entry<Object, Geometry>> entries = createRandomEntries(1000);
    int maxChildren = 8;
    RTree<Object, Geometry> tree = RTree.maxChildren(maxChildren).create().add(entries);
    tree.visualize(600, 600).save("target/tree.png");
    RTree<Object, Geometry> tree2 = RTree.star().maxChildren(maxChildren).create().add(entries);
    tree2.visualize(600, 600).save("target/tree2.png");
    RTree<Object, Geometry> tree3 = RTree.maxChildren(maxChildren).create(entries);
    tree3.visualize(600, 600).save("target/tree3.png");
}
Also used : Geometry(com.github.davidmoten.rtree2.geometry.Geometry) HasGeometry(com.github.davidmoten.rtree2.geometry.HasGeometry) Geometries.point(com.github.davidmoten.rtree2.geometry.Geometries.point) Point(com.github.davidmoten.rtree2.geometry.Point) Test(org.junit.Test)

Example 8 with Geometry

use of com.github.davidmoten.rtree2.geometry.Geometry in project rtree2 by davidmoten.

the class RTreeTest method testStandardRTreeSearch2.

@Test
public void testStandardRTreeSearch2() {
    Rectangle r = rectangle(10.0, 10.0, 50.0, 50.0);
    Point[] points = { point(28.0, 19.0), point(29.0, 4.0), point(10.0, 63.0), point(34.0, 85.0), point(62.0, 45.0) };
    RTree<Integer, Geometry> tree = RTree.create();
    for (int i = 0; i < points.length; i++) {
        Point point = points[i];
        System.out.println("point(" + point.x() + "," + point.y() + "), value=" + (i + 1));
        tree = tree.add(i + 1, point);
    }
    System.out.println(tree.asString());
    System.out.println("searching " + r);
    Set<Integer> set = new HashSet<Integer>(Observable.from(tree.search(r)).map(RTreeTest.<Integer>toValue()).toList().toBlocking().single());
    assertEquals(new HashSet<Integer>(asList(1)), set);
}
Also used : Geometry(com.github.davidmoten.rtree2.geometry.Geometry) HasGeometry(com.github.davidmoten.rtree2.geometry.HasGeometry) Rectangle(com.github.davidmoten.rtree2.geometry.Rectangle) Point(com.github.davidmoten.rtree2.geometry.Point) Geometries.point(com.github.davidmoten.rtree2.geometry.Geometries.point) Point(com.github.davidmoten.rtree2.geometry.Point) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Geometry

use of com.github.davidmoten.rtree2.geometry.Geometry in project rtree2 by davidmoten.

the class RTreeTest method testBulkLoadingEntryCount.

@Test
public void testBulkLoadingEntryCount() {
    List<Entry<Integer, Geometry>> entries = new ArrayList<Entry<Integer, Geometry>>(10000);
    for (int i = 1; i <= 10000; i++) {
        Point point = nextPoint();
        // System.out.println("point(" + point.x() + "," + point.y() +
        // "),");
        entries.add(new EntryDefault<Integer, Geometry>(i, point));
    }
    RTree<Integer, Geometry> tree = RTree.create(entries);
    int entrySize = Observable.from(tree.entries()).count().toBlocking().single();
    System.out.println("entry count: " + entrySize);
    assertEquals(entrySize, entries.size());
}
Also used : Geometry(com.github.davidmoten.rtree2.geometry.Geometry) HasGeometry(com.github.davidmoten.rtree2.geometry.HasGeometry) ArrayList(java.util.ArrayList) Point(com.github.davidmoten.rtree2.geometry.Point) Geometries.point(com.github.davidmoten.rtree2.geometry.Geometries.point) Point(com.github.davidmoten.rtree2.geometry.Point) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 Point (com.github.davidmoten.rtree2.geometry.Point)7 Geometries.point (com.github.davidmoten.rtree2.geometry.Geometries.point)6 Geometry (com.github.davidmoten.rtree2.geometry.Geometry)6 HasGeometry (com.github.davidmoten.rtree2.geometry.HasGeometry)6 Rectangle (com.github.davidmoten.rtree2.geometry.Rectangle)6 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 Position (com.github.davidmoten.grumpy.core.Position)1 LeafDefault (com.github.davidmoten.rtree2.internal.LeafDefault)1