Java – how to get intersections from shapes in elasticsearch

I have stored the path in elasticsearch as polygon Now that I have a circle (a point and a radius), I can check whether the point intersects the polygon (here is the code I use)

Question: how do I get the points in the alignment that intersect the circle?

public Boolean isMatchingDoc(Long elasticDocId,Double latitude,Double longitude,Long radius) {
    Coordinate origin = new Coordinate(latitude,longitude);
    ShapeBuilder circleShapeBuilder = ShapeBuilder.newCircleBuilder().center(origin).radius(radius,DistanceUnit.METERS);
    GeoShapeQueryBuilder geoShapeQueryBuilder = QueryBuilders.geoShapeQuery("route",circleShapeBuilder);
    SearchRequestBuilder finalQuery = client.prepareSearch(INDEX).setTypes(TYPE)
            .setQuery(QueryBuilders.termQuery("_id",elasticDocId)).setPostFilter(geoShapeQueryBuilder);
    SearchResponse searchResponse = finalQuery.execute().actionGet();
    SearchHits searchHits = searchResponse.getHits();
    if (searchHits.getTotalHits() > 0) {
        return true;
    }
    return false;
}

Solution

I think you know that using elastic search, can you query the polygons intersecting a given circle? See https://www.elastic.co/guide/en/elasticsearch/guide/current/querying-geo-shapes.html.

There are two reasons why this may not help you:

>Your route is not a polygon, but a line. > If I read your question correctly, you want to know the exact point of intersection

Elasticsearch may not be able to easily solve this problem for you You can solve this problem if you store all segments separately instead of a huge polygon per path Then, each segment must have an attribute that references the alignment to which it belongs Does this method sound useful to you?

Anyway, I suggest you look at the topic of "spatial database": spatial database optimizes indexing and search in geometric space Well known databases (such as PostgreSQL and mongodb) have plug-ins / extensions for spatial indexing I'm not sure what to recommend, but the mongodb geospatial API looks promising because it allows queries to cross - it supports lines and polygons

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>