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);
}
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);
}
}
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);
}
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);
}
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;
}
Aggregations