use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class TestRecursivePrefixTreeStrategy method q.
private SpatialArgs q(Point pt, double distDEG, double distErrPct) {
Shape shape = ctx.makeCircle(pt, distDEG);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, shape);
args.setDistErrPct(distErrPct);
return args;
}
use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class SpatialRPTFieldTypeTest method testShapeToFromStringWKT.
public void testShapeToFromStringWKT() throws Exception {
setupRPTField("miles", "true", "WKT", random().nextBoolean() ? new SpatialRecursivePrefixTreeFieldType() : new RptWithGeometrySpatialField());
AbstractSpatialFieldType ftype = (AbstractSpatialFieldType) h.getCore().getLatestSchema().getField("geo").getType();
String wkt = "POINT (1 2)";
Shape shape = ftype.parseShape(wkt);
String out = ftype.shapeToString(shape);
assertEquals(wkt, out);
//assert fails GeoJSON
try {
ftype.parseShape("{\"type\":\"Point\",\"coordinates\":[1,2]}");
fail("Should not parse GeoJSON if told format is WKT");
} catch (SolrException e) {
// expected
System.out.println(e);
}
}
use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class NumberRangePrefixTreeStrategy method calcFacets.
/** Calculates facets between {@code start} and {@code end} to a detail level one greater than that provided by the
* arguments. For example providing March to October of 2014 would return facets to the day level of those months.
* This is just a convenience method.
* @see #calcFacets(IndexReaderContext, Bits, Shape, int)
*/
public Facets calcFacets(IndexReaderContext context, Bits topAcceptDocs, UnitNRShape start, UnitNRShape end) throws IOException {
Shape facetRange = getGrid().toRangeShape(start, end);
int detailLevel = Math.max(start.getLevel(), end.getLevel()) + 1;
return calcFacets(context, topAcceptDocs, facetRange, detailLevel);
}
use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class AbstractSpatialFieldType method createFields.
@Override
public List<IndexableField> createFields(SchemaField field, Object val) {
String shapeStr = null;
Shape shape;
if (val instanceof Shape) {
shape = ((Shape) val);
} else {
shapeStr = val.toString();
shape = parseShape(shapeStr);
}
if (shape == null) {
log.debug("Field {}: null shape for input: {}", field, val);
return Collections.emptyList();
}
List<IndexableField> result = new ArrayList<>();
if (field.indexed() || field.hasDocValues()) {
T strategy = getStrategy(field.getName());
result.addAll(Arrays.asList(strategy.createIndexableFields(shape)));
}
if (field.stored()) {
result.add(new StoredField(field.getName(), getStoredValue(shape, shapeStr)));
}
return result;
}
use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class DateRangeField method getRangeQuery.
@Override
public Query getRangeQuery(QParser parser, SchemaField field, String startStr, String endStr, boolean minInclusive, boolean maxInclusive) {
if (parser == null) {
//null when invoked by SimpleFacets. But getQueryFromSpatialArgs expects to get localParams.
final SolrRequestInfo requestInfo = SolrRequestInfo.getRequestInfo();
parser = new QParser("", null, requestInfo.getReq().getParams(), requestInfo.getReq()) {
@Override
public Query parse() throws SyntaxError {
throw new IllegalStateException();
}
};
}
Calendar startCal;
if (startStr == null) {
startCal = tree.newCal();
} else {
startCal = parseCalendar(startStr);
if (!minInclusive) {
startCal.add(Calendar.MILLISECOND, 1);
}
}
Calendar endCal;
if (endStr == null) {
endCal = tree.newCal();
} else {
endCal = parseCalendar(endStr);
if (!maxInclusive) {
endCal.add(Calendar.MILLISECOND, -1);
}
}
Shape shape = tree.toRangeShape(tree.toShape(startCal), tree.toShape(endCal));
SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.Intersects, shape);
return getQueryFromSpatialArgs(parser, field, spatialArgs);
}
Aggregations