use of org.locationtech.spatial4j.shape.Shape 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);
}
use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class GeoJSONWriter method writeGeo.
protected void writeGeo(Object geo) throws IOException {
Shape shape = null;
String str = null;
if (geo instanceof Shape) {
shape = (Shape) geo;
} else if (geo instanceof IndexableField) {
str = ((IndexableField) geo).stringValue();
} else if (geo instanceof WriteableGeoJSON) {
shape = ((WriteableGeoJSON) geo).shape;
} else {
str = geo.toString();
}
if (str != null) {
// Assume it is well formed JSON
if (str.startsWith("{") && str.endsWith("}")) {
writer.write(str);
return;
}
if (formats == null) {
// *stored* values for the field look like JSON until we actually try to read them
throw new SolrException(ErrorCode.BAD_REQUEST, "GeoJSON unable to write field: '&" + GeoJSONResponseWriter.FIELD + "=" + geofield + "' (" + str + ")");
}
shape = formats.read(str);
}
if (geowriter == null) {
throw new SolrException(ErrorCode.BAD_REQUEST, "GeoJSON unable to write field: '&" + GeoJSONResponseWriter.FIELD + "=" + geofield + "'");
}
if (shape != null) {
geowriter.write(writer, shape);
}
}
use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class RecursivePrefixTreeStrategy method makeQuery.
@Override
public Query makeQuery(SpatialArgs args) {
final SpatialOperation op = args.getOperation();
Shape shape = args.getShape();
int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));
if (op == SpatialOperation.Intersects) {
if (isGridAlignedShape(args.getShape())) {
return makeGridShapeIntersectsQuery(args.getShape());
}
return new IntersectsPrefixTreeQuery(shape, getFieldName(), grid, detailLevel, prefixGridScanLevel);
} else if (op == SpatialOperation.IsWithin) {
return new WithinPrefixTreeQuery(shape, getFieldName(), grid, detailLevel, prefixGridScanLevel, //-1 flag is slower but ensures correct results
-1);
} else if (op == SpatialOperation.Contains) {
return new ContainsPrefixTreeQuery(shape, getFieldName(), grid, detailLevel, multiOverlappingIndexedShapes);
}
throw new UnsupportedSpatialOperation(op);
}
use of org.locationtech.spatial4j.shape.Shape 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);
}
use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class AbstractSpatialFieldType method createSpatialQuery.
//--------------------------------------------------------------
// Query Support
//--------------------------------------------------------------
/**
* Implemented for compatibility with geofilt & bbox query parsers:
* {@link SpatialQueryable}.
*/
@Override
public Query createSpatialQuery(QParser parser, SpatialOptions options) {
Point pt = SpatialUtils.parsePointSolrException(options.pointStr, ctx);
double distDeg = DistanceUtils.dist2Degrees(options.distance, options.radius);
Shape shape = ctx.makeCircle(pt, distDeg);
if (options.bbox)
shape = shape.getBoundingBox();
SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.Intersects, shape);
return getQueryFromSpatialArgs(parser, options.field, spatialArgs);
}
Aggregations