如何从ElasticSearch中获取形状的交点 [英] How to get the intersecting points from shape in ElasticSearch

查看:597
本文介绍了如何从ElasticSearch中获取形状的交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 ElasticSearch 中存储一条路线作为多边形。现在我有一个圆(A点和半径),我可以检查圆点与多边形相交(下面是我使用的代码)。

I have stored a route in ElasticSearch as a Polygon. Now I have a circle (A point and a radius), I'am able to check the circle points intersects the polygon or not (Below is the code I used).

问题:如何获取与圈子相交的路线中的积分?

Question: How can I get the points in the route which intersects 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;
}


推荐答案

我想你知道使用弹性搜索,您可以查询与给定圆相交的多边形?请参阅 https://www.elastic.co/ guide / en / elasticsearch / guide / current / querying-geo-shapes.html

I guess you are aware that with elasticsearch, you can query for polygons that intersect a given circle? See https://www.elastic.co/guide/en/elasticsearch/guide/current/querying-geo-shapes.html.

有两个原因可能无法帮助您: p>

There are two reasons why this may not help you:


  1. 您的路线不是多边形,而是线条。

  2. 您想知道交叉点的确切点如果我正确地阅读了您的问题。

弹性搜索可能无法方便地解决此问题。如果您可以分别存储所有线段,而不是在每条路线上的一个巨大的多边形中,那么可能会有所解决。然后,每个线段将必须承载引用其所属路由的属性。那个方法对你来说可行吗?

Elasticsearch probably cannot solve this problem for you conveniently. It might be possible to solve if you would store all of your line-segments separately instead of in one huge polygon per route. Each line-segment then would have to bear an attribute that references the route it belongs to. Does that approach sound feasible to you?

无论如何,我建议您查看空间数据库的主题:
空间数据库经过优化,用于在几何空间中进行索引和搜索。诸如PostgreSQL和MongoDB等知名数据库提供了用于空间索引的插件/扩展。我不知道该推荐什么,但 MongoDB地理空间API 看起来很有前途例如,因为它允许查询交集 - 并且它支持行和多边形。

Anyways, I would recommend you to look into the topic of "spatial databases": Spatial databases are optimized for indexing and searching in a geometric space. Well-know databases such as PostgreSQL and MongoDB feature plugins/extensions for spatial indexing. I'm not sure what to recommend, but the MongoDB geospatial API looks promising for example, as it allows querying for intersection - and it supports lines as well as polygons.

这篇关于如何从ElasticSearch中获取形状的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