You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2016/04/01 12:31:55 UTC

lucene-solr:branch_6_0: LUCENE-7158: use the same value (from WGS84) for earth's mean radius when we approximate it as a sphere

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6_0 b5f04a67f -> 48c80f91b


LUCENE-7158: use the same value (from WGS84) for earth's mean radius when we approximate it as a sphere

Conflicts:
	lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java
	lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoUtils.java
	lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java
	lucene/spatial/src/test/org/apache/lucene/spatial/util/TestGeoUtils.java
	lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPoint.java
	lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/48c80f91
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/48c80f91
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/48c80f91

Branch: refs/heads/branch_6_0
Commit: 48c80f91b8e5cd9b3a9b48e6184bd53e7619e7e3
Parents: b5f04a6
Author: Mike McCandless <mi...@apache.org>
Authored: Fri Apr 1 05:40:50 2016 -0400
Committer: Mike McCandless <mi...@apache.org>
Committed: Fri Apr 1 06:33:28 2016 -0400

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  4 ++++
 .../java/org/apache/lucene/util/SloppyMath.java |  6 ++++--
 .../org/apache/lucene/util/TestSloppyMath.java  | 20 ++++++++++----------
 .../demo/facet/DistanceFacetsExample.java       |  5 +++--
 .../lucene/expressions/TestDemoExpressions.java |  6 +++---
 .../expressions/js/TestJavascriptFunction.java  |  2 +-
 .../apache/lucene/spatial/util/GeoUtils.java    |  7 ++++++-
 .../lucene/spatial3d/geom/PlanetModel.java      |  3 ++-
 .../apache/lucene/spatial3d/TestGeo3DPoint.java |  2 +-
 .../lucene/spatial3d/geom/GeoCircleTest.java    | 15 ---------------
 10 files changed, 34 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c80f91/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 751116b..e7b0dd9 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -196,6 +196,10 @@ Bug Fixes
 * LUCENE-7126: Remove GeoPointDistanceRangeQuery. This query was implemented
   with boolean NOT, and incorrect for multi-valued documents. (Robert Muir)
 
