Search in sources :

Example 71 with Shape

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;
}
Also used : SpatialArgs(org.apache.lucene.spatial.query.SpatialArgs) Shape(org.locationtech.spatial4j.shape.Shape)

Example 72 with Shape

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);
    }
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) SolrException(org.apache.solr.common.SolrException)

Example 73 with Shape

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);
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) UnitNRShape(org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape) Point(org.locationtech.spatial4j.shape.Point)

Example 74 with Shape

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;
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) StoredField(org.apache.lucene.document.StoredField) Shape(org.locationtech.spatial4j.shape.Shape) ArrayList(java.util.ArrayList)

Example 75 with Shape

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);
}
Also used : SpatialArgs(org.apache.lucene.spatial.query.SpatialArgs) NRShape(org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.NRShape) Shape(org.locationtech.spatial4j.shape.Shape) UnitNRShape(org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape) Query(org.apache.lucene.search.Query) SyntaxError(org.apache.solr.search.SyntaxError) Calendar(java.util.Calendar) QParser(org.apache.solr.search.QParser) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo)

Aggregations

Shape (org.locationtech.spatial4j.shape.Shape)81 Test (org.junit.Test)18 Point (org.locationtech.spatial4j.shape.Point)16 ArrayList (java.util.ArrayList)14 SpatialArgs (org.apache.lucene.spatial.query.SpatialArgs)13 CoordinatesBuilder (org.elasticsearch.common.geo.builders.CoordinatesBuilder)13 PolygonBuilder (org.elasticsearch.common.geo.builders.PolygonBuilder)11 Document (org.apache.lucene.document.Document)10 Field (org.apache.lucene.document.Field)9 Query (org.apache.lucene.search.Query)8 Rectangle (org.locationtech.spatial4j.shape.Rectangle)8 StoredField (org.apache.lucene.document.StoredField)7 SpatialOperation (org.apache.lucene.spatial.query.SpatialOperation)7 LineStringBuilder (org.elasticsearch.common.geo.builders.LineStringBuilder)7 UnitNRShape (org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape)6 StringField (org.apache.lucene.document.StringField)5 TextField (org.apache.lucene.document.TextField)4 IndexableField (org.apache.lucene.index.IndexableField)4 UnsupportedSpatialOperation (org.apache.lucene.spatial.query.UnsupportedSpatialOperation)4 SpatialContext (org.locationtech.spatial4j.context.SpatialContext)4