Skip to content

Apache Lucene open-source search software

LUCENE-2359: fixed edge case around 180th meridian

Grant Ingersolleaca8cc2e8ca
diff --git a/lucene/contrib/CHANGES.txt b/lucene/contrib/CHANGES.txt
index 377c7ecf153..53fb2a1b2f1 100644
--- a/lucene/contrib/CHANGES.txt
+++ b/lucene/contrib/CHANGES.txt
@@ -60,6 +60,9 @@ Bug fixes
* LUCENE-2184: Fixed bug with handling best fit value when the proper best fit value is
not an indexed field. Note, this change affects the APIs. (Grant Ingersoll)
+
+ * LUCENE-2359: Fix bug in CartesianPolyFilterBuilder related to handling of behavior around
+ the 180th meridian (Grant Ingersoll)
API Changes
diff --git a/lucene/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianPolyFilterBuilder.java b/lucene/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianPolyFilterBuilder.java
index a12c049798a..d2fa6d9eb73 100644
--- a/lucene/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianPolyFilterBuilder.java
+++ b/lucene/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianPolyFilterBuilder.java
@@ -103,24 +103,26 @@ public class CartesianPolyFilterBuilder {
// iterate from startX->endX
// iterate from startY -> endY
// shape.add(currentLat.currentLong);
-
+ //for the edge cases (prime meridian and the 180th meridian), this call handles all tiles East of the meridian
+ //for all other cases, it handles the whole set of tiles
shape = getShapeLoop(shape,ctp,latX,longX,latY,longY);
-
if (longX2 != 0.0) {
- //We are around the prime meridian
- if (longX == 0.0) {
- longX = longX2;
- longY = 0.0;
- shape = getShapeLoop(shape,ctp,latX,longX,latY,longY);
- } else {//we are around the 180th longitude
- longX = longX2;
- longY = -180.0;
- shape = getShapeLoop(shape,ctp,latY,longY,latX,longX);
- }
+ if (longX == 0.0) {
+ longX = longX2;
+ longY = 0.0;
+ //handles the lower left longitude to the prime meridian
+ //shape = getShapeLoop(shape, ctp, latX, longX, latY, longY);
+ } else {
+ //this clause handles the lower left longitude up to the 180 meridian
+ longX = longX2;
+ longY = 180.0;
+ }
+ shape = getShapeLoop(shape, ctp, latX, longX, latY, longY);
- //System.err.println("getBoxShape2:"+latY+"," + longY);
- //System.err.println("getBoxShape2:"+latX+"," + longX);
- }
+ //System.err.println("getBoxShape2:"+latY+"," + longY);
+ //System.err.println("getBoxShape2:"+latX+"," + longX);
+ }
+
return shape;
}
@@ -132,7 +134,11 @@ public class CartesianPolyFilterBuilder {
//System.err.println("getShapeLoop:"+latX+"," + longX);
double beginAt = ctp.getTierBoxId(latX, longX);
double endAt = ctp.getTierBoxId(latY, longY);
-
+ if (beginAt > endAt){
+ double tmp = beginAt;
+ beginAt = endAt;
+ endAt = tmp;
+ }
double tierVert = ctp.getTierVerticalPosDivider();
//System.err.println(" | "+ beginAt+" | "+ endAt);
diff --git a/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java b/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java
index a16f0443a41..bef0e599d60 100644
--- a/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java
+++ b/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java
@@ -139,6 +139,7 @@ public class TestCartesian extends LuceneTestCase {
addPoint(writer,"Hilton Washington Embassy Row",38.9103000,-77.0451000);
addPoint(writer,"HorseFeathers, Bar & Grill", 39.01220000000001, -77.3942);
addPoint(writer,"Marshall Island Airfield",7.06, 171.2);
+ addPoint(writer, "Wonga Wongue Reserve, Gabon", -0.546562,9.459229);
addPoint(writer,"Midway Island",25.7, -171.7);
addPoint(writer,"North Pole Way",55.0, 4.0);
@@ -163,6 +164,34 @@ public class TestCartesian extends LuceneTestCase {
assertEquals(3474.331719997617, miles);
}
+ /*public void testCartesianPolyFilterBuilder() throws Exception {
+ CartesianPolyFilterBuilder cpfb = new CartesianPolyFilterBuilder(CartesianTierPlotter.DEFALT_FIELD_PREFIX, 2, 15);
+ //try out some shapes
+ final double miles = 20.0;
+ // Hawaii
+ // 2300 miles to Marshall Island Airfield
+ //Hawaii to Midway is 911 miles
+ lat = 0;
+ lng = -179.9;
+ Shape shape;
+ shape = cpfb.getBoxShape(lat, lng, miles);
+ System.out.println("Tier: " + shape.getTierLevel());
+ System.out.println("area: " + shape.getArea().size());
+ lat = 30;
+ lng = -100;
+ shape = cpfb.getBoxShape(lat, lng, miles);
+ System.out.println("Tier: " + shape.getTierLevel());
+ System.out.println("area: " + shape.getArea().size());
+
+ lat = 30;
+ lng = 100;
+ shape = cpfb.getBoxShape(lat, lng, miles);
+ System.out.println("Tier: " + shape.getTierLevel());
+ System.out.println("area: " + shape.getArea().size());
+ }
+*/
+
+
public void testAntiM() throws IOException, InvalidGeoException {
searcher = new IndexSearcher(directory, true);