Search in sources :

Example 6 with PointValue

use of org.neo4j.values.storable.PointValue in project neo4j by neo4j.

the class SpatialIndexValueTestUtil method pointsWithSameValueOnSpaceFillingCurve.

public static Pair<PointValue, PointValue> pointsWithSameValueOnSpaceFillingCurve(Config config) {
    ConfiguredSpaceFillingCurveSettingsCache configuredCache = new ConfiguredSpaceFillingCurveSettingsCache(config);
    SpaceFillingCurveSettings spaceFillingCurveSettings = configuredCache.forCRS(CoordinateReferenceSystem.WGS84);
    SpaceFillingCurve curve = spaceFillingCurveSettings.curve();
    double[] origin = { 0.0, 0.0 };
    Long spaceFillingCurveMapForOrigin = curve.derivedValueFor(origin);
    double[] centerPointForOriginTile = curve.centerPointFor(spaceFillingCurveMapForOrigin);
    PointValue originValue = Values.pointValue(CoordinateReferenceSystem.WGS84, origin);
    PointValue centerPointValue = Values.pointValue(CoordinateReferenceSystem.WGS84, centerPointForOriginTile);
    assertThat(origin).as("need non equal points for this test").isNotEqualTo(centerPointValue);
    return Pair.of(originValue, centerPointValue);
}
Also used : PointValue(org.neo4j.values.storable.PointValue) SpaceFillingCurve(org.neo4j.gis.spatial.index.curves.SpaceFillingCurve)

Example 7 with PointValue

use of org.neo4j.values.storable.PointValue in project neo4j by neo4j.

the class IndexOrderTestBase method shouldDoOrderedCompositeIndexScanWithPointsInBothValuesWithOneGapBetween.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldDoOrderedCompositeIndexScanWithPointsInBothValuesWithOneGapBetween(IndexOrder indexOrder) throws Exception {
    List<Pair<Long, Value[]>> expected = new ArrayList<>();
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithTwoProps(tx, new String[] { "a" }, new String[] { "b" }));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, -500000), "a"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, -500000), "a"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, 500000), "a"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, 500000), "a"));
        expected.add(entityWithTwoProps(tx, "b", new String[] { "b" }));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, -500000, -500000)));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, 500000, -500000)));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, -500000, 500000)));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, 500000, 500000)));
        expected.add(entityWithTwoProps(tx, "c", new String[] { "b" }));
        tx.commit();
    }
    createCompositeIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
        try (var cursor = getEntityValueIndexCursor(tx)) {
            entityIndexScan(tx, index, cursor, constrained(indexOrder, true));
            assertCompositeResultsInOrder(expected, cursor, indexOrder);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Value(org.neo4j.values.storable.Value) Values.pointValue(org.neo4j.values.storable.Values.pointValue) TextValue(org.neo4j.values.storable.TextValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) PointValue(org.neo4j.values.storable.PointValue) ArrayList(java.util.ArrayList) Pair(org.neo4j.internal.helpers.collection.Pair) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with PointValue

use of org.neo4j.values.storable.PointValue in project neo4j by neo4j.

the class BatchInsertIndexTest method shouldPopulateIndexWithUniquePointsThatCollideOnSpaceFillingCurve.

@ParameterizedTest
@EnumSource(SchemaIndex.class)
void shouldPopulateIndexWithUniquePointsThatCollideOnSpaceFillingCurve(SchemaIndex schemaIndex) throws Exception {
    configure(schemaIndex);
    BatchInserter inserter = newBatchInserter();
    Pair<PointValue, PointValue> collidingPoints = SpatialIndexValueTestUtil.pointsWithSameValueOnSpaceFillingCurve(configBuilder.build());
    inserter.createNode(MapUtil.map("prop", collidingPoints.first()), LABEL_ONE);
    inserter.createNode(MapUtil.map("prop", collidingPoints.other()), LABEL_ONE);
    inserter.createDeferredConstraint(LABEL_ONE).assertPropertyIsUnique("prop").create();
    inserter.shutdown();
    GraphDatabaseService db = startGraphDatabaseServiceAndAwaitIndexes();
    try (Transaction tx = db.beginTx()) {
        assertSingleCorrectHit(collidingPoints.first(), tx);
        assertSingleCorrectHit(collidingPoints.other(), tx);
        tx.commit();
    }
}
Also used : BatchInserter(org.neo4j.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) PointValue(org.neo4j.values.storable.PointValue) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with PointValue

use of org.neo4j.values.storable.PointValue in project neo4j by neo4j.

the class IndexOrderTestBase method shouldNodeIndexScanInOrderWithPointsWithinSameTile.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldNodeIndexScanInOrderWithPointsWithinSameTile(IndexOrder indexOrder) throws Exception {
    Config config = Config.defaults();
    IndexSpecificSpaceFillingCurveSettings indexSettings = IndexSpecificSpaceFillingCurveSettings.fromConfig(config);
    SpaceFillingCurve curve = indexSettings.forCrs(WGS84);
    // given
    // Many random points that all are close enough to each other to belong to the same tile on the space filling curve.
    int nbrOfValues = 10000;
    PointValue origin = Values.pointValue(WGS84, 0.0, 0.0);
    Long derivedValueForCenterPoint = curve.derivedValueFor(origin.coordinate());
    double[] centerPoint = curve.centerPointFor(derivedValueForCenterPoint);
    double xWidthMultiplier = curve.getTileWidth(0, curve.getMaxLevel()) / 2;
    double yWidthMultiplier = curve.getTileWidth(1, curve.getMaxLevel()) / 2;
    List<Pair<Long, Value>> expected = new ArrayList<>();
    try (KernelTransaction tx = beginTransaction()) {
        // NOTE: strings come after points in natural ascending sort order
        expected.add(entityWithProp(tx, "a"));
        expected.add(entityWithProp(tx, "b"));
        for (int i = 0; i < nbrOfValues / 8; i++) {
            double x1 = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
            double x2 = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
            double y1 = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
            double y2 = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
            expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x1, centerPoint[1] + y1)));
            expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x1, centerPoint[1] + y2)));
            expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x2, centerPoint[1] + y1)));
            expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x2, centerPoint[1] + y2)));
        }
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
        try (var cursor = getEntityValueIndexCursor(tx)) {
            for (int i = 0; i < nbrOfValues / 8; i++) {
                double x1 = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
                double x2 = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
                double y1 = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
                double y2 = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
                expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x1, centerPoint[1] + y1)));
                expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x1, centerPoint[1] + y2)));
                expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x2, centerPoint[1] + y1)));
                expected.add(entityWithProp(tx, Values.pointValue(WGS84, centerPoint[0] + x2, centerPoint[1] + y2)));
            }
            expected.add(entityWithProp(tx, "c"));
            expected.add(entityWithProp(tx, "d"));
            entityIndexScan(tx, index, cursor, constrained(indexOrder, true));
            assertResultsInOrder(expected, cursor, indexOrder);
        }
    }
}
Also used : IndexSpecificSpaceFillingCurveSettings(org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) PointValue(org.neo4j.values.storable.PointValue) Config(org.neo4j.configuration.Config) ArrayList(java.util.ArrayList) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) SpaceFillingCurve(org.neo4j.gis.spatial.index.curves.SpaceFillingCurve) Pair(org.neo4j.internal.helpers.collection.Pair) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with PointValue

