use of org.neo4j.gis.spatial.index.Envelope in project neo4j by neo4j.
the class SpaceFillingCurveTest method shouldCreateSimple2DZOrderCurveAtLevel5.
@Test
void shouldCreateSimple2DZOrderCurveAtLevel5() {
Envelope envelope = new Envelope(-8, 8, -8, 8);
assertAtLevel(new ZOrderSpaceFillingCurve2D(envelope, 5), envelope);
}
use of org.neo4j.gis.spatial.index.Envelope in project neo4j by neo4j.
the class SpaceFillingCurveTest method shouldGet2DHilbertSearchTilesForWideRangeAtManyLevels.
@Test
void shouldGet2DHilbertSearchTilesForWideRangeAtManyLevels() {
final int xmin = -100;
final int xmax = 100;
final int ymin = -100;
final int ymax = 100;
Envelope envelope = new Envelope(xmin, xmax, ymin, ymax);
for (int level = 1; level <= HilbertSpaceFillingCurve2D.MAX_LEVEL; level++) {
HilbertSpaceFillingCurve2D curve = new HilbertSpaceFillingCurve2D(envelope, level);
final int delta = 1;
final int xhalf = xmin + (xmax - xmin) / 2;
final int yhalf = ymin + (ymax - ymin) / 2;
Envelope q1 = new Envelope(xmin, xhalf - delta, ymin, yhalf - delta);
Envelope q2 = new Envelope(xmin, xhalf - delta, yhalf, ymax);
Envelope q3 = new Envelope(xhalf, xmax, yhalf, ymax);
Envelope q4 = new Envelope(xhalf, xmax, ymin, yhalf - delta);
// Bottom left should give 1/4 of all tiles started at index 0
assertTiles(curve.getTilesIntersectingEnvelope(q1), new SpaceFillingCurve.LongRange(0, curve.getValueWidth() / 4 - 1));
// Top left should give 1/4 of all tiles started at index 1/4
assertTiles(curve.getTilesIntersectingEnvelope(q2), new SpaceFillingCurve.LongRange(curve.getValueWidth() / 4, curve.getValueWidth() / 2 - 1));
// Top right should give 1/4 of all tiles started at index 1/2
assertTiles(curve.getTilesIntersectingEnvelope(q3), new SpaceFillingCurve.LongRange(curve.getValueWidth() / 2, 3 * curve.getValueWidth() / 4 - 1));
// Bottom right should give 1/4 of all tiles started at index 3/4
assertTiles(curve.getTilesIntersectingEnvelope(q4), new SpaceFillingCurve.LongRange(3 * curve.getValueWidth() / 4, curve.getValueWidth() - 1));
}
}
use of org.neo4j.gis.spatial.index.Envelope in project neo4j by neo4j.
the class SpaceFillingCurve method getTilesIntersectingEnvelope.
public List<LongRange> getTilesIntersectingEnvelope(double[] fromOrNull, double[] toOrNull, SpaceFillingCurveConfiguration config) {
double[] from = fromOrNull == null ? range.getMin() : Arrays.copyOf(fromOrNull, fromOrNull.length);
double[] to = toOrNull == null ? range.getMax() : Arrays.copyOf(toOrNull, toOrNull.length);
for (int i = 0; i < from.length; i++) {
if (from[i] > to[i]) {
if (fromOrNull == null) {
to[i] = from[i];
} else if (toOrNull == null) {
from[i] = to[i];
} else {
throw new IllegalArgumentException("Invalid range, min greater than max: " + from[i] + " > " + to[i]);
}
}
}
Envelope referenceEnvelope = new Envelope(from, to);
return getTilesIntersectingEnvelope(referenceEnvelope, config, null);
}
use of org.neo4j.gis.spatial.index.Envelope in project neo4j by neo4j.
the class SpatialIndexConfig method settingFromIndexConfig.
private static SpaceFillingCurveSettings settingFromIndexConfig(IndexConfig indexConfig, CoordinateReferenceSystem crs) {
final double[] min = asDoubleArray(indexConfig.get(IndexSettingUtil.spatialMinSettingForCrs(crs).getSettingName()));
final double[] max = asDoubleArray(indexConfig.get(IndexSettingUtil.spatialMaxSettingForCrs(crs).getSettingName()));
final Envelope envelope = new Envelope(min, max);
return new SpaceFillingCurveSettings(crs.getDimension(), envelope);
}
use of org.neo4j.gis.spatial.index.Envelope in project neo4j by neo4j.
the class SpaceFillingCurveSettingsFactoryTest method shouldGetCustomSettingsFor.
private static void shouldGetCustomSettingsFor(CoordinateReferenceSystem crs, double[] min, double[] max) {
CrsConfig crsConf = CrsConfig.group(crs);
Config config = Config.newBuilder().set(crsConf.min, Arrays.stream(min).boxed().collect(Collectors.toList())).set(crsConf.max, Arrays.stream(max).boxed().collect(Collectors.toList())).build();
shouldGetSettingsFor(config, crs, min.length, new Envelope(min, max));
}
Aggregations