Search in sources :

Example 46 with Point

use of org.locationtech.spatial4j.shape.Point in project lucene-solr by apache.

the class DistanceStrategyTest method testRecipScore.

@Test
public void testRecipScore() throws IOException {
    Point p100 = ctx.makePoint(2.02, 0.98);
    adoc("100", p100);
    Point p101 = ctx.makePoint(-1.001, 4.001);
    adoc("101", p101);
    //test score for nothing
    adoc("103", (Shape) null);
    //test deleted
    adoc("999", ctx.makePoint(2, 1));
    commit();
    deleteDoc("999");
    commit();
    double dist = ctx.getDistCalc().distance(p100, p101);
    Shape queryShape = ctx.makeCircle(2.01, 0.99, dist);
    checkValueSource(strategy.makeRecipDistanceValueSource(queryShape), new float[] { 1.00f, 0.10f, 0f }, 0.09f);
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) Point(org.locationtech.spatial4j.shape.Point) Test(org.junit.Test)

Example 47 with Point

use of org.locationtech.spatial4j.shape.Point in project lucene-solr by apache.

the class SpatialUtils method parsePoint.

/** Parses either "lat, lon" (spaces optional on either comma side) or "x y" style formats. Spaces can be basically
   * anywhere.  And not any whitespace, just the space char.
   *
   * @param str Non-null; may have leading or trailing spaces
   * @param ctx Non-null
   * @return Non-null
   * @throws InvalidShapeException If for any reason there was a problem parsing the string or creating the point.
   */
public static Point parsePoint(String str, SpatialContext ctx) throws InvalidShapeException {
    //note we don't do generic whitespace, just a literal space char detection
    try {
        double x, y;
        //TODO use findIndexNotSpace instead?
        str = str.trim();
        int commaIdx = str.indexOf(',');
        if (commaIdx == -1) {
            //  "x y" format
            int spaceIdx = str.indexOf(' ');
            if (spaceIdx == -1)
                throw new InvalidShapeException("Point must be in 'lat, lon' or 'x y' format: " + str);
            int middleEndIdx = findIndexNotSpace(str, spaceIdx + 1, +1);
            x = Double.parseDouble(str.substring(0, spaceIdx));
            y = Double.parseDouble(str.substring(middleEndIdx));
        } else {
            // "lat, lon" format
            int middleStartIdx = findIndexNotSpace(str, commaIdx - 1, -1);
            int middleEndIdx = findIndexNotSpace(str, commaIdx + 1, +1);
            y = Double.parseDouble(str.substring(0, middleStartIdx + 1));
            x = Double.parseDouble(str.substring(middleEndIdx));
        }
        //by default norm* methods do nothing but perhaps it's been customized
        x = ctx.normX(x);
        y = ctx.normY(y);
        //will verify x & y fit in boundary
        return ctx.makePoint(x, y);
    } catch (InvalidShapeException e) {
        throw e;
    } catch (Exception e) {
        throw new InvalidShapeException(e.toString(), e);
    }
}
Also used : InvalidShapeException(org.locationtech.spatial4j.exception.InvalidShapeException) Point(org.locationtech.spatial4j.shape.Point) SolrException(org.apache.solr.common.SolrException) InvalidShapeException(org.locationtech.spatial4j.exception.InvalidShapeException) ParseException(java.text.ParseException)

Example 48 with Point

use of org.locationtech.spatial4j.shape.Point in project lucene-solr by apache.

the class TestRecursivePrefixTreeStrategy method testPrecision.

@Test
public void testPrecision() throws IOException {
    init(GeohashPrefixTree.getMaxLevelsPossible());
    //lon, lat
    Point iPt = ctx.makePoint(2.8028712999999925, 48.3708044);
    addDocument(newDoc("iPt", iPt));
    commit();
    Point qPt = ctx.makePoint(2.4632387000000335, 48.6003516);
    final double KM2DEG = DistanceUtils.dist2Degrees(1, DistanceUtils.EARTH_MEAN_RADIUS_KM);
    final double DEG2KM = 1 / KM2DEG;
    //35.7499...
    final double DIST = 35.75;
    assertEquals(DIST, ctx.getDistCalc().distance(iPt, qPt) * DEG2KM, 0.001);
    //distErrPct will affect the query shape precision. The indexed precision
    // was set to nearly zilch via init(GeohashPrefixTree.getMaxLevelsPossible());
    //the suggested default, by the way
    final double distErrPct = 0.025;
    final double distMult = 1 + distErrPct;
    assertTrue(35.74 * distMult >= DIST);
    checkHits(q(qPt, 35.74 * KM2DEG, distErrPct), 1, null);
    assertTrue(30 * distMult < DIST);
    checkHits(q(qPt, 30 * KM2DEG, distErrPct), 0, null);
    assertTrue(33 * distMult < DIST);
    checkHits(q(qPt, 33 * KM2DEG, distErrPct), 0, null);
    assertTrue(34 * distMult < DIST);
    checkHits(q(qPt, 34 * KM2DEG, distErrPct), 0, null);
}
Also used : Point(org.locationtech.spatial4j.shape.Point) Test(org.junit.Test)