use of org.neo4j.values.storable.PointValue in project neo4j by neo4j.

the class ExtractorsTest method shouldExtractPoint.

@Test
void shouldExtractPoint() {
    // GIVEN
    Extractors extractors = new Extractors(',');
    PointValue value = Values.pointValue(CoordinateReferenceSystem.WGS84, 13.2, 56.7);
    // WHEN
    char[] asChars = "Point{latitude: 56.7, longitude: 13.2}".toCharArray();
    Extractors.PointExtractor extractor = extractors.point();
    String headerInfo = "{crs:WGS-84}";
    extractor.extract(asChars, 0, asChars.length, false, PointValue.parseHeaderInformation(headerInfo));
    // THEN
    assertEquals(value, extractor.value);
}
Also used : PointValue(org.neo4j.values.storable.PointValue) Test(org.junit.jupiter.api.Test)

Aggregations

PointValue (org.neo4j.values.storable.PointValue)32 Test (org.junit.jupiter.api.Test)16 ArrayList (java.util.ArrayList)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 Value (org.neo4j.values.storable.Value)9 EnumSource (org.junit.jupiter.params.provider.EnumSource)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 Transaction (org.neo4j.graphdb.Transaction)6 Pair (org.neo4j.internal.helpers.collection.Pair)6 CoordinateReferenceSystem (org.neo4j.values.storable.CoordinateReferenceSystem)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)5 Values.stringValue (org.neo4j.values.storable.Values.stringValue)5 Path (java.nio.file.Path)4 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)4 Node (org.neo4j.graphdb.Node)4 TextValue (org.neo4j.values.storable.TextValue)4 Values.pointValue (org.neo4j.values.storable.Values.pointValue)4 SpaceFillingCurve (org.neo4j.gis.spatial.index.curves.SpaceFillingCurve)3 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)3