Search in sources :

Example 31 with BoundingBox

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

the class QuadtreeCorrectTest method newGrid.

void newGrid(final int nGridCells) {
    int gridSize = (int) Math.sqrt(nGridCells);
    gridSize += 1;
    final double extent = MAX_EXTENT - MIN_EXTENT;
    final double gridInc = extent / gridSize;
    final double cellSize = 2 * gridInc;
    for (int i = 0; i < gridSize; i++) {
        for (int j = 0; j < gridSize; j++) {
            final double x = MIN_EXTENT + gridInc * i;
            final double y = MIN_EXTENT + gridInc * j;
            final BoundingBox env = new BoundingBoxDoubleXY(x, y, x + cellSize, y + cellSize);
            this.index.insertItem(env, env);
            this.envList.add(env);
        }
    }
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)

Example 32 with BoundingBox

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

the class SpatialIndexTester method addSourceData.

private void addSourceData(final double offset, final List<BoundingBox> sourceData) {
    for (int i = 0; i < CELLS_PER_GRID_SIDE; i++) {
        final double minx = i * CELL_EXTENT + offset;
        final double maxx = minx + FEATURE_EXTENT;
        for (int j = 0; j < CELLS_PER_GRID_SIDE; j++) {
            final double miny = j * CELL_EXTENT + offset;
            final double maxy = miny + FEATURE_EXTENT;
            final BoundingBox e = new BoundingBoxDoubleXY(minx, miny, maxx, maxy);
            sourceData.add(e);
        }
    }
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)

Example 33 with BoundingBox

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

the class GridGenerator method newBoundingBox.

/**
 * @return BoundingBox
 *
 * @see com.revolsys.geometry.testold.generator.GeometryGenerator#newIterator()
 *
 * @throws NoSuchElementException when all the grids have been created
 * @throws NullPointerException when either the Geometry Factory, or the Bounding Box are undefined.
 */
public BoundingBox newBoundingBox() {
    if (!canCreate()) {
        throw new NoSuchElementException("There are not any grids left to create.");
    }
    if (this.geometryFactory == null) {
        throw new NullPointerException("GeometryFactoryI is not declared");
    }
    if (this.boundingBox == null || this.boundingBox.isEmpty()) {
        throw new NullPointerException("Bounding Box is not declared");
    }
    // base x
    final double x = this.boundingBox.getMinX();
    final double dx = this.boundingBox.getMaxX() - x;
    // base y
    final double y = this.boundingBox.getMinY();
    final double dy = this.boundingBox.getMaxY() - y;
    final int row = this.numberRows == 1 ? 0 : this.index / this.numberRows;
    final int col = this.numberColumns == 1 ? 0 : this.index % this.numberColumns;
    // size of a step
    double sx, sy;
    sx = dx / this.numberColumns;
    sy = dy / this.numberRows;
    double minx, miny;
    minx = x + col * sx;
    miny = y + row * sy;
    final BoundingBox box = new BoundingBoxDoubleXY(this.geometryFactory.makePrecise(0, minx), this.geometryFactory.makePrecise(1, miny), this.geometryFactory.makePrecise(0, minx + sx), this.geometryFactory.makePrecise(1, miny + sy));
    this.index++;
    return box;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY) NoSuchElementException(java.util.NoSuchElementException)

Example 34 with BoundingBox

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

the class IndexTester method runSelfQuery.

void runSelfQuery(final List items) {
    double querySize = 0.0;
    for (int i = 0; i < items.size(); i++) {
        final BoundingBox env = (BoundingBox) items.get(i);
        final List list = this.index.query(env);
        Assert.isTrue(!list.isEmpty());
        querySize += list.size();
    }
// System.out.println("Avg query size = " + querySize / items.size());
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) List(java.util.List) ArrayList(java.util.ArrayList)

Example 35 with BoundingBox

use of com.revolsys.geometry.model.BoundingBox 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)

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