I am trying to use the proximity search of Geomodel. However, I
am facing a problem, which I am not sure what it is, but I think it is
related to either my PersistentManager or baseQuery. I ran the query,
however, while my database is not empty, I got null results.


Here are my codes:

public class HowToUseGeocell extends TestCase {
...

public int ProximitySearch(double lat, double lon, double distance) {

        Point center = new Point(lat, lon);
        List<ObjectToSave> objects = null;
        PersistenceManager pm = PMF.get().getPersistenceManager();

       try{
            List<Object> params = new ArrayList<Object>();
            params.add("Mahsa");
            GeocellQuery baseQuery = new GeocellQuery("Owner ==
OwnerParam", "String OwnerParam", params);

            try {
                objects = GeocellManager.proximityFetch(center, 40,
distance, ObjectToSave.class, baseQuery, pm);
                Assert.assertTrue(objects.size() > 0);
            } catch (Exception e) {
                // We catch excption here because we have not
configured the PersistentManager (and so the queries won't work)
            }

        } finally {
                pm.close();
        }

        if (objects == null)
                return -3;

        else
                return objects.size();

}
}

Here is my ObjectToSave class:

@PersistenceCapable(detachable="true")
public class ObjectToSave implements LocationCapable {

    @PrimaryKey
    @Persistent
    private long id;

    @Persistent
    private double latitude;

    @Persistent
    private double longitude;

    @Persistent
    private double altitude;

    @Persistent
    private List<String> geocells;

    @Persistent
    private String owner;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public double getAltitude() {
        return altitude;
    }

    public void setAltitude(double alt) {
        this.altitude = alt;
    }

    public List<String> getGeocells() {
        return geocells;
    }

    public void setGeocells(List<String> geocells) {
        this.geocells = geocells;
    }

    public String getKeyString() {
        return Long.valueOf(id).toString();
    }

    public Point getLocation() {
        return new Point(latitude, longitude);
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String o) {
        this.owner = o;
    }

}

My PMF class:

public final class PMF {
    private static final PersistenceManagerFactory pmfInstance =
        JDOHelper.getPersistenceManagerFactory("transactions-
optional");

    private PMF() {}

    public static PersistenceManagerFactory get() {
        return pmfInstance;
    }

}

My Servlet:

@SuppressWarnings("serial")
public class Test8_Geomodel_GAEServlet extends HttpServlet {

//      public static UseGeocell GC = new UseGeocell();
        //public final static PersistenceManagerFactory pmfInstance =
JDOHelper.getPersistenceManagerFactory("transactions-optional");

        public void doGet(HttpServletRequest req, HttpServletResponse
resp)
                        throws IOException {

                doPost(req, resp);

        //      resp.setContentType("text/plain");
        //      resp.getWriter().println("Hello, world");
        }

        public void doPost(HttpServletRequest req, HttpServletResponse
resp)
                throws IOException {

                HowToUseGeocell gc = new HowToUseGeocell();
                List<ObjectToSave> obj = new
ArrayList<ObjectToSave>();

                //Read Excel "source file" (which is defined in
web.xml file) &
store it in datastore
                ServletContext context = getServletContext();

                String file_path = context.getRealPath("LiDAR.xls");
                File Myfile = new File(file_path);

                Workbook workBook;
                int PointNo;
                double latitude = 0.0, longitude = 0.0, altitude =
0.0;
                String owner = "";

                try {

                        workBook = Workbook.getWorkbook(Myfile);
                        Sheet sheet = workBook.getSheet(0);

                    int NumOfColumns = sheet.getColumns();
                    int NumOfRows = sheet.getRows();

                    String data;
                    for(int row = 1; row < NumOfRows; row++) {
                        for(int col = 0; col < NumOfColumns; col++) {
                            data = sheet.getCell(col,
row).getContents();

                                        data = sheet.getCell(0,
row).getContents();
                                        PointNo =
Integer.parseInt(data.toString());

                                        data = sheet.getCell(1,
row).getContents();
                                        owner = data;

                                        data = sheet.getCell(2,
row).getContents();
                                        latitude =
Double.parseDouble(data.toString());

                                        data = sheet.getCell(3,
row).getContents();
                                        longitude =
Double.parseDouble(data.toString());

                                        data = sheet.getCell(4,
row).getContents();
                                        altitude =
Double.parseDouble(data.toString());

 
gc.SaveGeocellsInDatabase(latitude, longitude, altitude, owner);

                        }
                    }

                } catch (BiffException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

                                        //Reading input entries &
executing proximity query

                                        String lat =
req.getParameter("txtlatitude_prox");
                                        String lon =
req.getParameter("txtlongitude_prox");
                                        String dis =
req.getParameter("txtdistance_prox");

                                        double Latitude =
Double.parseDouble(lat);
                                        double Longitude =
Double.parseDouble(lon);
                                        double Distance =
Double.parseDouble(dis);

                                        int size =
gc.ProximitySearch(Latitude, Longitude, Distance);

                                        String res_size =
Integer.toString(size);
                                        resp.setContentType("text/
plain");
 
resp.getWriter().println(res_size);

     }

}

Finally, here is my database (LiDAR.xls file) which is saved in /WAR
and is defined in web.xml file as a resource file as follow:

   <resource-files>
        <include path="/**.xls" />
    </resource-files>

point_no        Owner         lat
long                  alt
1              Mahsa    40.46231168     -79.97302985    232.8336705
2              Mahsa    40.46229439     -79.97302785    240.4475744
3              Mahsa    40.46227221     -79.97302604    241.3772144
4              Mahsa    40.46224956     -79.97302421    242.0813024

When I run the program (in a browser), using any lat, lon, & distance,
it returns -3 as the size of the query results, which shows that the
query result was null. I am not sure what I am doing wrong. I really
appreciate if I get help with this.

Also, I appreciate it if someone clarifies what baseQuery is used for.
My understanding is that it first executes a query on the database and
then executes proximity query on the result of the first query
(baseQuery). Is that correct?

Thanks in advance & sorry if my questions sound simple. I am very new
to GAE & java/servlet web development.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to