use of org.locationtech.spatial4j.shape.Rectangle in project lucene-solr by apache.
the class TestBBoxStrategy method randomIndexedShape.
@Override
protected Shape randomIndexedShape() {
Rectangle world = ctx.getWorldBounds();
if (// increased chance of getting one of these
random().nextInt(10) == 0)
return world;
int worldWidth = (int) Math.round(world.getWidth());
int deltaLeft = nextIntInclusive(worldWidth);
int deltaRight = nextIntInclusive(worldWidth - deltaLeft);
int worldHeight = (int) Math.round(world.getHeight());
int deltaTop = nextIntInclusive(worldHeight);
int deltaBottom = nextIntInclusive(worldHeight - deltaTop);
if (ctx.isGeo() && (deltaLeft != 0 || deltaRight != 0)) {
//if geo & doesn't world-wrap, we shift randomly to potentially cross dateline
int shift = nextIntInclusive(360);
return ctx.makeRectangle(DistanceUtils.normLonDEG(world.getMinX() + deltaLeft + shift), DistanceUtils.normLonDEG(world.getMaxX() - deltaRight + shift), world.getMinY() + deltaBottom, world.getMaxY() - deltaTop);
} else {
return ctx.makeRectangle(world.getMinX() + deltaLeft, world.getMaxX() - deltaRight, world.getMinY() + deltaBottom, world.getMaxY() - deltaTop);
}
}
use of org.locationtech.spatial4j.shape.Rectangle in project lucene-solr by apache.
the class CompositeStrategyTest method randomCircle.
//TODO move up
private Shape randomCircle() {
final Point point = randomPoint();
//TODO pick using gaussian
double radius;
if (ctx.isGeo()) {
radius = randomDouble() * 100;
} else {
//find distance to closest edge
final Rectangle worldBounds = ctx.getWorldBounds();
double maxRad = point.getX() - worldBounds.getMinX();
maxRad = Math.min(maxRad, worldBounds.getMaxX() - point.getX());
maxRad = Math.min(maxRad, point.getY() - worldBounds.getMinY());
maxRad = Math.min(maxRad, worldBounds.getMaxY() - point.getY());
radius = randomDouble() * maxRad;
}
return ctx.makeCircle(point, radius);
}
use of org.locationtech.spatial4j.shape.Rectangle in project lucene-solr by apache.
the class QuadPrefixTree method checkBattenberg.
protected void checkBattenberg(char c, double cx, double cy, int level, List<Cell> matches, BytesRef str, Shape shape, int maxLevel) {
assert str.length == level;
assert str.offset == 0;
double w = levelW[level] / 2;
double h = levelH[level] / 2;
int strlen = str.length;
Rectangle rectangle = ctx.makeRectangle(cx - w, cx + w, cy - h, cy + h);
SpatialRelation v = shape.relate(rectangle);
if (SpatialRelation.CONTAINS == v) {
//append
str.bytes[str.length++] = (byte) c;
//str.append(SpatialPrefixGrid.COVER);
matches.add(new QuadCell(BytesRef.deepCopyOf(str), v.transpose()));
} else if (SpatialRelation.DISJOINT == v) {
// nothing
} else {
// SpatialRelation.WITHIN, SpatialRelation.INTERSECTS
//append
str.bytes[str.length++] = (byte) c;
int nextLevel = level + 1;
if (nextLevel >= maxLevel) {
//str.append(SpatialPrefixGrid.INTERSECTS);
matches.add(new QuadCell(BytesRef.deepCopyOf(str), v.transpose()));
} else {
build(cx, cy, nextLevel, matches, str, shape, maxLevel);
}
}
str.length = strlen;
}
use of org.locationtech.spatial4j.shape.Rectangle in project lucene-solr by apache.
the class LegacyPrefixTree method getDistanceForLevel.
public double getDistanceForLevel(int level) {
if (level < 1 || level > getMaxLevels())
throw new IllegalArgumentException("Level must be in 1 to maxLevels range");
//TODO cache for each level
Cell cell = getCell(ctx.getWorldBounds().getCenter(), level);
Rectangle bbox = cell.getShape().getBoundingBox();
double width = bbox.getWidth();
double height = bbox.getHeight();
// than the correct one but it's okay to over-estimate.
return Math.sqrt(width * width + height * height);
}
use of org.locationtech.spatial4j.shape.Rectangle in project lucene-solr by apache.
the class BBoxStrategy method makeQuery.
//---------------------------------
// Query Building
//---------------------------------
// Utility on SpatialStrategy?
// public Query makeQueryWithValueSource(SpatialArgs args, ValueSource valueSource) {
// return new CustomScoreQuery(makeQuery(args), new FunctionQuery(valueSource));
//or...
// return new BooleanQuery.Builder()
// .add(new FunctionQuery(valueSource), BooleanClause.Occur.MUST)//matches everything and provides score
// .add(filterQuery, BooleanClause.Occur.FILTER)//filters (score isn't used)
// .build();
// }
@Override
public Query makeQuery(SpatialArgs args) {
Shape shape = args.getShape();
if (!(shape instanceof Rectangle))
throw new UnsupportedOperationException("Can only query by Rectangle, not " + shape);
Rectangle bbox = (Rectangle) shape;
Query spatial;
// Useful for understanding Relations:
// http://edndoc.esri.com/arcsde/9.1/general_topics/understand_spatial_relations.htm
SpatialOperation op = args.getOperation();
if (op == SpatialOperation.BBoxIntersects)
spatial = makeIntersects(bbox);
else if (op == SpatialOperation.BBoxWithin)
spatial = makeWithin(bbox);
else if (op == SpatialOperation.Contains)
spatial = makeContains(bbox);
else if (op == SpatialOperation.Intersects)
spatial = makeIntersects(bbox);
else if (op == SpatialOperation.IsEqualTo)
spatial = makeEquals(bbox);
else if (op == SpatialOperation.IsDisjointTo)
spatial = makeDisjoint(bbox);
else if (op == SpatialOperation.IsWithin)
spatial = makeWithin(bbox);
else {
//no Overlaps support yet
throw new UnsupportedSpatialOperation(op);
}
return new ConstantScoreQuery(spatial);
}
Aggregations