/** * Returns the singleton point of this shape. Only applicable for point and circle shapes. * * @return */ public Point getPoint() { Preconditions.checkArgument(getType()==Type.POINT || getType()==Type.CIRCLE,"Shape does not have a single point"); return new Point(shape.getCenter().getY(), shape.getCenter().getX()); }
@Override public Point getCenter() { return s.getCenter(); }
for(Shape shape : shapes) System.out.println(shape.getCenter())
@Override public DocumentDistance apply(ScoreDoc doc) { return new LuceneDocumentDistance(doc, geoField, units, boundingCircle.getCenter(), requireContext, LuceneIndex.this); } });
@Override public double doubleValue() throws IOException { return distCalc.distance(queryPoint, shapeValues.value().getCenter()) * multiplier; }
@Override public Object execute(Object iThis, OIdentifiable iCurrentRecord, Object iCurrentResult, Object[] iParams, OCommandContext iContext) { if (containsNull(iParams)) { return null; } Shape shape = factory.fromObject(iParams[0]); Shape shape1 = factory.fromObject(iParams[1]); double distance = factory.context().getDistCalc().distance(shape.getCenter(), shape1.getCenter()); final double docDistInKM = DistanceUtils.degrees2Dist(distance, DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM); return docDistInKM * 1000; }
@Override protected Point readShape(BytesRef term) { scanCell = grid.readCell(term, scanCell); if (scanCell.getLevel() == grid.getMaxLevels()) return scanCell.getShape().getCenter(); return null; } }
protected Query makeQueryFromShape(Shape shape) { SpatialArgs args = new SpatialArgs(operation, shape); if (!Double.isNaN(distErrPct)) args.setDistErrPct(distErrPct); Query filterQuery = strategy.makeQuery(args); if (score) { //wrap with distance computing query DoubleValuesSource valueSource = strategy.makeDistanceValueSource(shape.getCenter()); return new FunctionScoreQuery(filterQuery, valueSource); } else { return filterQuery; // assume constant scoring } }
@Override public void onRecordAddedToResultSet(OLuceneQueryContext queryContext, OContextualRecordId recordId, Document doc, ScoreDoc score) { OSpatialQueryContext spatialContext = (OSpatialQueryContext) queryContext; if (spatialContext.spatialArgs != null) { Point docPoint = (Point) ctx.readShape(doc.get(strategy.getFieldName())); double docDistDEG = ctx.getDistCalc().distance(spatialContext.spatialArgs.getShape().getCenter(), docPoint); final double docDistInKM = DistanceUtils.degrees2Dist(docDistDEG, DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM); recordId.setContext(new HashMap<String, Object>() { { put("distance", docDistInKM); } }); } }
@Override public double getDistance() { List<String> wkts = getDocument().getProperty(geoProperty); double min = Double.POSITIVE_INFINITY; for (String wkt : wkts) { Shape shape; try { shape = index.getSpatialContext(geoProperty).readShapeFromWkt(wkt); double dist = index.getSpatialContext(geoProperty).calcDistance(shape.getCenter(), origin); min = Math.min(dist, min); } catch (ParseException e) { // ignore } } return GeoUnits.fromDegrees(min, units); } }
@Override public void onRecordAddedToResultSet(OLuceneQueryContext queryContext, OContextualRecordId recordId, Document doc, ScoreDoc score) { OSpatialQueryContext spatialContext = (OSpatialQueryContext) queryContext; if (spatialContext.spatialArgs != null) { updateLastAccess(); openIfClosed(); Point docPoint = (Point) ctx.readShape(doc.get(strategy.getFieldName())); double docDistDEG = ctx.getDistCalc().distance(spatialContext.spatialArgs.getShape().getCenter(), docPoint); final double docDistInKM = DistanceUtils.degrees2Dist(docDistDEG, DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM); recordId.setContext(new HashMap<String, Object>() { { put("distance", docDistInKM); } }); } }
/** * Returns a ValueSource with values ranging from 1 to 0, depending inversely * on the distance from {@link #makeDistanceValueSource(org.locationtech.spatial4j.shape.Point,double)}. * The formula is {@code c/(d + c)} where 'd' is the distance and 'c' is * one tenth the distance to the farthest edge from the center. Thus the * scores will be 1 for indexed points at the center of the query shape and as * low as ~0.1 at its furthest edges. */ public final DoubleValuesSource makeRecipDistanceValueSource(Shape queryShape) { Rectangle bbox = queryShape.getBoundingBox(); double diagonalDist = ctx.getDistCalc().distance( ctx.makePoint(bbox.getMinX(), bbox.getMinY()), bbox.getMaxX(), bbox.getMaxY()); double distToEdge = diagonalDist * 0.5; float c = (float)distToEdge * 0.1f;//one tenth DoubleValuesSource distance = makeDistanceValueSource(queryShape.getCenter(), 1.0); return new ReciprocalDoubleValuesSource(c, distance); }