public DistanceCollector(Coordinates centerCoordinates, int hitsCount, String fieldname) { this.center = Point.fromCoordinates( centerCoordinates ); this.distances = new SpatialResultsCollector( hitsCount ); this.latitudeField = SpatialHelper.formatLatitude( fieldname ); this.longitudeField = SpatialHelper.formatLongitude( fieldname ); }
@Override public Scorer scorer(LeafReaderContext context) throws IOException { DocIdSetIterator iterator = createDocIdSetIterator( context ); return new ConstantScoreScorer( this, score(), iterator ); } };
public DistanceComparator(Point center, int numHits, String fieldName) { this.center = center; this.distances = new double[numHits]; this.latitudeField = SpatialHelper.formatLatitude( fieldName ); this.longitudeField = SpatialHelper.formatLongitude( fieldName ); }
/** * Compute distance between two points * * @param other a {@link org.hibernate.search.spatial.impl.Point} object. * @return the distance between points * @see <a href="http://www.movable-type.co.uk/scripts/latlong.html">Distance haversine formula</a> */ public double getDistanceTo(Point other) { return getDistanceTo( other.getLatitude(), other.getLongitude() ); }
public boolean projectedBoundingBoxCellsIdsInclusionTest( Point center, Double radius) { Integer spatialHashLevel = SpatialHelper.findBestSpatialHashLevelForSearchRange( radius ); List<String> cellsIds = SpatialHelper.getSpatialHashCellsIds( center, radius, spatialHashLevel ); Point edge = null; boolean validated = true; for ( int heading = 0; heading < 360; heading++ ) { edge = center.computeDestination( radius, heading ); String cellId = SpatialHelper.getSpatialHashCellId( edge, spatialHashLevel ); validated &= cellsIds.contains( cellId ); } return validated; }
/** * @param latitude in degrees * @param longitude in degrees * @return a point with coordinates given in degrees */ public static Point fromDegreesInclusive(double latitude, double longitude) { return new Point( normalizeLatitude( latitude ), normalizeLongitudeInclusive( longitude ) ); }
/** * @param latitude in degrees * @param longitude in degrees * @return a point with coordinates given in degrees */ public static Point fromDegrees(double latitude, double longitude) { return new Point( normalizeLatitude( latitude ), normalizeLongitude( longitude ) ); }
/** * @param latitude in radians * @param longitude in radians * @return a point with coordinates given in radians */ public static Point fromRadians(double latitude, double longitude) { return fromDegrees( latitude * GeometricConstants.TO_DEGREES_RATIO, longitude * GeometricConstants.TO_DEGREES_RATIO ); }
private double distanceTo(final int doc) { if ( docsWithLatitude.get( doc ) && docsWithLongitude.get( doc ) ) { return center.getDistanceTo( coordinate( latitudeValues, doc ), coordinate( longitudeValues, doc ) ); } else { return Double.MAX_VALUE; } }
public String getCoordinatesField() { if ( coordinatesField != null ) { return coordinatesField; } else { return SpatialHelper.stripSpatialFieldSuffix( latitudeField ); } }
@Override public FieldComparator<?> newComparator(String fieldName, int numHits, int sortPos, boolean reversed) throws IOException { return new DistanceComparator( center, numHits, fieldName ); } }
/** * @param longitude in degrees * @return longitude normalized in ]-180;+180] */ public static double normalizeLongitude(double longitude) { if ( longitude == ( -GeometricConstants.LONGITUDE_DEGREE_RANGE / 2 ) ) { return GeometricConstants.LONGITUDE_DEGREE_RANGE / 2 ; } else { return normalizeLongitudeInclusive( longitude ); } }
private String getLatitudeField() { if ( latitudeField != null ) { return latitudeField; } else { return SpatialHelper.formatLatitude( coordinatesField ); } }
private String getLongitudeField() { if ( longitudeField != null ) { return longitudeField; } else { return SpatialHelper.formatLongitude( coordinatesField ); } }
public DistanceCollector(Coordinates centerCoordinates, int hitsCount, String fieldname) { this.center = Point.fromCoordinates( centerCoordinates ); this.distances = new SpatialResultsCollector( hitsCount ); this.latitudeField = SpatialHelper.formatLatitude( fieldname ); this.longitudeField = SpatialHelper.formatLongitude( fieldname ); }
/** * @param latitude in degrees * @param longitude in degrees * @return a point with coordinates given in degrees */ public static Point fromDegreesInclusive(double latitude, double longitude) { return new Point( normalizeLatitude( latitude ), normalizeLongitudeInclusive( longitude ) ); }
@Override public Scorer scorer(LeafReaderContext context) throws IOException { DocIdSetIterator iterator = createDocIdSetIterator( context ); return new ConstantScoreScorer( this, score(), iterator ); } };
public String getCoordinatesField() { if ( coordinatesField != null ) { return coordinatesField; } else { return SpatialHelper.stripSpatialFieldSuffix( latitudeField ); } }
@Override public FieldComparator<?> newComparator(String fieldName, int numHits, int sortPos, boolean reversed) throws IOException { return new DistanceComparator( center, numHits, fieldName ); } }
/** * @param longitude in degrees * @return longitude normalized in ]-180;+180] */ public static double normalizeLongitude(double longitude) { if ( longitude == ( -GeometricConstants.LONGITUDE_DEGREE_RANGE / 2 ) ) { return GeometricConstants.LONGITUDE_DEGREE_RANGE / 2 ; } else { return normalizeLongitudeInclusive( longitude ); } }