Search in sources :

Example 1 with CoordinateReferenceSystem

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

the class Neo4jPackV2Test method randomPoint.

private PointValue randomPoint(int index, int dimension) {
    CoordinateReferenceSystem crs;
    if (index % 2 == 0) {
        double[] coordinates;
        double x = random.doubles(1, -180, 180).sum();
        double y = random.doubles(1, -90, 90).sum();
        crs = WGS84_3D;
        if (dimension == 2) {
            crs = WGS84;
            coordinates = new double[] { x, y };
            return unsafePointValue(crs, coordinates);
        }
        if (dimension == 3) {
            double z = random.doubles(1, Double.MIN_VALUE, Double.MAX_VALUE).sum();
            coordinates = new double[] { x, y, z };
            return unsafePointValue(crs, coordinates);
        }
    } else {
        crs = dimension == 2 ? Cartesian : Cartesian_3D;
    }
    return unsafePointValue(crs, random.doubles(dimension, Double.MIN_VALUE, Double.MAX_VALUE).toArray());
}
Also used : CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem)

Example 2 with CoordinateReferenceSystem

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

the class GenericKeyStateTest method comparePointsMustOnlyReturnZeroForEqualPoints.

@Test
void comparePointsMustOnlyReturnZeroForEqualPoints() {
    PointValue firstPoint = random.randomValues().nextPointValue();
    PointValue equalPoint = Values.point(firstPoint);
    CoordinateReferenceSystem crs = firstPoint.getCoordinateReferenceSystem();
    SpaceFillingCurve curve = noSpecificIndexSettings.forCrs(crs);
    Long spaceFillingCurveValue = curve.derivedValueFor(firstPoint.coordinate());
    PointValue centerPoint = Values.pointValue(crs, curve.centerPointFor(spaceFillingCurveValue));
    GenericKey firstKey = newKeyState();
    firstKey.writeValue(firstPoint, NEUTRAL);
    GenericKey equalKey = newKeyState();
    equalKey.writeValue(equalPoint, NEUTRAL);
    GenericKey centerKey = newKeyState();
    centerKey.writeValue(centerPoint, NEUTRAL);
    GenericKey noCoordsKey = newKeyState();
    noCoordsKey.writeValue(equalPoint, NEUTRAL);
    GeometryType.setNoCoordinates(noCoordsKey);
    assertEquals(0, firstKey.compareValueTo(equalKey), "expected keys to be equal");
    assertEquals(firstPoint.compareTo(centerPoint) != 0, firstKey.compareValueTo(centerKey) != 0, "expected keys to be equal if and only if source points are equal");
    assertEquals(0, firstKey.compareValueTo(noCoordsKey), "expected keys to be equal");
}
Also used : PointValue(org.neo4j.values.storable.PointValue) SpaceFillingCurve(org.neo4j.gis.spatial.index.curves.SpaceFillingCurve) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with CoordinateReferenceSystem

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

the class CompositeIndexAccessorCompatibility method testIndexSeekExactWithRange.

private void testIndexSeekExactWithRange(Value base1, Value base2, Value obj1, Value obj2, Value obj3, Value obj4, Value obj5) throws Exception {
    Assume.assumeTrue("Assume support for granular composite queries", testSuite.supportsGranularCompositeQueries());
    updateAndCommit(asList(add(1L, descriptor.schema(), base1, obj1), add(2L, descriptor.schema(), base1, obj2), add(3L, descriptor.schema(), base1, obj3), add(4L, descriptor.schema(), base1, obj4), add(5L, descriptor.schema(), base1, obj5), add(6L, descriptor.schema(), base2, obj1), add(7L, descriptor.schema(), base2, obj2), add(8L, descriptor.schema(), base2, obj3), add(9L, descriptor.schema(), base2, obj4), add(10L, descriptor.schema(), base2, obj5)));
    assertThat(query(exact(0, base1), range(1, obj2, true, obj4, false))).isEqualTo(asList(2L, 3L));
    assertThat(query(exact(0, base1), range(1, obj4, true, null, false))).isEqualTo(asList(4L, 5L));
    assertThat(query(exact(0, base1), range(1, obj4, false, null, true))).isEqualTo(singletonList(5L));
    assertThat(query(exact(0, base1), range(1, obj5, false, obj2, true))).isEqualTo(EMPTY_LIST);
    assertThat(query(exact(0, base1), range(1, null, false, obj3, false))).isEqualTo(asList(1L, 2L));
    assertThat(query(exact(0, base1), range(1, null, true, obj3, true))).isEqualTo(asList(1L, 2L, 3L));
    assertThat(query(exact(0, base1), range(1, obj1, false, obj2, true))).isEqualTo(singletonList(2L));
    assertThat(query(exact(0, base1), range(1, obj1, false, obj3, false))).isEqualTo(singletonList(2L));
    assertThat(query(exact(0, base2), range(1, obj2, true, obj4, false))).isEqualTo(asList(7L, 8L));
    assertThat(query(exact(0, base2), range(1, obj4, true, null, false))).isEqualTo(asList(9L, 10L));
    assertThat(query(exact(0, base2), range(1, obj4, false, null, true))).isEqualTo(singletonList(10L));
    assertThat(query(exact(0, base2), range(1, obj5, false, obj2, true))).isEqualTo(EMPTY_LIST);
    assertThat(query(exact(0, base2), range(1, null, false, obj3, false))).isEqualTo(asList(6L, 7L));
    assertThat(query(exact(0, base2), range(1, null, true, obj3, true))).isEqualTo(asList(6L, 7L, 8L));
    assertThat(query(exact(0, base2), range(1, obj1, false, obj2, true))).isEqualTo(singletonList(7L));
    assertThat(query(exact(0, base2), range(1, obj1, false, obj3, false))).isEqualTo(singletonList(7L));
    ValueGroup valueGroup = obj1.valueGroup();
    if (valueGroup != GEOMETRY && valueGroup != GEOMETRY_ARRAY) {
        assertThat(query(exact(0, base1), range(1, valueGroup))).isEqualTo(asList(1L, 2L, 3L, 4L, 5L));
        assertThat(query(exact(0, base2), range(1, valueGroup))).isEqualTo(asList(6L, 7L, 8L, 9L, 10L));
    } else {
        CoordinateReferenceSystem crs = getCrs(obj1);
        assertThat(query(exact(0, base1), range(1, crs))).isEqualTo(asList(1L, 2L, 3L, 4L, 5L));
        assertThat(query(exact(0, base2), range(1, crs))).isEqualTo(asList(6L, 7L, 8L, 9L, 10L));
    }
}
Also used : ValueGroup(org.neo4j.values.storable.ValueGroup) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem)

