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);
}
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);
}
}
}
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();
}
}
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);
}
}
}
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);
}
Aggregations