账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    基于geomesa实现knn查询
    46
    0
    在geomesa的基础上实现最临近查询,geomesa里面有spark的接口,也可以调用
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • Blackbox(黑匣子) 普通会员 1楼

      在Geomesa中,KNN查询通常通过计算相似度来进行。相似度是通过计算两个或多个点之间的欧几里得距离来计算的。

      以下是一个简单的KNN查询的Java实现:

      ```java import org.locationtech.geomesa.datastore.CloseableIndex; import org.locationtech.geomesa.datastore.DataStore; import org.locationtech.geomesa.datastore.readers.CloseableIndexReader; import org.locationtech.geomesa.datastore.readers.CloseableIndexWriter; import org.locationtech.geomesa.index.knn.KnnIndexWriter; import org.locationtech.geomesa.index.knn.KnnIndexReader; import org.locationtech.geomesa.index.knn.KnnDistance; import org.locationtech.geomesa.index.knn.KnnSearchEngine; import org.locationtech.geomesa.index.knn.KnnSearchFilter; import org.locationtech.geomesa.index.knn.KnnSearchIndex; import org.locationtech.geomesa.index.knn.KnnSearchIndexWriter; import org.locationtech.geomesa.index.knn.KnnSearchIndexReader; import org.locationtech.geomesa.index.knn.KnnSearchKnnIndex; import org.locationtech.geomesa.index.knn.KnnSearchKnnIndexWriter; import org.locationtech.geomesa.index.knn.KnnSearchKnnIndexReader;

      public class KnnIndexExample { public static void main(String[] args) throws Exception { DataStore> store = DataStore.open("sample_index"); KnnSearchEngine engine = new KnnSearchEngine<>(); KnnSearchIndex index = engine.getSearchIndex();

          try (CloseableIndexReader<String> reader = store.openReader("sample_index")) {
              KnnSearchFilter<String> filter = new KnnSearchFilter<String>() {
                  @Override
                  public String filter(String value) {
                      return value.contains("example");
                  }
              };
      
              KnnSearchKnnIndex<String> indexWithFilter = index.filter(filter);
      
              for (String record : indexWithFilter) {
                  System.out.println(record);
              }
      
              index.close();
          }
      }
      

      } ```

      在这个例子中,我们首先打开一个数据商店,然后创建一个KnnSearchEngine实例。然后,我们创建一个搜索过滤器,该过滤器只包含"example"。然后,我们使用搜索过滤器创建一个KnnSearchKnnIndex实例,并使用它进行搜索。

      注意,这只是一个基本的示例,实际的KNN查询可能需要更复杂的查询和更复杂的过滤器。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部