I recently work with hibernate spatial and I have such a question. I wanna to get all points inside polygon. How can I do that?
For example my distance query looks lite this:
final Coordinates coordinates = Point.fromDegrees(searchDistanceParameters.getLatitude(), searchDistanceParameters.getLongitude());
final Query fromCoordinates = SpatialQueryBuilderFromCoordinates.buildDistanceQuery(coordinates, searchDistanceParameters.getDistance(), "location");
final FullTextSession fullTextSession = Search.getFullTextSession(session);
final FullTextQuery textQuery = fullTextSession.createFullTextQuery(fromCoordinates, GeoPointModel.class);
I create a Polygon like this:
GeometryFactory geometryFactory = new GeometryFactory();
Polygon polygon = geometryFactory.createPolygon(coordinates);
But what can I use to get points inside this polygon?
Hibernate Search 5's spatial support only covers distance queries. Matching points inside a polygon is not supported.
Hibernate Search 6 does provide a "within polygon" predicate, but APIs in Hibernate Search 6 are different from those in Search 5. If you're fine with that, you can use the latest Beta: http://hibernate.org/search/releases/6.0/ . You might want to have a look at the getting started guide for Hibernate Search 6 first, so as to understand the new APIs before you migrate.
If you need to stay on Hibernate Search 5, you will have to use lucene-spatial
: implement bridges to index points as lucene-spatial
expects, and generate lucene-spatial queries directly with lucene-spatial APIs.