bryan-emmanuel / javageomodel

Automatically exported from code.google.com/p/javageomodel
0 stars 0 forks source link

Question - BoundingBox search #4

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Thanks for porting this project into Java. I have downloaded this project a 
couple weeks back and was working on to add the proximity search. 

But I just saw your latest updates with proximity search. Thanks for that.

Question - Your BoundingBox search method in GeocellManager returns the 
geocells but not list of Objects. Do you plan to implement a boundingbox 
search similar to proximity search?

How can I join the mailing list?

Original issue reported on code.google.com by nitin.na@gmail.com on 12 Apr 2010 at 5:04

GoogleCodeExporter commented 8 years ago
Solution is something like:

    BoundingBox bb = new BoundingBox(latN, lonE, latS, lonW);

    List<String> cellNameList = GeocellManager.bestBboxSearchCells(bb, null);

    PersistenceManager pm = pmf.getPersistenceManager();

    Query query = pm.newQuery(<T>.class);
    query.setFilter("geocells.contains(cellName)");
    query.declareParameters("String cellName");

    List<T> allObjects = new List<T>();
    List<T> objects = null;
    for (String cellName: cellNameList)
    {
        objects = (List<T>) query.execute(cellName);
        if (allObjects.size() + objects.size() > maxObjects) break;
        allObjects.addAll(objects);
    }

Original comment by takayama...@gmail.com on 1 Jun 2010 at 12:39

GoogleCodeExporter commented 8 years ago
new List<T>() should be: new ArrayList<T>()

Original comment by takayama...@gmail.com on 1 Jun 2010 at 1:02

GoogleCodeExporter commented 8 years ago
Shouldn't that be with the geocellParameter line? (Although I have no idea what 
it does, but it works for me ;)

  Query query = pm.newQuery(<T>.class);
  query.setFilter("cells.contains(cellName)");
  query.declareParameters("String cellName");
  query.declareParameters("String geocellsParameter");

Original comment by pajoma on 14 Jun 2010 at 5:52

GoogleCodeExporter commented 8 years ago
No.
The assumptions are:

<T> is represents a point on a Map.

<T>.point: The (latitude, longitude) of the point.
<T>.cells: All the Geocell names in which this point is in.

If you set the MAX_LEVEL to 13, there will be 13 Geocell names in this member 
field. The name represents a bounding box in which the point appears on 
different resolution levels. 

Off course, there will be one more bounding box on top of all these, which is 
the "world". All "points" belong to it.

e.g.

[8, 8e, 8e6, 8e63, 8e630, 8e630d, 8e630d6, 8e630d63, 8e630d634, 8e630d6342, 
8e630d63425, 8e630d634255, 8e630d634255d]

The query is "SELECT FROM <T> WHERE cells.CONTAINS(cellName)".

In this query, only the cellName is a parameter. Only that I don't use "Param" 
in its name.

So, if you prefer to use Param in the name, it's like:

"SELECT FROM <T> as t WHERE t.cells.CONTAINS(cellNameParam)"

NB: Don't use <T> in the real code. This is used only to as a general reference 
to the object searched in the JDO Datastore, because this is a pseudo code.

Original comment by takayama...@gmail.com on 15 Jun 2010 at 10:50

GoogleCodeExporter commented 8 years ago
Actually, if we could assume that the order of the list "cells" is always the 
same, i.e. 1 to MAX_LEVEL, and also List's get() works in JDOQL, we could 
simplify the query to:

List<String> cellNameList = GeocellManager.bestBboxSearchCells(bb, null);
int resolutionLevel = cellNameList.get(0).length;
int resolutionIndex = resolutionLevel -1;

PersistenceManager pm = pmf.getPersistenceManager();

Query query = pm.newQuery(<T>.class);
query.setFilter("cellNameList.contains(cells.get(resolutionIndex)");
query.declareParameters("String cellNameList, String resolutionIndex");

List<T> list = new ArrayList<T>();
list = (List<T>) query.execute(cellNameList, resolutionIndex);

The get() is defined in Datanucleus JDO 2.0, but marked as non-standard JDO.

Unfortunately, the current implementation of JDO in GAE does not support the 
get() method.

Original comment by takayama...@gmail.com on 15 Jun 2010 at 2:16

GoogleCodeExporter commented 8 years ago
To answer to the first questions:

Question - Your BoundingBox search method in GeocellManager returns the 
geocells but not list of Objects. Do you plan to implement a boundingbox 
search similar to proximity search?

======> No, I would say the code is more flexible like this. It returns a list 
of geocells and then you may use the geocells in your own query the way you 
like it (whatever the complexity of your query might be). Below is an example 
for a simple query:

List<String> cells = GeocellManager.bestBboxSearchCells(bb, null);

String queryString = "select from ObjectToSave where 
geocellsParameter.contains(geocells)";
Query query = pm.newQuery(queryString);
query.declareParameters("String geocellsParameter");
List<ObjectToSave> objects = (List<ObjectToSave>) query.execute(cells);

How can I join the mailing list?

======> I've just created a Google group: 
http://groups.google.com/group/javageomodel-discuss

Original comment by alexandr...@gmail.com on 10 Nov 2010 at 8:40

GoogleCodeExporter commented 8 years ago
My mistake, the line above should be:

String queryString = "select from ObjectToSave where 
geocells.contains(geocellsParameter)";

and not

String queryString = "select from ObjectToSave where 
geocellsParameter.contains(geocells)";

Original comment by alexandr...@gmail.com on 11 Nov 2010 at 6:31