Example 4 with CoordinateReferenceSystem

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

the class AppendOnlyValuesContainer method readPoint.

private static PointValue readPoint(ByteBuffer chunk, int offset) {
    final int crsCode = chunk.getInt(offset);
    offset += Integer.BYTES;
    final CoordinateReferenceSystem crs = CoordinateReferenceSystem.get(crsCode);
    final double[] coordinate = new double[crs.getDimension()];
    for (int i = 0; i < coordinate.length; i++) {
        coordinate[i] = chunk.getDouble(offset);
        offset += Double.BYTES;
    }
    return pointValue(crs, coordinate);
}
Also used : CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem)

Example 5 with CoordinateReferenceSystem

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

the class SpatialIndexConfigTest method mustAddSpatialConfigToMap.

@Test
void mustAddSpatialConfigToMap() {
    Map<String, Value> map = new HashMap<>();
    for (CoordinateReferenceSystem crs : CoordinateReferenceSystem.all()) {
        Config config = Config.defaults();
        SpaceFillingCurveSettings spaceFillingCurveSettings = new ConfiguredSpaceFillingCurveSettingsCache(config).forCRS(crs);
        SpatialIndexConfig.addSpatialConfig(map, crs, spaceFillingCurveSettings);
        assertNotNull(map.remove(IndexSettingUtil.spatialMinSettingForCrs(crs).getSettingName()));
        assertNotNull(map.remove(IndexSettingUtil.spatialMaxSettingForCrs(crs).getSettingName()));
        assertTrue(map.isEmpty());
    }
}
Also used : HashMap(java.util.HashMap) SpaceFillingCurveSettings(org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings) Config(org.neo4j.configuration.Config) IndexConfig(org.neo4j.internal.schema.IndexConfig) ConfiguredSpaceFillingCurveSettingsCache(org.neo4j.kernel.impl.index.schema.config.ConfiguredSpaceFillingCurveSettingsCache) Value(org.neo4j.values.storable.Value) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) Test(org.junit.jupiter.api.Test)

Aggregations

CoordinateReferenceSystem (org.neo4j.values.storable.CoordinateReferenceSystem)21 Test (org.junit.jupiter.api.Test)10 HashMap (java.util.HashMap)5 IndexConfig (org.neo4j.internal.schema.IndexConfig)5 PointValue (org.neo4j.values.storable.PointValue)5 SpaceFillingCurveSettings (org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings)4 Value (org.neo4j.values.storable.Value)4 SpaceFillingCurve (org.neo4j.gis.spatial.index.curves.SpaceFillingCurve)3 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Config (org.neo4j.configuration.Config)2 Node (org.neo4j.graphdb.Node)2 Transaction (org.neo4j.graphdb.Transaction)2 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)2 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)2 IndexDirectoryStructure (org.neo4j.kernel.api.index.IndexDirectoryStructure)2 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)2 ConfiguredSpaceFillingCurveSettingsCache (org.neo4j.kernel.impl.index.schema.config.ConfiguredSpaceFillingCurveSettingsCache)2 IndexSpecificSpaceFillingCurveSettings (org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings)2 DoubleArray (org.neo4j.values.storable.DoubleArray)2