Search in sources :

Example 1 with Envelope

use of org.neo4j.gis.spatial.index.Envelope in project neo4j by neo4j.

the class SpaceFillingCurveTest method shouldCreateSimple3DHilbertCurveAtLevel1.

@Test
void shouldCreateSimple3DHilbertCurveAtLevel1() {
    Envelope envelope = new Envelope(new double[] { -8, -8, -8 }, new double[] { 8, 8, 8 });
    HilbertSpaceFillingCurve3D curve = new HilbertSpaceFillingCurve3D(envelope, 1);
    assertAtLevel(curve, envelope);
    assertRange(2, 0, curve, 0, 0, 0);
    assertRange(2, 1, curve, 0, 1, 0);
    assertRange(2, 2, curve, 0, 1, 1);
    assertRange(2, 3, curve, 0, 0, 1);
    assertRange(2, 4, curve, 1, 0, 1);
    assertRange(2, 5, curve, 1, 1, 1);
    assertRange(2, 6, curve, 1, 1, 0);
    assertRange(2, 7, curve, 1, 0, 0);
}
Also used : Envelope(org.neo4j.gis.spatial.index.Envelope) Test(org.junit.jupiter.api.Test)

Example 2 with Envelope

use of org.neo4j.gis.spatial.index.Envelope in project neo4j by neo4j.

the class SpaceFillingCurveTest method shouldGet2DZOrderSearchTilesForManyLevels.

@Test
void shouldGet2DZOrderSearchTilesForManyLevels() {
    Envelope envelope = new Envelope(-8, 8, -8, 8);
    for (int level = 1; level <= ZOrderSpaceFillingCurve2D.MAX_LEVEL; level++) {
        ZOrderSpaceFillingCurve2D curve = new ZOrderSpaceFillingCurve2D(envelope, level);
        double halfTile = curve.getTileWidth(0, level) / 2.0;
        long start = System.currentTimeMillis();
        assertTiles(curve.getTilesIntersectingEnvelope(new Envelope(-8, -8 + halfTile, 8 - halfTile, 8)), new SpaceFillingCurve.LongRange(0, 0));
        assertTiles(curve.getTilesIntersectingEnvelope(new Envelope(8 - halfTile, 8, -8, -8 + halfTile)), new SpaceFillingCurve.LongRange(curve.getValueWidth() - 1, curve.getValueWidth() - 1));
        assertTiles(curve.getTilesIntersectingEnvelope(new Envelope(8 - halfTile, 8, 0, 0 + halfTile)), new SpaceFillingCurve.LongRange(curve.getValueWidth() / 2 - 1, curve.getValueWidth() / 2 - 1));
    }
}
Also used : Envelope(org.neo4j.gis.spatial.index.Envelope) Test(org.junit.jupiter.api.Test)

Example 3 with Envelope

use of org.neo4j.gis.spatial.index.Envelope in project neo4j by neo4j.

the class SpaceFillingCurveTest method shouldGet2DHilbertSearchTilesForLevel2.

@Test
void shouldGet2DHilbertSearchTilesForLevel2() {
    Envelope envelope = new Envelope(-8, 8, -8, 8);
    HilbertSpaceFillingCurve2D curve = new HilbertSpaceFillingCurve2D(envelope, 2);
    assertTiles(curve.getTilesIntersectingEnvelope(new Envelope(-6, -5, -6, -5)), new SpaceFillingCurve.LongRange(0, 0));
    assertTiles(curve.getTilesIntersectingEnvelope(new Envelope(0, 6, -6, -5)), new SpaceFillingCurve.LongRange(14, 15));
    assertTiles(curve.getTilesIntersectingEnvelope(new Envelope(-6, 4, -5, -2)), new SpaceFillingCurve.LongRange(0, 3), new SpaceFillingCurve.LongRange(12, 15));
    assertTiles(curve.getTilesIntersectingEnvelope(new Envelope(-2, -1, -6, 5)), new SpaceFillingCurve.LongRange(1, 2), new SpaceFillingCurve.LongRange(6, 7));
    assertTiles(curve.getTilesIntersectingEnvelope(new Envelope(-2, 1, -6, 5)), new SpaceFillingCurve.LongRange(1, 2), new SpaceFillingCurve.LongRange(6, 9), new SpaceFillingCurve.LongRange(13, 14));
}
Also used : Envelope(org.neo4j.gis.spatial.index.Envelope) Test(org.junit.jupiter.api.Test)

Example 4 with Envelope

use of org.neo4j.gis.spatial.index.Envelope in project neo4j by neo4j.

the class SpaceFillingCurveTest method shouldHaveReasonableCoveredVolume.

