String urLat = request.getParameter("urLat");
String urLon = request.getParameter("urLon");
if (llLat != null && llLon != null && urLat != null && urLon != null) {
try {
LatLonRect bbox = new LatLonRect(new LatLon(
Double.parseDouble(llLat), Double.parseDouble(llLon)),
new LatLon(Double.parseDouble(urLat), Double.parseDouble(urLon)));
beforeTime = System.currentTimeMillis();
results = tree.queryByBoundingBox(bbox);
afterTime = System.currentTimeMillis();
// get the polygon that approximates the region
Rectangle2D[] rects = bbox.getJavaRectangles();
for (int i = 0; i < rects.length; i++) {
String regionStr = (rects[i].getMinY() - 90) + ","
+ (rects[i].getMinX() - 180) + ",";
regionStr += (rects[i].getMaxY() - 90) + ","
+ (rects[i].getMinX() - 180) + ",";
regionStr += (rects[i].getMaxY() - 90) + ","
+ (rects[i].getMaxX() - 180) + ",";
regionStr += (rects[i].getMinY() - 90) + ","
+ (rects[i].getMaxX() - 180) + ",";
regionStr += (rects[i].getMinY() - 90) + ","
+ (rects[i].getMinX() - 180);
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) {
LatLon point = null;
try {
point = new LatLon(Double.parseDouble(lat), Double.parseDouble(lon));
} 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) {
LatLon pt = DistanceUtils.getPointOnGreatCircle(point.getLat(), point
.getLon(), radiusKM, i);
regionStr += pt.toString() + ",";
}
LatLon pt = DistanceUtils.getPointOnGreatCircle(point.getLat(), point
.getLon(), radiusKM, 0);
regionStr += pt.toString() + ",";
regions.add(regionStr.substring(0, regionStr.length() - 1));
beforeTime = System.currentTimeMillis();
results = tree.queryByPointRadius(point, radiusKM);
afterTime = System.currentTimeMillis();