Search in sources :

Example 6 with Envelope

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

the class SpaceFillingCurveTest method shouldCreate2DHilbertCurveOfThreeLevelsFromExampleInThePaper.

@Test
void shouldCreate2DHilbertCurveOfThreeLevelsFromExampleInThePaper() {
    HilbertSpaceFillingCurve2D curve = new HilbertSpaceFillingCurve2D(new Envelope(0, 8, 0, 8), 3);
    assertThat(curve.derivedValueFor(new double[] { 6, 4 })).as("Example should evaluate to 101110").isEqualTo(46L);
}
Also used : Envelope(org.neo4j.gis.spatial.index.Envelope) Test(org.junit.jupiter.api.Test)

Example 7 with Envelope

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

the class SpaceFillingCurveTest method shouldCreateSimple3DHilbertCurveAtManyLevels.

@Test
void shouldCreateSimple3DHilbertCurveAtManyLevels() {
    Envelope envelope = new Envelope(new double[] { -8, -8, -8 }, new double[] { 8, 8, 8 });
    for (int level = 1; level <= HilbertSpaceFillingCurve3D.MAX_LEVEL; level++) {
        HilbertSpaceFillingCurve3D curve = new HilbertSpaceFillingCurve3D(envelope, level);
        assertAtLevel(curve, envelope);
        assertRange((int) curve.getWidth(), 0, curve, 0, 0, 0);
        assertRange((int) curve.getWidth(), curve.getValueWidth() - 1, curve, (int) curve.getWidth() - 1, 0, 0);
    }
}
Also used : Envelope(org.neo4j.gis.spatial.index.Envelope) Test(org.junit.jupiter.api.Test)

Example 8 with Envelope

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

the class SpaceFillingCurveTest method shouldCreateSimple3DHilbertCurveAtLevel4.

@Test
void shouldCreateSimple3DHilbertCurveAtLevel4() {
    Envelope envelope = new Envelope(new double[] { -8, -8, -8 }, new double[] { 8, 8, 8 });
    HilbertSpaceFillingCurve3D curve = new HilbertSpaceFillingCurve3D(envelope, 4);
    assertAtLevel(curve, envelope);
    assertRange(16, 0, curve, 0, 0, 0);
    assertRange(16, (long) Math.pow(8, 4) - 1, curve, 15, 0, 0);
}
Also used : Envelope(org.neo4j.gis.spatial.index.Envelope) Test(org.junit.jupiter.api.Test)

Example 9 with Envelope

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

the class SpaceFillingCurveTest method shouldGet3DSearchTilesForManyLevels.

@Test
void shouldGet3DSearchTilesForManyLevels() {
    Envelope envelope = new Envelope(new double[] { -8, -8, -8 }, new double[] { 8, 8, 8 });
    for (int level = 1; level <= HilbertSpaceFillingCurve3D.MAX_LEVEL; level++) {
        HilbertSpaceFillingCurve3D curve = new HilbertSpaceFillingCurve3D(envelope, level);
        double halfTile = curve.getTileWidth(0, level) / 2.0;
        assertTiles(curve.getTilesIntersectingEnvelope(new Envelope(new double[] { -8, -8, -8 }, new double[] { -8 + halfTile, -8 + halfTile, -8 + halfTile })), new SpaceFillingCurve.LongRange(0, 0));
        assertTiles(curve.getTilesIntersectingEnvelope(new Envelope(new double[] { 8 - halfTile, -8, -8 }, new double[] { 8, -8 + halfTile, -8 + halfTile })), new SpaceFillingCurve.LongRange(curve.getValueWidth() - 1, curve.getValueWidth() - 1));
    // TODO: There is a performance issue building the full range when the search envelope hits a very wide part of the extent
    // Suggestion to fix this with shallower traversals
    // assertTiles(curve.getTilesIntersectingEnvelope(new Envelope(new double[]{-8, -8, -8}, new double[]{8, 8, 8})),
    // new HilbertSpaceFillingCurve.LongRange(0, curve.getValueWidth() - 1));
    }
}
Also used : Envelope(org.neo4j.gis.spatial.index.Envelope) Test(org.junit.jupiter.api.Test)

Example 10 with Envelope

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

the class SpaceFillingCurveTest method shouldHaveReasonableCoveredArea.

@Test
void shouldHaveReasonableCoveredArea() {
    final double minExtent = 0.000001;
    final double maxAspect = 100.0;
    final int xmin = -100;
    final int xmax = 100;
    final int ymin = -100;
    final int ymax = 100;
    // Chosen to be smaller than 10, and "random" enough to not intersect with tile borders on higher levels.
    final double rectangleStepsPerDimension = 9.789;
    final double extensionFactor = 5;
    Envelope envelope = new Envelope(xmin, xmax, ymin, ymax);
    // For all 2D levels
    for (int level = 1; level <= HilbertSpaceFillingCurve2D.MAX_LEVEL; level++) {
        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) }) {
            HilbertSpaceFillingCurve2D curve = new HilbertSpaceFillingCurve2D(envelope, level);
            // For differently shaped rectangles
            for (double xExtent = minExtent; xExtent <= xmax; xExtent *= extensionFactor) {
                for (double yExtent = minExtent; yExtent <= ymax; yExtent *= extensionFactor) {
                    // Filter out very thin rectangles
                    double aspect = xExtent > yExtent ? (xExtent / yExtent) : (yExtent / xExtent);
                    if (aspect < maxAspect) {
                        // For different positions of the rectangle
                        for (double xOffset = 0; xmin + xOffset + xExtent <= xmax; xOffset += (xmax - xmin - xExtent) / rectangleStepsPerDimension) {
                            for (double yOffset = 0; xmin + yOffset + yExtent <= ymax; yOffset += (ymax - ymin - yExtent) / rectangleStepsPerDimension) {
                                HistogramMonitor monitor = new HistogramMonitor(curve.getMaxLevel());
                                final double xStart = xmin + xOffset;
                                final double xEnd = xStart + xExtent;
                                final double yStart = ymin + yOffset;
                                final double yEnd = yStart + yExtent;
                                Envelope searchEnvelope = new Envelope(xStart, xEnd, yStart, yEnd);
                                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 x=[%a,%a] y=[%a,%a]", level, xStart, xEnd, yStart, yEnd)).isLessThanOrEqualTo(monitor.getCoveredArea());
                            }
                        }
                    }
                }
            }
        }
    }
}
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