@Test
void shouldHaveReasonableCoveredVolume() {
    final double minExtent = 0.000001;
    final double maxAspect = 100.0;
    Envelope envelope = new Envelope(new double[] { -100, -100, -100 }, new double[] { 100, 100, 100 });
    // Chosen to be smaller than 10, and "random" enough to not intersect with tile borders on higher levels.
    final double rectangleStepsPerDimension = 3.789;
    final double extensionFactor = 8;
    // For all 3D levels
    for (int level = 7; level <= HilbertSpaceFillingCurve3D.MAX_LEVEL; level += 3) {
        for (SpaceFillingCurveConfiguration config : new SpaceFillingCurveConfiguration[] { new StandardConfiguration(1), new StandardConfiguration(2), new StandardConfiguration(3), new StandardConfiguration(4), new PartialOverlapConfiguration(1, 0.99, 0.1), new PartialOverlapConfiguration(1, 0.99, 0.5), new PartialOverlapConfiguration(2, 0.99, 0.1), new PartialOverlapConfiguration(2, 0.99, 0.5), new PartialOverlapConfiguration(3, 0.99, 0.1), new PartialOverlapConfiguration(3, 0.99, 0.5), new PartialOverlapConfiguration(4, 0.99, 0.1), new PartialOverlapConfiguration(4, 0.99, 0.5) }) {
            HilbertSpaceFillingCurve3D curve = new HilbertSpaceFillingCurve3D(envelope, level);
            double[] extent = new double[3];
            // For differently shaped rectangles
            for (extent[0] = minExtent; extent[0] <= envelope.getMax(0); extent[0] *= extensionFactor) {
                for (extent[1] = minExtent; extent[1] <= envelope.getMax(1); extent[1] *= extensionFactor) {
                    for (extent[2] = minExtent; extent[2] <= envelope.getMax(2); extent[2] *= extensionFactor) {
                        // Filter out very thin rectangles
                        double aspectXY = extent[0] > extent[1] ? (extent[0] / extent[1]) : (extent[1] / extent[0]);
                        double aspectYZ = extent[1] > extent[2] ? (extent[1] / extent[2]) : (extent[2] / extent[1]);
                        double aspectZX = extent[2] > extent[0] ? (extent[2] / extent[0]) : (extent[0] / extent[2]);
                        if (aspectXY < maxAspect && aspectYZ < maxAspect && aspectZX < maxAspect) {
                            double[] offset = new double[3];
                            // For different positions of the rectangle
                            for (offset[0] = 0; envelope.getMin(0) + offset[0] + extent[0] <= envelope.getMax(0); offset[0] += (envelope.getWidth(0) - extent[0]) / rectangleStepsPerDimension) {
                                for (offset[1] = 0; envelope.getMin(1) + offset[1] + extent[1] <= envelope.getMax(1); offset[1] += (envelope.getWidth(1) - extent[1]) / rectangleStepsPerDimension) {
                                    for (offset[2] = 0; envelope.getMin(2) + offset[2] + extent[2] <= envelope.getMax(2); offset[2] += (envelope.getWidth(2) - extent[2]) / rectangleStepsPerDimension) {
                                        HistogramMonitor monitor = new HistogramMonitor(curve.getMaxLevel());
                                        final double[] startPoint = Arrays.copyOf(envelope.getMin(), 3);
                                        final double[] endPoint = Arrays.copyOf(extent, 3);
                                        for (int i = 0; i < 3; i++) {
                                            startPoint[i] += offset[i];
                                            endPoint[i] += startPoint[i];
                                        }
                                        Envelope searchEnvelope = new Envelope(startPoint, endPoint);
                                        List<SpaceFillingCurve.LongRange> ranges = curve.getTilesIntersectingEnvelope(searchEnvelope, config, monitor);
                                        assertThat(ranges).isNotEmpty();
                                        assertThat(monitor.getSearchArea()).as(String.format("Search size was bigger than covered size for level %d, with search %s", level, searchEnvelope.toString())).isLessThanOrEqualTo(monitor.getCoveredArea());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Envelope(org.neo4j.gis.spatial.index.Envelope) Test(org.junit.jupiter.api.Test)

Example 5 with Envelope

use of org.neo4j.gis.spatial.index.Envelope in project neo4j by neo4j.

the class SpaceFillingCurveTest method shouldCreateSimple2DZOrderCurveAtLevel1.

// 
// Set of tests for 2D ZOrderCurve at various levels
// 
@Test
void shouldCreateSimple2DZOrderCurveAtLevel1() {
    Envelope envelope = new Envelope(-8, 8, -8, 8);
    ZOrderSpaceFillingCurve2D curve = new ZOrderSpaceFillingCurve2D(envelope, 1);
    assertAtLevel(curve, envelope);
    assertRange("Bottom-left should evaluate to zero", curve, getTileEnvelope(envelope, 2, 0, 1), 0L);
    assertRange("Top-left should evaluate to one", curve, getTileEnvelope(envelope, 2, 1, 1), 1L);
    assertRange("Top-right should evaluate to two", curve, getTileEnvelope(envelope, 2, 0, 0), 2L);
    assertRange("Bottom-right should evaluate to three", curve, getTileEnvelope(envelope, 2, 1, 0), 3L);
}
Also used : Envelope(org.neo4j.gis.spatial.index.Envelope) Test(org.junit.jupiter.api.Test)

Aggregations

Envelope (org.neo4j.gis.spatial.index.Envelope)55 Test (org.junit.jupiter.api.Test)48 Config (org.neo4j.configuration.Config)1 SpaceFillingCurveSettings (org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings)1