2017-08-15 42 views
1
内找到多边形点

我有大约500个固定多边形,我希望能够检查多个点是否在这些多边形的哪一个中。 也许某些点在许多这些多边形内,有些点根本不在任何多边形内。 我知道elasticsearch geo_shape可以帮助我,但正如我知道我只能, 查询一个点知道它是哪个多边形。

因此,例如20分我应该连接到elasticsearch 20倍(考虑RTT)

,如果我加载所有多边形在我的过程和迭代点和polygins应该有嵌套20的计数循环* 500 和在每个周期中,我应该检测点是否在多边形 因此,这个脚本所需的执行速度和内存量都不是我想的。

可以任何身体帮助我一个更好的解决方案?

+0

我认为更好的方法是使用'percolator'映射类型并存储每个多边形的'geo_shape'查询。接下来,您可以为每个要检查的点发出一个包含一个'percolate'查询的'msearch'查询。你会得到每个点,包含它的多边形。 – Val

+0

直到现在我还不知道有关渗滤液的任何信息, 感谢您的评论我会尝试阅读更多信息。 – mhndev

+0

我继续向您提供解决方案的快速提示。 – Val

回答

1

我认为更好的方法是使用percolator mapping type。首先,创建一个索引,您将在其中存储geo_shape查询(在queries类型中)。您还需要定义点的映射(在points类型),使ES上知道它是针对查询:

PUT /my-index 
{ 
    "mappings": { 
     "points": { 
      "properties": { 
       "point": { 
        "type": "geo_shape" 
       } 
      } 
     }, 
     "queries": { 
      "properties": { 
       "query": { 
        "type": "percolator" 
       } 
      } 
     } 
    } 
} 

然后,你可以索引一个geo_shape查询每个已编制索引的多边形。这里我们定义一个geo_shape查询您已经存储在polygon-index每个多边形:

PUT /my-index/queries/query-id-for-polygon-id 
{ 
    "query" : { 
      "geo_shape": { 
       "location": { 
        "indexed_shape": { 
         "index": "polygon-index", 
         "type": "polygon-type", 
         "id": "polygon-id", 
         "path": "polygon-field" 
        } 
       } 
      } 
    } 
} 

最后,你可以发出包含每个要检查的要点之一percolate querymsearch query

单个点的一个过滤查询将如下所示。这个查询基本上是这样说的:“找到包含给定点的所有多边形查询”。因此,您将得到一个命中列表,其中每个命中是查询并将包含匹配的多边形(查询)的ID。

POST /my-index/_search 
{ 
    "query" : { 
     "percolate" : { 
      "field" : "query", 
      "document_type" : "points", 
      "document" : { 
       "point" : { 
        "type" : "point", 
        "coordinates" : [-77.03653, 38.897676] 
       } 
      } 
     } 
    } 
} 

所以,现在你需要创建者为每个要在以下格式检查点中的一个:

POST /my-index/_search 
{} 
{"query": {"percolate": {"field": "query", "document_type" : "points", "document" : {"point" : {"type" : "point","coordinates" : [-77.03653, 38.897676]}}}}} 
{} 
{"query": {"percolate": {"field": "query", "document_type" : "points", "document" : {"point" : {"type" : "point","coordinates" : [-77.03653, 38.897676]}}}}} 
{} 
{"query": {"percolate": {"field": "query", "document_type" : "points", "document" : {"point" : {"type" : "point","coordinates" : [-77.03653, 38.897676]}}}}} 
{} 
{"query": {"percolate": {"field": "query", "document_type" : "points", "document" : {"point" : {"type" : "point","coordinates" : [-77.03653, 38.897676]}}}}} 
... 

你会回来的每一个点,包含多边形它。