+* LUCENE-7158: Consistently use earth's WGS84 mean radius wherever our
+  geo search implementations approximate the earth as a sphere (Karl
+  Wright via Mike McCandless)
+
 Other
 
 * LUCENE-7035: Upgrade icu4j to 56.1/unicode 8. (Robert Muir)

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c80f91/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java b/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
index e3ba489..d8b7056 100644
--- a/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
+++ b/lucene/core/src/java/org/apache/lucene/util/SloppyMath.java
@@ -176,8 +176,10 @@ public class SloppyMath {
   // TODO: remove these for java 9, they fixed Math.toDegrees()/toRadians() to work just like this.
   public static final double TO_RADIANS = Math.PI / 180D;
   public static final double TO_DEGREES = 180D / Math.PI;
-  private static final double TO_METERS = 6_378_137D; // equatorial radius
-  private static final double TO_KILOMETERS = 6_378.137D; // equatorial radius
+
+  // Earth's mean radius, in meters and kilometers; see http://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf
+  private static final double TO_METERS = 6_371_008.7714D; // equatorial radius
+  private static final double TO_KILOMETERS = 6_371.0087714D; // equatorial radius
   
   // cos/asin
   private static final double ONE_DIV_F2 = 1/2.0;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c80f91/lucene/core/src/test/org/apache/lucene/util/TestSloppyMath.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestSloppyMath.java b/lucene/core/src/test/org/apache/lucene/util/TestSloppyMath.java
index 2ccf619..f11d35f 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestSloppyMath.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestSloppyMath.java
@@ -99,8 +99,8 @@ public class TestSloppyMath extends LuceneTestCase {
     assertEquals(0, haversinMeters(90, -180, 90, 180), 0D);
     assertEquals(0, haversinMeters(90, 180, 90, 180), 0D);
     
-    // Test half a circle on the equator, using WGS84 equatorial earth radius
-    double earthRadiusMs = 6_378_137D;
+    // Test half a circle on the equator, using WGS84 mean earth radius in meters
+    double earthRadiusMs = 6_371_008.7714;
     double halfCircle = earthRadiusMs * Math.PI;
     assertEquals(halfCircle, haversinMeters(0, 0, 0, 180), 0D);
 
@@ -111,17 +111,17 @@ public class TestSloppyMath extends LuceneTestCase {
     double randomLat2 = 40.65 + (r.nextInt(10) - 5) * 360;
     double randomLon2 = -73.95 + (r.nextInt(10) - 5) * 360;
     
-    assertEquals(8_581.7047, haversinMeters(randomLat1, randomLon1, randomLat2, randomLon2), 0.01D);
+    assertEquals(8_572.1137, haversinMeters(randomLat1, randomLon1, randomLat2, randomLon2), 0.01D);
     
     
     // from solr and ES tests (with their respective epsilons)
     assertEquals(0, haversinMeters(40.7143528, -74.0059731, 40.7143528, -74.0059731), 0D);
-    assertEquals(5_291.80, haversinMeters(40.7143528, -74.0059731, 40.759011, -73.9844722), 0.01D);
-    assertEquals(462.62, haversinMeters(40.7143528, -74.0059731, 40.718266, -74.007819), 0.01D);
-    assertEquals(1_056.16, haversinMeters(40.7143528, -74.0059731, 40.7051157, -74.0088305), 0.01D);
-    assertEquals(1_259.53, haversinMeters(40.7143528, -74.0059731, 40.7247222, -74), 0.01D);
-    assertEquals(2_030.79, haversinMeters(40.7143528, -74.0059731, 40.731033, -73.9962255), 0.01D);
-    assertEquals(8_581.70, haversinMeters(40.7143528, -74.0059731, 40.65, -73.95), 0.01D);
+    assertEquals(5_285.89, haversinMeters(40.7143528, -74.0059731, 40.759011, -73.9844722), 0.01D);
+    assertEquals(462.10, haversinMeters(40.7143528, -74.0059731, 40.718266, -74.007819), 0.01D);
+    assertEquals(1_054.98, haversinMeters(40.7143528, -74.0059731, 40.7051157, -74.0088305), 0.01D);
+    assertEquals(1_258.12, haversinMeters(40.7143528, -74.0059731, 40.7247222, -74), 0.01D);
+    assertEquals(2_028.52, haversinMeters(40.7143528, -74.0059731, 40.731033, -73.9962255), 0.01D);
+    assertEquals(8_572.11, haversinMeters(40.7143528, -74.0059731, 40.65, -73.95), 0.01D);
   }
   
   /** Test this method sorts the same way as real haversin */
@@ -164,6 +164,6 @@ public class TestSloppyMath extends LuceneTestCase {
     double h1 = (1 - StrictMath.cos(StrictMath.toRadians(lat2) - StrictMath.toRadians(lat1))) / 2;
     double h2 = (1 - StrictMath.cos(StrictMath.toRadians(lon2) - StrictMath.toRadians(lon1))) / 2;
     double h = h1 + StrictMath.cos(StrictMath.toRadians(lat1)) * StrictMath.cos(StrictMath.toRadians(lat2)) * h2;
-    return 2 * 6378137 * StrictMath.asin(Math.min(1, Math.sqrt(h))); 
+    return 2 * 6371008.7714 * StrictMath.asin(Math.min(1, Math.sqrt(h))); 
   }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c80f91/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java
----------------------------------------------------------------------
diff --git a/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java b/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java
index 8328f97..96ca57c 100644
--- a/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java
+++ b/lucene/demo/src/java/org/apache/lucene/demo/facet/DistanceFacetsExample.java
@@ -70,12 +70,13 @@ public class DistanceFacetsExample implements Closeable {
   /** The "home" longitude. */
   public final static double ORIGIN_LONGITUDE = -74.0059731;
 
-  /** Radius of the Earth in KM
+  /** Mean radius of the Earth in KM
    *
    * NOTE: this is approximate, because the earth is a bit
    * wider at the equator than the poles.  See
    * http://en.wikipedia.org/wiki/Earth_radius */
-  public final static double EARTH_RADIUS_KM = 6371.01;
+  // see http://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf
+  public final static double EARTH_RADIUS_KM = 6_371.0087714;
 
   /** Empty constructor */
   public DistanceFacetsExample() {}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c80f91/lucene/expressions/src/test/org/apache/lucene/expressions/TestDemoExpressions.java
----------------------------------------------------------------------
diff --git a/lucene/expressions/src/test/org/apache/lucene/expressions/TestDemoExpressions.java b/lucene/expressions/src/test/org/apache/lucene/expressions/TestDemoExpressions.java
index 6b35942..01b3394 100644
--- a/lucene/expressions/src/test/org/apache/lucene/expressions/TestDemoExpressions.java
+++ b/lucene/expressions/src/test/org/apache/lucene/expressions/TestDemoExpressions.java
@@ -224,13 +224,13 @@ public class  TestDemoExpressions extends LuceneTestCase {
     TopFieldDocs td = searcher.search(new MatchAllDocsQuery(), 3, sort);
     
     FieldDoc d = (FieldDoc) td.scoreDocs[0];
-    assertEquals(0.4626D, (Double)d.fields[0], 1E-4);
+    assertEquals(0.4621D, (Double)d.fields[0], 1E-4);
     
     d = (FieldDoc) td.scoreDocs[1];
-    assertEquals(1.0562D, (Double)d.fields[0], 1E-4);
+    assertEquals(1.055D, (Double)d.fields[0], 1E-4);
     
     d = (FieldDoc) td.scoreDocs[2];
-    assertEquals(5.2918D, (Double)d.fields[0], 1E-4);
+    assertEquals(5.2859D, (Double)d.fields[0], 1E-4);
   }
 
   public void testStaticExtendedVariableExample() throws Exception {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c80f91/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptFunction.java
----------------------------------------------------------------------
diff --git a/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptFunction.java b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptFunction.java
index ce38acd..81362a6 100644
--- a/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptFunction.java
+++ b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptFunction.java
@@ -158,7 +158,7 @@ public class TestJavascriptFunction extends LuceneTestCase {
   }
   
   public void testHaversinMethod() throws Exception {
-    assertEvaluatesTo("haversin(40.7143528,-74.0059731,40.759011,-73.9844722)", 5.291799723323441);
+    assertEvaluatesTo("haversin(40.7143528,-74.0059731,40.759011,-73.9844722)", 5.285885589128259);
   }
   
   public void testLnMethod() throws Exception {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c80f91/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoUtils.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoUtils.java b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoUtils.java
index 403c425..db58d6b 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoUtils.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoUtils.java
@@ -53,6 +53,11 @@ public final class GeoUtils {
   /** Maximum latitude value. */
   public static final double MAX_LAT_INCL = 90.0D;
 
+  // WGS84 earth-ellipsoid parameters
+  /** mean earth axis in meters */
+  // see http://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf
+  public static final double EARTH_MEAN_RADIUS_METERS = 6_371_008.7714;
+
   // No instance:
   private GeoUtils() {
   }
@@ -75,7 +80,7 @@ public final class GeoUtils {
   public static GeoRect circleToBBox(final double centerLat, final double centerLon, final double radiusMeters) {
     final double radLat = TO_RADIANS * centerLat;
     final double radLon = TO_RADIANS * centerLon;
-    double radDistance = radiusMeters / SEMIMAJOR_AXIS;
+    double radDistance = radiusMeters / EARTH_MEAN_RADIUS_METERS;
     double minLat = radLat - radDistance;
     double maxLat = radLat + radDistance;
     double minLon;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c80f91/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java
index b905b56..2feb65a 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java
@@ -26,7 +26,8 @@ public class PlanetModel {
   public static final PlanetModel SPHERE = new PlanetModel(1.0,1.0);
 
   /** Mean radius */
-  public static final double WGS84_MEAN = 6371009.0;
+  // see http://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf
+  public static final double WGS84_MEAN = 6371008.7714;
   /** Polar radius */
   public static final double WGS84_POLAR = 6356752.314245;
   /** Equatorial radius */

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c80f91/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
index 5c0044f..8d665f1 100644
--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DPoint.java
@@ -796,7 +796,7 @@ public class TestGeo3DPoint extends LuceneTestCase {
 
   public void testToString() {
     Geo3DPoint point = new Geo3DPoint("point", toRadians(44.244272), toRadians(7.769736));
-    assertEquals("Geo3DPoint <point: x=0.9248467864160119 y=0.06280434265368656 z=0.37682349005486243>", point.toString());
+    assertEquals("Geo3DPoint <point: x=0.9248468196007059 y=0.06280434490718728 z=0.37682350357577465>", point.toString());
   }
 
   public void testShapeQueryToString() {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/48c80f91/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoCircleTest.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoCircleTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoCircleTest.java
index 186bf4c..ca8b669 100755
--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoCircleTest.java
+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoCircleTest.java
@@ -211,21 +211,6 @@ public class GeoCircleTest extends LuceneTestCase {
       xyzb.getMinimumX(), xyzb.getMaximumX(), xyzb.getMinimumY(), xyzb.getMaximumY(), xyzb.getMinimumZ(), xyzb.getMaximumZ());
     assertTrue(GeoArea.WITHIN == area.getRelationship(c) || GeoArea.OVERLAPS == area.getRelationship(c));
     
-    // Yet another test case from BKD
-    c = GeoCircleFactory.makeGeoCircle(PlanetModel.WGS84, 0.006229478708446979, 0.005570196723795424, 3.840276763694387E-5);
-    xyzb = new XYZBounds();
-    c.getBounds(xyzb);
-    area = GeoAreaFactory.makeGeoArea(PlanetModel.WGS84,
-      xyzb.getMinimumX(), xyzb.getMaximumX(), xyzb.getMinimumY(), xyzb.getMaximumY(), xyzb.getMinimumZ(), xyzb.getMaximumZ());
-    p1 = new GeoPoint(PlanetModel.WGS84, 0.006224927111830945, 0.005597367237251763);
-    p2 = new GeoPoint(1.0010836083810235, 0.005603490759433942, 0.006231850560862502);
-    assertTrue(PlanetModel.WGS84.pointOnSurface(p1));
-    //assertTrue(PlanetModel.WGS84.pointOnSurface(p2));
-    assertTrue(c.isWithin(p1));
-    assertTrue(c.isWithin(p2));
-    assertTrue(area.isWithin(p1));
-    assertTrue(area.isWithin(p2));
-    
     // Another test case from BKD
     c = GeoCircleFactory.makeGeoCircle(PlanetModel.SPHERE, -0.005955031040627789, -0.0029274772647399153, 1.601488279374338E-5);
     xyzb = new XYZBounds();