Example 49 with Point

use of org.locationtech.spatial4j.shape.Point in project lucene-solr by apache.

the class RandomSpatialOpFuzzyPrefixTreeTest method testPackedQuadPointsOnlyBug.

@Test
public void testPackedQuadPointsOnlyBug() throws IOException {
    // packed quad.  maxLevels doesn't matter.
    setupQuadGrid(1, true);
    setupCtx2D(ctx);
    ((PrefixTreeStrategy) strategy).setPointsOnly(true);
    Point point = ctx.makePoint(169.0, 107.0);
    adoc("0", point);
    commit();
    Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects, point));
    assertEquals(1, executeQuery(query, 1).numFound);
}
Also used : SpatialArgs(org.apache.lucene.spatial.query.SpatialArgs) Query(org.apache.lucene.search.Query) Point(org.locationtech.spatial4j.shape.Point) Test(org.junit.Test)

Example 50 with Point

use of org.locationtech.spatial4j.shape.Point in project lucene-solr by apache.

the class PointVectorStrategy method createIndexableFields.

/** @see #createIndexableFields(org.locationtech.spatial4j.shape.Shape) */
public Field[] createIndexableFields(Point point) {
    Field[] fields = new Field[fieldsLen];
    int idx = -1;
    if (hasStored) {
        fields[++idx] = new StoredField(fieldNameX, point.getX());
        fields[++idx] = new StoredField(fieldNameY, point.getY());
    }
    if (hasDocVals) {
        fields[++idx] = new DoubleDocValuesField(fieldNameX, point.getX());
        fields[++idx] = new DoubleDocValuesField(fieldNameY, point.getY());
    }
    if (hasPointVals) {
        fields[++idx] = new DoublePoint(fieldNameX, point.getX());
        fields[++idx] = new DoublePoint(fieldNameY, point.getY());
    }
    if (legacyNumericFieldType != null) {
        fields[++idx] = new LegacyDoubleField(fieldNameX, point.getX(), legacyNumericFieldType);
        fields[++idx] = new LegacyDoubleField(fieldNameY, point.getY(), legacyNumericFieldType);
    }
    assert idx == fields.length - 1;
    return fields;
}
Also used : StoredField(org.apache.lucene.document.StoredField) LegacyDoubleField(org.apache.solr.legacy.LegacyDoubleField) DoubleDocValuesField(org.apache.lucene.document.DoubleDocValuesField) Field(org.apache.lucene.document.Field) StoredField(org.apache.lucene.document.StoredField) LegacyDoubleField(org.apache.solr.legacy.LegacyDoubleField) DoubleDocValuesField(org.apache.lucene.document.DoubleDocValuesField) DoublePoint(org.apache.lucene.document.DoublePoint) DoublePoint(org.apache.lucene.document.DoublePoint) Point(org.locationtech.spatial4j.shape.Point)

Aggregations

Point (org.locationtech.spatial4j.shape.Point)71 Test (org.junit.Test)21 Shape (org.locationtech.spatial4j.shape.Shape)15 Query (org.apache.lucene.search.Query)9 SpatialArgs (org.apache.lucene.spatial.query.SpatialArgs)9 Rectangle (org.locationtech.spatial4j.shape.Rectangle)9 ArrayList (java.util.ArrayList)7 Field (org.apache.lucene.document.Field)6 PointImpl (org.locationtech.spatial4j.shape.impl.PointImpl)6 BooleanQuery (org.apache.lucene.search.BooleanQuery)5 TopDocs (org.apache.lucene.search.TopDocs)5 IOException (java.io.IOException)4 SpatialContext (org.locationtech.spatial4j.context.SpatialContext)4 Document (org.apache.lucene.document.Document)3 StoredField (org.apache.lucene.document.StoredField)3 IndexReader (org.apache.lucene.index.IndexReader)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 ScoreDoc (org.apache.lucene.search.ScoreDoc)3 Cell (org.apache.lucene.spatial.prefix.tree.Cell)3 CellIterator (org.apache.lucene.spatial.prefix.tree.CellIterator)3