Class PointInShapeEvaluator
java.lang.Object
org.springframework.data.couchbase.repository.query.support.PointInShapeEvaluator
- Direct Known Subclasses:
AwtPointInShapeEvaluator
PointInShapeEvaluator can be used to tell if a particular
Point
is contained by a Polygon
or
Circle
. It is most useful to eliminate false positive when a geo query has been made using a bounding box
approximation. For the purpose of this class, a point on the edge of a polygon isn't considered within
it. On the contrary a point on the edge of a circle is considered in it (distance from center <= radius). To that
end, additional methods
that return a List
of
objects with false positives removed are also provided. However, these need a Converter<T,
Point>
to extract the location attribute that should be tested against the polygon/circle.- Author:
- Simon Baslé
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
pointInCircle
(Point p, Circle c) abstract boolean
pointInCircle
(Point p, Point center, Distance radius) abstract boolean
pointInPolygon
(Point p, Point... points) abstract boolean
pointInPolygon
(Point p, Polygon polygon) <T> List<T>
removeFalsePositives
(Collection<? extends T> boundingBoxResults, Converter<T, Point> locationExtractor, Circle circle) Utility method to remove false positives from a collection of objects that have a notion of location, where we want to only include values that are located within a circle.<T> List<T>
removeFalsePositives
(Collection<? extends T> boundingBoxResults, Converter<T, Point> locationExtractor, Point... polygon) Utility method to remove false positives from a collection of objects that have a notion of location, where we want to only include values that are located within a polygon.<T> List<T>
removeFalsePositives
(Collection<? extends T> boundingBoxResults, Converter<T, Point> locationExtractor, Point center, Distance radius) Utility method to remove false positives from a collection of objects that have a notion of location, where we want to only include values that are located within a circle.<T> List<T>
removeFalsePositives
(Collection<? extends T> boundingBoxResults, Converter<T, Point> locationExtractor, Polygon polygon) Utility method to remove false positives from a collection of objects that have a notion of location, where we want to only include values that are located within a polygon.
-
Constructor Details
-
PointInShapeEvaluator
public PointInShapeEvaluator()
-
-
Method Details
-
pointInPolygon
- Parameters:
p
- the point to test.polygon
- the polygon we want the point to be in.- Returns:
- true if the polygon contains the point, false otherwise.
-
pointInPolygon
Determine if aPoint
is contained by a polygon represented as an array ofpoints
. The points are not required to form a closed shape, but can (by having the first and last points be the same).- Parameters:
p
- the point to test.points
- the Point[] representation of the polygon we want the point to be in.- Returns:
- true if the polygon contains the point, false otherwise.
-
pointInCircle
- Parameters:
p
- the point to test.c
- the Circle we want the point to be in.- Returns:
- true if the circle contains the point, false otherwise.
-
pointInCircle
- Parameters:
p
- the point to test.center
- the center Point of the Circle we want the point to be in.radius
- the Distance radius of the Circle we want the point to be in.- Returns:
- true if the circle contains the point, false otherwise.
-
removeFalsePositives
public <T> List<T> removeFalsePositives(Collection<? extends T> boundingBoxResults, Converter<T, Point> locationExtractor, Polygon polygon) Utility method to remove false positives from a collection of objects that have a notion of location, where we want to only include values that are located within a polygon. The collection should usually be already contained in the bounding box approximation of the polygon for maximum efficiency.- Type Parameters:
T
- the type of located value objects in the collection.- Parameters:
boundingBoxResults
- the collections of located objects approximately inside the target polygon.locationExtractor
- aConverter
to extract the location of the value objects.polygon
- the target polygon.- Returns:
- a
List
of the value objects which location has been verified to actually be contained within the polygon.
-
removeFalsePositives
public <T> List<T> removeFalsePositives(Collection<? extends T> boundingBoxResults, Converter<T, Point> locationExtractor, Circle circle) Utility method to remove false positives from a collection of objects that have a notion of location, where we want to only include values that are located within a circle. The collection should usually be already contained in the bounding box approximation of the circle for maximum efficiency.- Type Parameters:
T
- the type of located value objects in the collection.- Parameters:
boundingBoxResults
- the collections of located objects approximately inside the target circle.locationExtractor
- aConverter
to extract the location of the value objects.circle
- the target circle.- Returns:
- a
List
of the value objects which location has been verified to actually be contained within the circle.
-
removeFalsePositives
public <T> List<T> removeFalsePositives(Collection<? extends T> boundingBoxResults, Converter<T, Point> locationExtractor, Point... polygon) Utility method to remove false positives from a collection of objects that have a notion of location, where we want to only include values that are located within a polygon. The collection should usually be already contained in the bounding box approximation of the polygon for maximum efficiency.- Type Parameters:
T
- the type of located value objects in the collection.- Parameters:
boundingBoxResults
- the collections of located objects approximately inside the target polygon.locationExtractor
- aConverter
to extract the location of the value objects.polygon
- the target polygon, as an array ofPoint
(not necessarily closed).- Returns:
- a
List
of the value objects which location has been verified to actually be contained within the polygon.
-
removeFalsePositives
public <T> List<T> removeFalsePositives(Collection<? extends T> boundingBoxResults, Converter<T, Point> locationExtractor, Point center, Distance radius) Utility method to remove false positives from a collection of objects that have a notion of location, where we want to only include values that are located within a circle. The collection should usually be already contained in the bounding box approximation of the circle for maximum efficiency.- Type Parameters:
T
- the type of located value objects in the collection.- Parameters:
boundingBoxResults
- the collections of located objects approximately inside the target circle.locationExtractor
- aConverter
to extract the location of the value objects.center
- the center of the target circle.radius
- the radius of the target circle.- Returns:
- a
List
of the value objects which location has been verified to actually be contained within the circle.
-