String urLat = request.getParameter("urLat");
String urLon = request.getParameter("urLon");
if (llLat != null && llLon != null && urLat != null && urLon != null) {
try {
Envelope2D bbox = new Envelope2D(new DirectPosition2D(
Double.parseDouble(llLon), Double.parseDouble(llLat)),
new DirectPosition2D(Double.parseDouble(urLon), Double.parseDouble(urLat)));
beforeTime = System.currentTimeMillis();
results = tree.queryByBoundingBox(bbox);
afterTime = System.currentTimeMillis();
// get the polygon that approximates the region
Rectangle2D[] rects = bbox.toRectangles();
for (int i = 0; i < rects.length; i++) {
final Rectangle2D r = rects[i];
String regionStr = (r.getMinY()) + "," + (r.getMinX()) + ",";
regionStr += (r.getMaxY()) + "," + (r.getMinX()) + ",";
regionStr += (r.getMaxY()) + "," + (r.getMaxX()) + ",";
regionStr += (r.getMinY()) + "," + (r.getMaxX()) + ",";
regionStr += (r.getMinY()) + "," + (r.getMinX());
regions.add(regionStr);
}
} catch (NumberFormatException ex) {
System.out
.println("[ERROR] Input parameters were not valid latitudes and longitudes");
}
}
} else if (type != null && type.equals("pointradius")) {
String radius = request.getParameter("radius");
String lat = request.getParameter("lat");
String lon = request.getParameter("lon");
if (radius != null && lat != null && lon != null) {
DirectPosition2D point = null;
try {
point = new DirectPosition2D(Double.parseDouble(lon), Double.parseDouble(lat));
} catch (NumberFormatException ex) {
System.out
.println("{ERROR] Input parameters were not valid latitudes and longitudes");
}
double radiusKM = Double.parseDouble(radius);
String regionStr = "";
for (int i = 0; i < 360; i += 10) {
DirectPosition2D pt = DistanceUtils.getPointOnGreatCircle(point.y, point.x, radiusKM, i);
regionStr += pt.y + "," + pt.x + ",";
}
DirectPosition2D pt = DistanceUtils.getPointOnGreatCircle(point.y, point.x, radiusKM, 0);
regionStr += pt.y + "," + pt.x + ",";
regions.add(regionStr.substring(0, regionStr.length() - 1));
beforeTime = System.currentTimeMillis();
results = tree.queryByPointRadius(point, radiusKM);