使用物化的地理空间半径搜索 [英] GeoSpatial Radius Search Using Objectify

查看:107
本文介绍了使用物化的地理空间半径搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 GeoModel 开发应用程序。我需要根据给定的经度和纬度在特定半径内执行搜索。我能够使用Objectify在数据存储中生成GeoCell,但无法在特定的半径范围内取回结果。



我在下面分享我的代码。

$ b

实体类$ b public class NewsFeed实现Serializable {
private static final long serialVersionUID = 1L;
@Id
@Index
私有长feedID;
@Index
private String topic;
@Index
私有字符串标题;
私有字符串描述;
@Index
private日期createDate;
私人字符串imageOrVideo;
private String imageUrl;
私人字符串blobKey;
@Latitude
私人双纬度;
@Longitude
私人双倍经度;
@Geocells
私人列表< String>细胞;

// getter and setters ...
}

自定义GeocellQueryEngine课程 来自此源

  public class ObjectifyGeocellQueryEngine实现GeocellQueryEngine {
private String geocellsProperty;
私人物品化;
public static final String DEFAULT_GEOCELLS_PROPERTY =cells;

public ObjectifyGeocellQueryEngine(Objectify ofy){
this(ofy,DEFAULT_GEOCELLS_PROPERTY);
}

public ObjectifyGeocellQueryEngine(Objectify ofy,String geocellsProperty){
this.ofy = ofy;
this.geocellsProperty = geocellsProperty;
}

@Override
public< T>列表与LT; T> query(GeocellQuery baseQuery,List< String> geocells,Class< T> entityClass){
StringTokenizer st;
int tokenNo = 0;
查询< T> query = ofy.query(entityClass);
if(baseQuery!= null){
st = new StringTokenizer(baseQuery.getBaseQuery(),,); $(st.hasMoreTokens()){
query.filter(st.nextToken(),baseQuery.getParameters()。get(tokenNo ++));


返回query.filter(geocellsProperty +IN,geocells).list();





$ b

在这里抓取数据

  Point p = new Point(24.8993714,79.5839124); 
//生成GeoCells列表
List< String> cells = GeocellManager.generateGeoCell(p);
列表< Object> params = new ArrayList< Object>();
params.add(电影);
GeocellQuery baseQuery = new GeocellQuery(topic == topic,String topic,params);
ObjectifyGeocellQueryEngine objectifyGeocellQueryEngine = new ObjectifyGeocellQueryEngine(ofy(),cells);
列出< NewsFeed> list = objectifyGeocellQueryEngine.query(baseQuery,cells,NewsFeed.class);
列出< NewsFeed> list2 = GeocellManager.proximitySearch(p,10,10000,NewsFeed.class,baseQuery,objectifyGeocellQueryEngine,GeocellManager.MAX_GEOCELL_RESOLUTION);
System.out.println(list +:+ list2);

现在问题是我没有从这里得到任何结果。请问你们能否帮助我,因为我没有得到任何异常,只是得到空的名单。

我已经完成了解决这种情况的方法我添加了一个并行JDO类来存储和检索地理空间结果。


I am developing an application using GeoModel. I need to perform search in a particular radius based on the given latitude and longitude. I am able to generate the GeoCells in the datastore using Objectify, but not able to get back the results in a particular radius.

I am sharing my code below.

Entity Class

@Entity
public class NewsFeed implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Index
private Long feedID;
@Index
private String topic;
@Index
private String title;
private String description;
@Index
private Date createDate;
private String imageOrVideo;
private String imageUrl;
private String blobKey;
@Latitude
private Double latitude;
@Longitude
private Double longitude;
@Geocells
private List<String> cells;

    // getter and setters ...
}

Custom GeocellQueryEngine Class From This Source

public class ObjectifyGeocellQueryEngine implements GeocellQueryEngine {
private String geocellsProperty;
private Objectify ofy;
public static final String DEFAULT_GEOCELLS_PROPERTY = "cells";

public ObjectifyGeocellQueryEngine(Objectify ofy) {
    this(ofy, DEFAULT_GEOCELLS_PROPERTY);
}

public ObjectifyGeocellQueryEngine(Objectify ofy, String geocellsProperty) {
    this.ofy = ofy;
    this.geocellsProperty = geocellsProperty;
}

@Override
public <T> List<T> query(GeocellQuery baseQuery, List<String> geocells, Class<T> entityClass) {
    StringTokenizer st;
    int tokenNo = 0;
    Query<T> query = ofy.query(entityClass);
    if (baseQuery != null) {
        st = new StringTokenizer(baseQuery.getBaseQuery(), ",");
        while (st.hasMoreTokens()) {
            query.filter(st.nextToken(), baseQuery.getParameters().get(tokenNo++));
        }
    }
    return query.filter(geocellsProperty + " IN", geocells).list();
}
}

Fetching Data Here

    Point p = new Point(24.8993714, 79.5839124);
    // Generates the list of GeoCells
    List<String> cells = GeocellManager.generateGeoCell(p);
    List<Object> params = new ArrayList<Object>();
    params.add("Movies");
    GeocellQuery baseQuery = new GeocellQuery("topic == topic", "String topic",params);
    ObjectifyGeocellQueryEngine objectifyGeocellQueryEngine = new ObjectifyGeocellQueryEngine(ofy(), "cells");
    List<NewsFeed> list = objectifyGeocellQueryEngine.query(baseQuery, cells, NewsFeed.class);
    List<NewsFeed> list2 = GeocellManager.proximitySearch(p, 10, 10000,NewsFeed.class, baseQuery, objectifyGeocellQueryEngine, GeocellManager.MAX_GEOCELL_RESOLUTION);
    System.out.println(list+" : "+list2);

Now the problem is I am not getting any results out from here. Can you people please help me with this as I am not getting any exception, just getting the empty list.

解决方案

I have done a workaround for this situation I have added a parallel JDO Class to store and retrieve the geospatial results.

这篇关于使用物化的地理空间半径搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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