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/03/22 16:53:06 UTC
[3/3] lucene-solr:branch_6x: LUCENE-7128: clean up new geo APIs to
consistently take lat before lon, make methods private when possible,
use lat/lon instead of y/x naming, remove unused code
LUCENE-7128: clean up new geo APIs to consistently take lat before lon, make methods private when possible, use lat/lon instead of y/x naming, remove unused code
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/c5da271b
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/c5da271b
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/c5da271b
Branch: refs/heads/branch_6x
Commit: c5da271b9d9b05e31a592b8bbdb416529a2c1770
Parents: 86d7eef
Author: Mike McCandless <mi...@apache.org>
Authored: Tue Mar 22 11:52:26 2016 -0400
Committer: Mike McCandless <mi...@apache.org>
Committed: Tue Mar 22 11:53:00 2016 -0400
----------------------------------------------------------------------
.../document/LatLonPointDistanceComparator.java | 2 +-
.../document/LatLonPointDistanceQuery.java | 2 +-
.../document/LatLonPointInPolygonQuery.java | 18 +-
.../lucene/search/TestLatLonPointQueries.java | 12 +-
.../geopoint/document/GeoPointField.java | 32 +-
.../geopoint/document/GeoPointTokenStream.java | 8 +-
.../geopoint/search/GeoPointDistanceQuery.java | 44 +--
.../search/GeoPointDistanceQueryImpl.java | 21 +-
.../search/GeoPointDistanceRangeQuery.java | 22 +-
.../geopoint/search/GeoPointInBBoxQuery.java | 68 ++--
.../search/GeoPointInBBoxQueryImpl.java | 49 +--
.../geopoint/search/GeoPointInPolygonQuery.java | 44 +--
.../search/GeoPointInPolygonQueryImpl.java | 26 +-
.../geopoint/search/GeoPointMultiTermQuery.java | 42 +-
.../search/GeoPointNumericTermsEnum.java | 6 +-
.../search/GeoPointPrefixTermsEnum.java | 14 +-
.../GeoPointTermQueryConstantScoreWrapper.java | 2 +-
.../geopoint/search/GeoPointTermsEnum.java | 4 +-
.../lucene/spatial/util/GeoDistanceUtils.java | 86 +---
.../lucene/spatial/util/GeoEncodingUtils.java | 7 +-
.../lucene/spatial/util/GeoHashUtils.java | 283 --------------
.../lucene/spatial/util/GeoProjectionUtils.java | 327 +---------------
.../org/apache/lucene/spatial/util/GeoRect.java | 10 +-
.../lucene/spatial/util/GeoRelationUtils.java | 388 ++++++++++---------
.../apache/lucene/spatial/util/GeoUtils.java | 47 +--
.../geopoint/search/TestGeoPointField.java | 94 ++---
.../geopoint/search/TestGeoPointQuery.java | 20 +-
.../search/TestLegacyGeoPointField.java | 92 ++---
.../search/TestLegacyGeoPointQuery.java | 20 +-
.../spatial/util/BaseGeoPointTestCase.java | 2 +-
.../lucene/spatial/util/TestGeoUtils.java | 183 +--------
31 files changed, 580 insertions(+), 1395 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceComparator.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceComparator.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceComparator.java
index 2f142ba..e818e1d 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceComparator.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceComparator.java
@@ -83,7 +83,7 @@ class LatLonPointDistanceComparator extends FieldComparator<Double> implements L
// sampling if we get called way too much: don't make gobs of bounding
// boxes if comparator hits a worst case order (e.g. backwards distance order)
if (setBottomCounter < 1024 || (setBottomCounter & 0x3F) == 0x3F) {
- GeoRect box = GeoUtils.circleToBBox(longitude, latitude, haversin2(bottom));
+ GeoRect box = GeoUtils.circleToBBox(latitude, longitude, haversin2(bottom));
// pre-encode our box to our integer encoding, so we don't have to decode
// to double values for uncompetitive hits. This has some cost!
minLat = LatLonPoint.encodeLatitude(box.minLat);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
index 8f4b347..5e7a04e 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java
@@ -75,7 +75,7 @@ final class LatLonPointDistanceQuery extends Query {
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
- GeoRect box = GeoUtils.circleToBBox(longitude, latitude, radiusMeters);
+ GeoRect box = GeoUtils.circleToBBox(latitude, longitude, radiusMeters);
// create bounding box(es) for the distance range
// these are pre-encoded with LatLonPoint's encoding
final byte minLat[] = new byte[Integer.BYTES];
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
index cb98895..68c734e 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/LatLonPointInPolygonQuery.java
@@ -169,13 +169,13 @@ final class LatLonPointInPolygonQuery extends Query {
if (cellMinLat <= minLat && cellMaxLat >= maxLat && cellMinLon <= minLon && cellMaxLon >= maxLon) {
// Cell fully encloses the query
return Relation.CELL_CROSSES_QUERY;
- } else if (GeoRelationUtils.rectWithinPolyPrecise(cellMinLon, cellMinLat, cellMaxLon, cellMaxLat,
- polyLons, polyLats,
- minLon, minLat, maxLon, maxLat)) {
+ } else if (GeoRelationUtils.rectWithinPolyPrecise(cellMinLat, cellMaxLat, cellMinLon, cellMaxLon,
+ polyLats, polyLons,
+ minLat, maxLat, minLon, maxLon)) {
return Relation.CELL_INSIDE_QUERY;
- } else if (GeoRelationUtils.rectCrossesPolyPrecise(cellMinLon, cellMinLat, cellMaxLon, cellMaxLat,
- polyLons, polyLats,
- minLon, minLat, maxLon, maxLat)) {
+ } else if (GeoRelationUtils.rectCrossesPolyPrecise(cellMinLat, cellMaxLat, cellMinLon, cellMaxLon,
+ polyLats, polyLons,
+ minLat, maxLat, minLon, maxLon)) {
return Relation.CELL_CROSSES_QUERY;
} else {
return Relation.CELL_OUTSIDE_QUERY;
@@ -204,7 +204,7 @@ final class LatLonPointInPolygonQuery extends Query {
long encoded = docValues.valueAt(i);
double docLatitude = LatLonPoint.decodeLatitude((int)(encoded >> 32));
double docLongitude = LatLonPoint.decodeLongitude((int)(encoded & 0xFFFFFFFF));
- if (GeoRelationUtils.pointInPolygon(polyLons, polyLats, docLatitude, docLongitude)) {
+ if (GeoRelationUtils.pointInPolygon(polyLats, polyLons, docLatitude, docLongitude)) {
return true;
}
}
@@ -289,9 +289,9 @@ final class LatLonPointInPolygonQuery extends Query {
sb.append(" Points: ");
for (int i=0; i<polyLons.length; ++i) {
sb.append("[")
- .append(polyLons[i])
- .append(", ")
.append(polyLats[i])
+ .append(", ")
+ .append(polyLons[i])
.append("] ");
}
return sb.toString();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
index e12923f..df34940 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/search/TestLatLonPointQueries.java
@@ -55,11 +55,11 @@ public class TestLatLonPointQueries extends BaseGeoPointTestCase {
assert Double.isNaN(pointLat) == false;
if (rect.minLon < rect.maxLon) {
- return GeoRelationUtils.pointInRectPrecise(pointLon, pointLat, rect.minLon, rect.minLat, rect.maxLon, rect.maxLat);
+ return GeoRelationUtils.pointInRectPrecise(pointLat, pointLon, rect.minLat, rect.maxLat, rect.minLon, rect.maxLon);
} else {
// Rect crosses dateline:
- return GeoRelationUtils.pointInRectPrecise(pointLon, pointLat, -180.0, rect.minLat, rect.maxLon, rect.maxLat)
- || GeoRelationUtils.pointInRectPrecise(pointLon, pointLat, rect.minLon, rect.minLat, 180.0, rect.maxLat);
+ return GeoRelationUtils.pointInRectPrecise(pointLat, pointLon, rect.minLat, rect.maxLat, -180.0, rect.maxLon)
+ || GeoRelationUtils.pointInRectPrecise(pointLat, pointLon, rect.minLat, rect.maxLat, rect.minLon, 180.0);
}
}
@@ -82,11 +82,11 @@ public class TestLatLonPointQueries extends BaseGeoPointTestCase {
assert Double.isNaN(pointLat) == false;
assert rect.crossesDateline() == false;
- double y[] = new double[] { rect.minLat, rect.maxLat, rect.maxLat, rect.minLat, rect.minLat };
- double x[] = new double[] { rect.minLon, rect.minLon, rect.maxLon, rect.maxLon, rect.minLon };
+ double polyLats[] = new double[] { rect.minLat, rect.maxLat, rect.maxLat, rect.minLat, rect.minLat };
+ double polyLons[] = new double[] { rect.minLon, rect.minLon, rect.maxLon, rect.maxLon, rect.minLon };
// TODO: separately test this method is 100% correct, here treat it like a black box (like haversin)
- return GeoRelationUtils.pointInPolygon(x, y, pointLat, pointLon);
+ return GeoRelationUtils.pointInPolygon(polyLats, polyLons, pointLat, pointLon);
}
@Override
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointField.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointField.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointField.java
index 39f12df..688315a 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointField.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointField.java
@@ -127,39 +127,39 @@ public final class GeoPointField extends Field {
/** Creates a stored or un-stored GeoPointField
* @param name field name
- * @param lon longitude double value [-180.0 : 180.0]
* @param lat latitude double value [-90.0 : 90.0]
+ * @param lon longitude double value [-180.0 : 180.0]
* @param stored Store.YES if the content should also be stored
* @throws IllegalArgumentException if the field name is null.
*/
- public GeoPointField(String name, double lon, double lat, Store stored) {
- this(name, lon, lat, getFieldType(stored));
+ public GeoPointField(String name, double lat, double lon, Store stored) {
+ this(name, lat, lon, getFieldType(stored));
}
/** Creates a stored or un-stored GeoPointField using the specified {@link TermEncoding} method
* @param name field name
- * @param lon longitude double value [-180.0 : 180.0]
* @param lat latitude double value [-90.0 : 90.0]
+ * @param lon longitude double value [-180.0 : 180.0]
* @param termEncoding encoding type to use ({@link TermEncoding#NUMERIC} Terms, or {@link TermEncoding#PREFIX} only Terms)
* @param stored Store.YES if the content should also be stored
* @throws IllegalArgumentException if the field name is null.
*/
@Deprecated
- public GeoPointField(String name, double lon, double lat, TermEncoding termEncoding, Store stored) {
- this(name, lon, lat, getFieldType(termEncoding, stored));
+ public GeoPointField(String name, double lat, double lon, TermEncoding termEncoding, Store stored) {
+ this(name, lat, lon, getFieldType(termEncoding, stored));
}
/** Expert: allows you to customize the {@link
* FieldType}.
* @param name field name
- * @param lon longitude double value [-180.0 : 180.0]
* @param lat latitude double value [-90.0 : 90.0]
+ * @param lon longitude double value [-180.0 : 180.0]
* @param type customized field type: must have {@link FieldType#numericType()}
* of {@link org.apache.lucene.document.FieldType.LegacyNumericType#LONG}.
* @throws IllegalArgumentException if the field name or type is null, or
* if the field type does not have a LONG numericType()
*/
- public GeoPointField(String name, double lon, double lat, FieldType type) {
+ public GeoPointField(String name, double lat, double lon, FieldType type) {
super(name, type);
// field must be indexed
@@ -181,7 +181,7 @@ public final class GeoPointField extends Field {
}
// set field data
- fieldsData = GeoEncodingUtils.mortonHash(lon, lat);
+ fieldsData = GeoEncodingUtils.mortonHash(lat, lon);
}
private static FieldType getFieldType(Store stored) {
@@ -226,25 +226,25 @@ public final class GeoPointField extends Field {
return reuse;
}
- /** access longitude value */
- public double getLon() {
- return GeoEncodingUtils.mortonUnhashLon((long) fieldsData);
- }
-
/** access latitude value */
public double getLat() {
return GeoEncodingUtils.mortonUnhashLat((long) fieldsData);
}
+ /** access longitude value */
+ public double getLon() {
+ return GeoEncodingUtils.mortonUnhashLon((long) fieldsData);
+ }
+
@Override
public String toString() {
if (fieldsData == null) {
return null;
}
StringBuilder sb = new StringBuilder();
- sb.append(GeoEncodingUtils.mortonUnhashLon((long) fieldsData));
- sb.append(',');
sb.append(GeoEncodingUtils.mortonUnhashLat((long) fieldsData));
+ sb.append(',');
+ sb.append(GeoEncodingUtils.mortonUnhashLon((long) fieldsData));
return sb.toString();
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointTokenStream.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointTokenStream.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointTokenStream.java
index 4a70ea3..66216ab 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointTokenStream.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/document/GeoPointTokenStream.java
@@ -56,18 +56,18 @@ import static org.apache.lucene.spatial.geopoint.document.GeoPointField.PRECISIO
*
* <pre class="prettyprint">
* // using prefix terms
- * GeoPointField geoPointField = new GeoPointField(fieldName1, lon, lat, GeoPointField.PREFIX_TYPE_NOT_STORED);
+ * GeoPointField geoPointField = new GeoPointField(fieldName1, lat, lon, GeoPointField.PREFIX_TYPE_NOT_STORED);
* document.add(geoPointField);
*
* // query by bounding box (default uses TermEncoding.PREFIX)
* Query q = new GeoPointInBBoxQuery(fieldName1, minLon, minLat, maxLon, maxLat);
*
* // using numeric terms
- * geoPointField = new GeoPointField(fieldName2, lon, lat, GeoPointField.NUMERIC_TYPE_NOT_STORED);
+ * geoPointField = new GeoPointField(fieldName2, lat, lon, GeoPointField.NUMERIC_TYPE_NOT_STORED);
* document.add(geoPointField);
*
* // query by distance (requires TermEncoding.NUMERIC)
- * q = new GeoPointDistanceQuery(fieldName2, TermEncoding.NUMERIC, centerLon, centerLat, radiusMeters);
+ * q = new GeoPointDistanceQuery(fieldName2, TermEncoding.NUMERIC, centerLat, centerLon, radiusMeters);
* </pre>
*
* @lucene.experimental
@@ -230,4 +230,4 @@ final class GeoPointTokenStream extends TokenStream {
public String toString() {
return getClass().getSimpleName() + "(precisionStep=" + PRECISION_STEP + " shift=" + geoPointTermAtt.getShift() + ")";
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQuery.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQuery.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQuery.java
index a513b3d..2486852 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQuery.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQuery.java
@@ -42,19 +42,19 @@ import org.apache.lucene.spatial.util.GeoUtils;
*
* @lucene.experimental */
public class GeoPointDistanceQuery extends GeoPointInBBoxQuery {
- /** longitude value (in degrees) for query location */
- protected final double centerLon;
/** latitude value (in degrees) for query location */
protected final double centerLat;
- /** distance (in meters) from lon, lat center location */
+ /** longitude value (in degrees) for query location */
+ protected final double centerLon;
+ /** distance (in meters) from lat, lon center location */
protected final double radiusMeters;
/**
* Constructs a Query for all {@link org.apache.lucene.spatial.geopoint.document.GeoPointField} types within a
* distance (in meters) from a given point
**/
- public GeoPointDistanceQuery(final String field, final double centerLon, final double centerLat, final double radiusMeters) {
- this(field, TermEncoding.PREFIX, centerLon, centerLat, radiusMeters);
+ public GeoPointDistanceQuery(final String field, final double centerLat, final double centerLon, final double radiusMeters) {
+ this(field, TermEncoding.PREFIX, centerLat, centerLon, radiusMeters);
}
/**
@@ -62,38 +62,38 @@ public class GeoPointDistanceQuery extends GeoPointInBBoxQuery {
* distance (in meters) from a given point. Accepts optional
* {@link org.apache.lucene.spatial.geopoint.document.GeoPointField.TermEncoding} parameter
**/
- public GeoPointDistanceQuery(final String field, final TermEncoding termEncoding, final double centerLon, final double centerLat, final double radiusMeters) {
- this(field, termEncoding, GeoUtils.circleToBBox(centerLon, centerLat, radiusMeters), centerLon, centerLat, radiusMeters);
+ public GeoPointDistanceQuery(final String field, final TermEncoding termEncoding, final double centerLat, final double centerLon, final double radiusMeters) {
+ this(field, termEncoding, GeoUtils.circleToBBox(centerLat, centerLon, radiusMeters), centerLat, centerLon, radiusMeters);
}
- private GeoPointDistanceQuery(final String field, final TermEncoding termEncoding, final GeoRect bbox, final double centerLon,
- final double centerLat, final double radiusMeters) {
- super(field, termEncoding, bbox.minLon, bbox.minLat, bbox.maxLon, bbox.maxLat);
+ private GeoPointDistanceQuery(final String field, final TermEncoding termEncoding, final GeoRect bbox,
+ final double centerLat, final double centerLon, final double radiusMeters) {
+ super(field, termEncoding, bbox.minLat, bbox.maxLat, bbox.minLon, bbox.maxLon);
{
// check longitudinal overlap (restrict distance to maximum longitudinal radius)
// todo this restriction technically shouldn't be needed,
// its only purpose is to ensure the bounding box doesn't self overlap.
- final double maxRadius = GeoDistanceUtils.maxRadialDistanceMeters(centerLon, centerLat);
+ final double maxRadius = GeoDistanceUtils.maxRadialDistanceMeters(centerLat, centerLon);
if (radiusMeters > maxRadius) {
throw new IllegalArgumentException("radiusMeters " + radiusMeters + " exceeds maxRadius [" + maxRadius
- + "] at location [" + centerLon + " " + centerLat + "]");
+ + "] at location [" + centerLat + " " + centerLon + "]");
}
}
- if (GeoUtils.isValidLon(centerLon) == false) {
- throw new IllegalArgumentException("invalid centerLon " + centerLon);
- }
-
if (GeoUtils.isValidLat(centerLat) == false) {
throw new IllegalArgumentException("invalid centerLat " + centerLat);
}
+ if (GeoUtils.isValidLon(centerLon) == false) {
+ throw new IllegalArgumentException("invalid centerLon " + centerLon);
+ }
+
if (radiusMeters <= 0.0) {
throw new IllegalArgumentException("invalid radiusMeters " + radiusMeters);
}
- this.centerLon = centerLon;
this.centerLat = centerLat;
+ this.centerLon = centerLon;
this.radiusMeters = radiusMeters;
}
@@ -110,7 +110,7 @@ public class GeoPointDistanceQuery extends GeoPointInBBoxQuery {
unwrappedLon += -360.0D;
}
GeoPointDistanceQueryImpl left = new GeoPointDistanceQueryImpl(field, termEncoding, this, unwrappedLon,
- new GeoRect(GeoUtils.MIN_LON_INCL, maxLon, minLat, maxLat));
+ new GeoRect(minLat, maxLat, GeoUtils.MIN_LON_INCL, maxLon));
bqb.add(new BooleanClause(left, BooleanClause.Occur.SHOULD));
if (unwrappedLon < maxLon) {
@@ -118,13 +118,13 @@ public class GeoPointDistanceQuery extends GeoPointInBBoxQuery {
unwrappedLon += 360.0D;
}
GeoPointDistanceQueryImpl right = new GeoPointDistanceQueryImpl(field, termEncoding, this, unwrappedLon,
- new GeoRect(minLon, GeoUtils.MAX_LON_INCL, minLat, maxLat));
+ new GeoRect(minLat, maxLat, minLon, GeoUtils.MAX_LON_INCL));
bqb.add(new BooleanClause(right, BooleanClause.Occur.SHOULD));
return bqb.build();
}
return new GeoPointDistanceQueryImpl(field, termEncoding, this, centerLon,
- new GeoRect(this.minLon, this.maxLon, this.minLat, this.maxLat));
+ new GeoRect(this.minLat, this.maxLat, this.minLon, this.maxLon));
}
@Override
@@ -166,9 +166,9 @@ public class GeoPointDistanceQuery extends GeoPointInBBoxQuery {
sb.append(':');
}
return sb.append( " Center: [")
- .append(centerLon)
- .append(',')
.append(centerLat)
+ .append(',')
+ .append(centerLon)
.append(']')
.append(" Distance: ")
.append(radiusMeters)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQueryImpl.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQueryImpl.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQueryImpl.java
index 6a54e23..8f50db5 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQueryImpl.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceQueryImpl.java
@@ -32,7 +32,7 @@ final class GeoPointDistanceQueryImpl extends GeoPointInBBoxQueryImpl {
GeoPointDistanceQueryImpl(final String field, final TermEncoding termEncoding, final GeoPointDistanceQuery q,
final double centerLonUnwrapped, final GeoRect bbox) {
- super(field, termEncoding, bbox.minLon, bbox.minLat, bbox.maxLon, bbox.maxLat);
+ super(field, termEncoding, bbox.minLat, bbox.maxLat, bbox.minLon, bbox.maxLon);
distanceQuery = q;
centerLon = centerLonUnwrapped;
}
@@ -53,20 +53,21 @@ final class GeoPointDistanceQueryImpl extends GeoPointInBBoxQueryImpl {
}
@Override
- protected boolean cellCrosses(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return GeoRelationUtils.rectCrossesCircle(minLon, minLat, maxLon, maxLat,
- centerLon, distanceQuery.centerLat, distanceQuery.radiusMeters, true);
+ protected boolean cellCrosses(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return GeoRelationUtils.rectCrossesCircle(minLat, maxLat, minLon, maxLon,
+ distanceQuery.centerLat, centerLon, distanceQuery.radiusMeters, true);
}
@Override
- protected boolean cellWithin(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return GeoRelationUtils.rectWithinCircle(minLon, minLat, maxLon, maxLat,
- centerLon, distanceQuery.centerLat, distanceQuery.radiusMeters, true);
+ protected boolean cellWithin(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return GeoRelationUtils.rectWithinCircle(minLat, maxLat, minLon, maxLon,
+ distanceQuery.centerLat, centerLon,
+ distanceQuery.radiusMeters, true);
}
@Override
- protected boolean cellIntersectsShape(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return cellCrosses(minLon, minLat, maxLon, maxLat);
+ protected boolean cellIntersectsShape(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return cellCrosses(minLat, maxLat, minLon, maxLon);
}
/**
@@ -76,7 +77,7 @@ final class GeoPointDistanceQueryImpl extends GeoPointInBBoxQueryImpl {
* {@link org.apache.lucene.util.SloppyMath#haversinMeters(double, double, double, double)} method.
*/
@Override
- protected boolean postFilter(final double lon, final double lat) {
+ protected boolean postFilter(final double lat, final double lon) {
return SloppyMath.haversinMeters(distanceQuery.centerLat, centerLon, lat, lon) <= distanceQuery.radiusMeters;
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceRangeQuery.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceRangeQuery.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceRangeQuery.java
index f24aa6a..bdfbb88 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceRangeQuery.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointDistanceRangeQuery.java
@@ -37,9 +37,9 @@ public final class GeoPointDistanceRangeQuery extends GeoPointDistanceQuery {
* Constructs a query for all {@link org.apache.lucene.spatial.geopoint.document.GeoPointField} types within a minimum / maximum
* distance (in meters) range from a given point
*/
- public GeoPointDistanceRangeQuery(final String field, final double centerLon, final double centerLat,
+ public GeoPointDistanceRangeQuery(final String field, final double centerLat, final double centerLon,
final double minRadiusMeters, final double maxRadiusMeters) {
- this(field, TermEncoding.PREFIX, centerLon, centerLat, minRadiusMeters, maxRadiusMeters);
+ this(field, TermEncoding.PREFIX, centerLat, centerLon, minRadiusMeters, maxRadiusMeters);
}
/**
@@ -47,9 +47,9 @@ public final class GeoPointDistanceRangeQuery extends GeoPointDistanceQuery {
* distance (in meters) range from a given point. Accepts an optional
* {@link org.apache.lucene.spatial.geopoint.document.GeoPointField.TermEncoding}
*/
- public GeoPointDistanceRangeQuery(final String field, final TermEncoding termEncoding, final double centerLon, final double centerLat,
+ public GeoPointDistanceRangeQuery(final String field, final TermEncoding termEncoding, final double centerLat, final double centerLon,
final double minRadiusMeters, final double maxRadius) {
- super(field, termEncoding, centerLon, centerLat, maxRadius);
+ super(field, termEncoding, centerLat, centerLon, maxRadius);
this.minRadiusMeters = minRadiusMeters;
}
@@ -64,7 +64,7 @@ public final class GeoPointDistanceRangeQuery extends GeoPointDistanceQuery {
BooleanQuery.Builder bqb = new BooleanQuery.Builder();
// create a new exclusion query
- GeoPointDistanceQuery exclude = new GeoPointDistanceQuery(field, termEncoding, centerLon, centerLat, minRadiusMeters);
+ GeoPointDistanceQuery exclude = new GeoPointDistanceQuery(field, termEncoding, centerLat, centerLon, minRadiusMeters);
// full map search
// if (radiusMeters >= GeoProjectionUtils.SEMIMINOR_AXIS) {
// bqb.add(new BooleanClause(new GeoPointInBBoxQuery(this.field, -180.0, -90.0, 180.0, 90.0), BooleanClause.Occur.MUST));
@@ -87,9 +87,9 @@ public final class GeoPointDistanceRangeQuery extends GeoPointDistanceQuery {
sb.append(':');
}
return sb.append( " Center: [")
- .append(centerLon)
- .append(',')
.append(centerLat)
+ .append(',')
+ .append(centerLon)
.append(']')
.append(" From Distance: ")
.append(minRadiusMeters)
@@ -98,14 +98,14 @@ public final class GeoPointDistanceRangeQuery extends GeoPointDistanceQuery {
.append(radiusMeters)
.append(" m")
.append(" Lower Left: [")
- .append(minLon)
- .append(',')
.append(minLat)
+ .append(',')
+ .append(minLon)
.append(']')
.append(" Upper Right: [")
- .append(maxLon)
- .append(',')
.append(maxLat)
+ .append(',')
+ .append(maxLon)
.append("]")
.toString();
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQuery.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQuery.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQuery.java
index 32c0aec..f81f37e 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQuery.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQuery.java
@@ -47,14 +47,14 @@ import org.apache.lucene.spatial.util.GeoUtils;
public class GeoPointInBBoxQuery extends Query {
/** field name */
protected final String field;
- /** minimum longitude value (in degrees) */
- protected final double minLon;
/** minimum latitude value (in degrees) */
protected final double minLat;
- /** maximum longitude value (in degrees) */
- protected final double maxLon;
+ /** minimum longitude value (in degrees) */
+ protected final double minLon;
/** maximum latitude value (in degrees) */
protected final double maxLat;
+ /** maximum longitude value (in degrees) */
+ protected final double maxLon;
/** term encoding enum to define how the points are encoded (PREFIX or NUMERIC) */
protected final TermEncoding termEncoding;
@@ -62,28 +62,28 @@ public class GeoPointInBBoxQuery extends Query {
* Constructs a query for all {@link org.apache.lucene.spatial.geopoint.document.GeoPointField} types that fall within a
* defined bounding box
*/
- public GeoPointInBBoxQuery(final String field, final double minLon, final double minLat, final double maxLon, final double maxLat) {
- this(field, TermEncoding.PREFIX, minLon, minLat, maxLon, maxLat);
+ public GeoPointInBBoxQuery(final String field, final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ this(field, TermEncoding.PREFIX, minLat, maxLat, minLon, maxLon);
}
/**
* Constructs a query for all {@link org.apache.lucene.spatial.geopoint.document.GeoPointField} types that fall within a
* defined bounding box. Accepts optional {@link org.apache.lucene.spatial.geopoint.document.GeoPointField.TermEncoding} parameter
*/
- public GeoPointInBBoxQuery(final String field, final TermEncoding termEncoding, final double minLon, final double minLat, final double maxLon, final double maxLat) {
+ public GeoPointInBBoxQuery(final String field, final TermEncoding termEncoding, final double minLat, final double maxLat, final double minLon, final double maxLon) {
this.field = field;
- this.minLon = minLon;
this.minLat = minLat;
- this.maxLon = maxLon;
this.maxLat = maxLat;
+ this.minLon = minLon;
+ this.maxLon = maxLon;
this.termEncoding = termEncoding;
}
@Override
public Query rewrite(IndexReader reader) {
// short-circuit to match all if specifying the whole map
- if (minLon == GeoUtils.MIN_LON_INCL && maxLon == GeoUtils.MAX_LON_INCL
- && minLat == GeoUtils.MIN_LAT_INCL && maxLat == GeoUtils.MAX_LAT_INCL) {
+ if (minLat == GeoUtils.MIN_LAT_INCL && maxLat == GeoUtils.MAX_LAT_INCL &&
+ minLon == GeoUtils.MIN_LON_INCL && maxLon == GeoUtils.MAX_LON_INCL) {
// FieldValueQuery is valid since DocValues are *required* for GeoPointField
return new FieldValueQuery(field);
}
@@ -91,13 +91,13 @@ public class GeoPointInBBoxQuery extends Query {
if (maxLon < minLon) {
BooleanQuery.Builder bqb = new BooleanQuery.Builder();
- GeoPointInBBoxQueryImpl left = new GeoPointInBBoxQueryImpl(field, termEncoding, -180.0D, minLat, maxLon, maxLat);
+ GeoPointInBBoxQueryImpl left = new GeoPointInBBoxQueryImpl(field, termEncoding, minLat, maxLat, -180.0D, maxLon);
bqb.add(new BooleanClause(left, BooleanClause.Occur.SHOULD));
- GeoPointInBBoxQueryImpl right = new GeoPointInBBoxQueryImpl(field, termEncoding, minLon, minLat, 180.0D, maxLat);
+ GeoPointInBBoxQueryImpl right = new GeoPointInBBoxQueryImpl(field, termEncoding, minLat, maxLat, minLon, 180.0D);
bqb.add(new BooleanClause(right, BooleanClause.Occur.SHOULD));
return bqb.build();
}
- return new GeoPointInBBoxQueryImpl(field, termEncoding, minLon, minLat, maxLon, maxLat);
+ return new GeoPointInBBoxQueryImpl(field, termEncoding, minLat, maxLat, minLon, maxLon);
}
@Override
@@ -111,14 +111,14 @@ public class GeoPointInBBoxQuery extends Query {
sb.append(':');
}
return sb.append(" Lower Left: [")
- .append(minLon)
- .append(',')
.append(minLat)
+ .append(',')
+ .append(minLon)
.append(']')
.append(" Upper Right: [")
- .append(maxLon)
- .append(',')
.append(maxLat)
+ .append(',')
+ .append(maxLon)
.append("]")
.toString();
}
@@ -131,10 +131,10 @@ public class GeoPointInBBoxQuery extends Query {
GeoPointInBBoxQuery that = (GeoPointInBBoxQuery) o;
- if (Double.compare(that.maxLat, maxLat) != 0) return false;
- if (Double.compare(that.maxLon, maxLon) != 0) return false;
if (Double.compare(that.minLat, minLat) != 0) return false;
+ if (Double.compare(that.maxLat, maxLat) != 0) return false;
if (Double.compare(that.minLon, minLon) != 0) return false;
+ if (Double.compare(that.maxLon, maxLon) != 0) return false;
if (!field.equals(that.field)) return false;
return true;
@@ -145,14 +145,14 @@ public class GeoPointInBBoxQuery extends Query {
int result = super.hashCode();
long temp;
result = 31 * result + field.hashCode();
- temp = Double.doubleToLongBits(minLon);
- result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(minLat);
result = 31 * result + (int) (temp ^ (temp >>> 32));
- temp = Double.doubleToLongBits(maxLon);
- result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(maxLat);
result = 31 * result + (int) (temp ^ (temp >>> 32));
+ temp = Double.doubleToLongBits(minLon);
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
+ temp = Double.doubleToLongBits(maxLon);
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
@@ -161,23 +161,23 @@ public class GeoPointInBBoxQuery extends Query {
return this.field;
}
- /** getter method for retrieving the minimum longitude (in degrees) */
- public final double getMinLon() {
- return this.minLon;
- }
-
/** getter method for retrieving the minimum latitude (in degrees) */
public final double getMinLat() {
return this.minLat;
}
- /** getter method for retrieving the maximum longitude (in degrees) */
- public final double getMaxLon() {
- return this.maxLon;
- }
-
/** getter method for retrieving the maximum latitude (in degrees) */
public final double getMaxLat() {
return this.maxLat;
}
+
+ /** getter method for retrieving the minimum longitude (in degrees) */
+ public final double getMinLon() {
+ return this.minLon;
+ }
+
+ /** getter method for retrieving the maximum longitude (in degrees) */
+ public final double getMaxLon() {
+ return this.maxLon;
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQueryImpl.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQueryImpl.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQueryImpl.java
index 107b136..c19e6d2 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQueryImpl.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInBBoxQueryImpl.java
@@ -36,8 +36,8 @@ class GeoPointInBBoxQueryImpl extends GeoPointMultiTermQuery {
* @param maxLon upper longitude (x) value of the bounding box
* @param maxLat upper latitude (y) value of the bounding box
*/
- GeoPointInBBoxQueryImpl(final String field, final TermEncoding termEncoding, final double minLon, final double minLat, final double maxLon, final double maxLat) {
- super(field, termEncoding, minLon, minLat, maxLon, maxLat);
+ GeoPointInBBoxQueryImpl(final String field, final TermEncoding termEncoding, final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ super(field, termEncoding, minLat, maxLat, minLon, maxLon);
}
@Override
@@ -50,8 +50,8 @@ class GeoPointInBBoxQueryImpl extends GeoPointMultiTermQuery {
final short shiftFactor;
// compute diagonal radius
- double midLon = (minLon + maxLon) * 0.5;
double midLat = (minLat + maxLat) * 0.5;
+ double midLon = (minLon + maxLon) * 0.5;
if (SloppyMath.haversinMeters(minLat, minLon, midLat, midLon) > 1000000) {
shiftFactor = 5;
@@ -76,26 +76,29 @@ class GeoPointInBBoxQueryImpl extends GeoPointMultiTermQuery {
* Determine whether the quad-cell crosses the shape
*/
@Override
- protected boolean cellCrosses(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return GeoRelationUtils.rectCrosses(minLon, minLat, maxLon, maxLat, GeoPointInBBoxQueryImpl.this.minLon,
- GeoPointInBBoxQueryImpl.this.minLat, GeoPointInBBoxQueryImpl.this.maxLon, GeoPointInBBoxQueryImpl.this.maxLat); }
+ protected boolean cellCrosses(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return GeoRelationUtils.rectCrosses(minLat, maxLat, minLon, maxLon, GeoPointInBBoxQueryImpl.this.minLat,
+ GeoPointInBBoxQueryImpl.this.maxLat, GeoPointInBBoxQueryImpl.this.minLon, GeoPointInBBoxQueryImpl.this.maxLon);
+ }
/**
* Determine whether quad-cell is within the shape
*/
@Override
- protected boolean cellWithin(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return GeoRelationUtils.rectWithin(minLon, minLat, maxLon, maxLat, GeoPointInBBoxQueryImpl.this.minLon,
- GeoPointInBBoxQueryImpl.this.minLat, GeoPointInBBoxQueryImpl.this.maxLon, GeoPointInBBoxQueryImpl.this.maxLat); }
+ protected boolean cellWithin(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return GeoRelationUtils.rectWithin(minLat, maxLat, minLon, maxLon, GeoPointInBBoxQueryImpl.this.minLat,
+ GeoPointInBBoxQueryImpl.this.maxLat,
+ GeoPointInBBoxQueryImpl.this.minLon, GeoPointInBBoxQueryImpl.this.maxLon);
+ }
@Override
- protected boolean cellIntersectsShape(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return cellIntersectsMBR(minLon, minLat, maxLon, maxLat);
+ protected boolean cellIntersectsShape(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return cellIntersectsMBR(minLat, maxLat, minLon, maxLon);
}
@Override
- protected boolean postFilter(final double lon, final double lat) {
- return GeoRelationUtils.pointInRectPrecise(lon, lat, minLon, minLat, maxLon, maxLat);
+ protected boolean postFilter(final double lat, final double lon) {
+ return GeoRelationUtils.pointInRectPrecise(lat, lon, minLat, maxLat, minLon, maxLon);
}
}
@@ -108,10 +111,10 @@ class GeoPointInBBoxQueryImpl extends GeoPointMultiTermQuery {
GeoPointInBBoxQueryImpl that = (GeoPointInBBoxQueryImpl) o;
- if (Double.compare(that.maxLat, maxLat) != 0) return false;
- if (Double.compare(that.maxLon, maxLon) != 0) return false;
if (Double.compare(that.minLat, minLat) != 0) return false;
+ if (Double.compare(that.maxLat, maxLat) != 0) return false;
if (Double.compare(that.minLon, minLon) != 0) return false;
+ if (Double.compare(that.maxLon, maxLon) != 0) return false;
return true;
}
@@ -120,14 +123,14 @@ class GeoPointInBBoxQueryImpl extends GeoPointMultiTermQuery {
public int hashCode() {
int result = super.hashCode();
long temp;
- temp = Double.doubleToLongBits(minLon);
- result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(minLat);
result = 31 * result + (int) (temp ^ (temp >>> 32));
- temp = Double.doubleToLongBits(maxLon);
- result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(maxLat);
result = 31 * result + (int) (temp ^ (temp >>> 32));
+ temp = Double.doubleToLongBits(minLon);
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
+ temp = Double.doubleToLongBits(maxLon);
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
@@ -142,14 +145,14 @@ class GeoPointInBBoxQueryImpl extends GeoPointMultiTermQuery {
sb.append(':');
}
return sb.append(" Lower Left: [")
- .append(minLon)
- .append(',')
.append(minLat)
+ .append(',')
+ .append(minLon)
.append(']')
.append(" Upper Right: [")
- .append(maxLon)
- .append(',')
.append(maxLat)
+ .append(',')
+ .append(maxLon)
.append("]")
.toString();
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQuery.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQuery.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQuery.java
index ef8c2ff..f43aaf2 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQuery.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQuery.java
@@ -47,30 +47,30 @@ import org.apache.lucene.spatial.util.GeoUtils;
public final class GeoPointInPolygonQuery extends GeoPointInBBoxQuery {
// polygon position arrays - this avoids the use of any objects or
// or geo library dependencies
- /** array of x (longitude) values (in degrees) */
- protected final double[] x;
/** array of y (latitude) values (in degrees) */
- protected final double[] y;
+ protected final double[] polyLats;
+ /** array of x (longitude) values (in degrees) */
+ protected final double[] polyLons;
/**
* Constructs a new GeoPolygonQuery that will match encoded {@link org.apache.lucene.spatial.geopoint.document.GeoPointField} terms
* that fall within or on the boundary of the polygon defined by the input parameters.
*/
- public GeoPointInPolygonQuery(final String field, final double[] polyLons, final double[] polyLats) {
- this(field, TermEncoding.PREFIX, GeoUtils.polyToBBox(polyLons, polyLats), polyLons, polyLats);
+ public GeoPointInPolygonQuery(final String field, final double[] polyLats, final double[] polyLons) {
+ this(field, TermEncoding.PREFIX, GeoUtils.polyToBBox(polyLats, polyLons), polyLats, polyLons);
}
/**
* Constructs a new GeoPolygonQuery that will match encoded {@link org.apache.lucene.spatial.geopoint.document.GeoPointField} terms
* that fall within or on the boundary of the polygon defined by the input parameters.
*/
- public GeoPointInPolygonQuery(final String field, final TermEncoding termEncoding, final double[] polyLons, final double[] polyLats) {
- this(field, termEncoding, GeoUtils.polyToBBox(polyLons, polyLats), polyLons, polyLats);
+ public GeoPointInPolygonQuery(final String field, final TermEncoding termEncoding, final double[] polyLats, final double[] polyLons) {
+ this(field, termEncoding, GeoUtils.polyToBBox(polyLats, polyLons), polyLats, polyLons);
}
/** Common constructor, used only internally. */
- private GeoPointInPolygonQuery(final String field, TermEncoding termEncoding, GeoRect bbox, final double[] polyLons, final double[] polyLats) {
- super(field, termEncoding, bbox.minLon, bbox.minLat, bbox.maxLon, bbox.maxLat);
+ private GeoPointInPolygonQuery(final String field, TermEncoding termEncoding, GeoRect bbox, final double[] polyLats, final double[] polyLons) {
+ super(field, termEncoding, bbox.minLat, bbox.maxLat, bbox.minLon, bbox.maxLon);
if (polyLats.length != polyLons.length) {
throw new IllegalArgumentException("polyLats and polyLons must be equal length");
}
@@ -84,14 +84,14 @@ public final class GeoPointInPolygonQuery extends GeoPointInBBoxQuery {
throw new IllegalArgumentException("first and last points of the polygon must be the same (it must close itself): polyLons[0]=" + polyLons[0] + " polyLons[" + (polyLons.length-1) + "]=" + polyLons[polyLons.length-1]);
}
- this.x = polyLons;
- this.y = polyLats;
+ this.polyLons = polyLons;
+ this.polyLats = polyLats;
}
/** throw exception if trying to change rewrite method */
@Override
public Query rewrite(IndexReader reader) {
- return new GeoPointInPolygonQueryImpl(field, termEncoding, this, this.minLon, this.minLat, this.maxLon, this.maxLat);
+ return new GeoPointInPolygonQueryImpl(field, termEncoding, this, this.minLat, this.maxLat, this.minLon, this.maxLon);
}
@Override
@@ -102,8 +102,8 @@ public final class GeoPointInPolygonQuery extends GeoPointInBBoxQuery {
GeoPointInPolygonQuery that = (GeoPointInPolygonQuery) o;
- if (!Arrays.equals(x, that.x)) return false;
- if (!Arrays.equals(y, that.y)) return false;
+ if (!Arrays.equals(polyLats, that.polyLats)) return false;
+ if (!Arrays.equals(polyLons, that.polyLons)) return false;
return true;
}
@@ -111,15 +111,15 @@ public final class GeoPointInPolygonQuery extends GeoPointInBBoxQuery {
@Override
public int hashCode() {
int result = super.hashCode();
- result = 31 * result + (x != null ? Arrays.hashCode(x) : 0);
- result = 31 * result + (y != null ? Arrays.hashCode(y) : 0);
+ result = 31 * result + (polyLats != null ? Arrays.hashCode(polyLats) : 0);
+ result = 31 * result + (polyLons != null ? Arrays.hashCode(polyLons) : 0);
return result;
}
/** print out this polygon query */
@Override
public String toString(String field) {
- assert x.length == y.length;
+ assert polyLats.length == polyLons.length;
final StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
@@ -130,11 +130,11 @@ public final class GeoPointInPolygonQuery extends GeoPointInBBoxQuery {
sb.append(':');
}
sb.append(" Points: ");
- for (int i=0; i<x.length; ++i) {
+ for (int i=0; i<polyLats.length; ++i) {
sb.append("[")
- .append(x[i])
+ .append(polyLats[i])
.append(", ")
- .append(y[i])
+ .append(polyLons[i])
.append("] ");
}
@@ -146,7 +146,7 @@ public final class GeoPointInPolygonQuery extends GeoPointInBBoxQuery {
* The returned array is not a copy so do not change it!
*/
public double[] getLons() {
- return this.x;
+ return this.polyLons;
}
/**
@@ -154,6 +154,6 @@ public final class GeoPointInPolygonQuery extends GeoPointInBBoxQuery {
* The returned array is not a copy so do not change it!
*/
public double[] getLats() {
- return this.y;
+ return this.polyLats;
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQueryImpl.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQueryImpl.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQueryImpl.java
index 35a3950..acace24 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQueryImpl.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointInPolygonQueryImpl.java
@@ -28,8 +28,8 @@ final class GeoPointInPolygonQueryImpl extends GeoPointInBBoxQueryImpl {
private final GeoPointInPolygonQuery polygonQuery;
GeoPointInPolygonQueryImpl(final String field, final TermEncoding termEncoding, final GeoPointInPolygonQuery q,
- final double minLon, final double minLat, final double maxLon, final double maxLat) {
- super(field, termEncoding, minLon, minLat, maxLon, maxLat);
+ final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ super(field, termEncoding, minLat, maxLat, minLon, maxLon);
polygonQuery = q;
}
@@ -53,21 +53,21 @@ final class GeoPointInPolygonQueryImpl extends GeoPointInBBoxQueryImpl {
}
@Override
- protected boolean cellCrosses(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return GeoRelationUtils.rectCrossesPolyApprox(minLon, minLat, maxLon, maxLat, polygonQuery.x, polygonQuery.y,
- polygonQuery.minLon, polygonQuery.minLat, polygonQuery.maxLon, polygonQuery.maxLat);
+ protected boolean cellCrosses(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return GeoRelationUtils.rectCrossesPolyApprox(minLat, maxLat, minLon, maxLon, polygonQuery.polyLats, polygonQuery.polyLons,
+ polygonQuery.minLat, polygonQuery.maxLat, polygonQuery.minLon, polygonQuery.maxLon);
}
@Override
- protected boolean cellWithin(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return GeoRelationUtils.rectWithinPolyApprox(minLon, minLat, maxLon, maxLat, polygonQuery.x, polygonQuery.y,
- polygonQuery.minLon, polygonQuery.minLat, polygonQuery.maxLon, polygonQuery.maxLat);
+ protected boolean cellWithin(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return GeoRelationUtils.rectWithinPolyApprox(minLat, maxLat, minLon, maxLon, polygonQuery.polyLats, polygonQuery.polyLons,
+ polygonQuery.minLat, polygonQuery.maxLat, polygonQuery.minLon, polygonQuery.maxLon);
}
@Override
- protected boolean cellIntersectsShape(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return cellContains(minLon, minLat, maxLon, maxLat) || cellWithin(minLon, minLat, maxLon, maxLat)
- || cellCrosses(minLon, minLat, maxLon, maxLat);
+ protected boolean cellIntersectsShape(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return cellContains(minLat, maxLat, minLon, maxLon) || cellWithin(minLat, maxLat, minLon, maxLon)
+ || cellCrosses(minLat, maxLat, minLon, maxLon);
}
/**
@@ -78,8 +78,8 @@ final class GeoPointInPolygonQueryImpl extends GeoPointInBBoxQueryImpl {
* {@link org.apache.lucene.spatial.util.GeoRelationUtils#pointInPolygon} method.
*/
@Override
- protected boolean postFilter(final double lon, final double lat) {
- return GeoRelationUtils.pointInPolygon(polygonQuery.x, polygonQuery.y, lat, lon);
+ protected boolean postFilter(final double lat, final double lon) {
+ return GeoRelationUtils.pointInPolygon(polygonQuery.polyLats, polygonQuery.polyLons, lat, lon);
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointMultiTermQuery.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointMultiTermQuery.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointMultiTermQuery.java
index edbd53d..a63c4d6 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointMultiTermQuery.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointMultiTermQuery.java
@@ -52,28 +52,28 @@ abstract class GeoPointMultiTermQuery extends MultiTermQuery {
* Constructs a query matching terms that cannot be represented with a single
* Term.
*/
- public GeoPointMultiTermQuery(String field, final TermEncoding termEncoding, final double minLon, final double minLat, final double maxLon, final double maxLat) {
+ public GeoPointMultiTermQuery(String field, final TermEncoding termEncoding, final double minLat, final double maxLat, final double minLon, final double maxLon) {
super(field);
- if (GeoUtils.isValidLon(minLon) == false) {
- throw new IllegalArgumentException("invalid minLon " + minLon);
- }
- if (GeoUtils.isValidLon(maxLon) == false) {
- throw new IllegalArgumentException("invalid maxLon " + maxLon);
- }
if (GeoUtils.isValidLat(minLat) == false) {
throw new IllegalArgumentException("invalid minLat " + minLat);
}
if (GeoUtils.isValidLat(maxLat) == false) {
throw new IllegalArgumentException("invalid maxLat " + maxLat);
}
+ if (GeoUtils.isValidLon(minLon) == false) {
+ throw new IllegalArgumentException("invalid minLon " + minLon);
+ }
+ if (GeoUtils.isValidLon(maxLon) == false) {
+ throw new IllegalArgumentException("invalid maxLon " + maxLon);
+ }
- final long minHash = GeoEncodingUtils.mortonHash(minLon, minLat);
- final long maxHash = GeoEncodingUtils.mortonHash(maxLon, maxLat);
- this.minLon = GeoEncodingUtils.mortonUnhashLon(minHash);
+ final long minHash = GeoEncodingUtils.mortonHash(minLat, minLon);
+ final long maxHash = GeoEncodingUtils.mortonHash(maxLat, maxLon);
this.minLat = GeoEncodingUtils.mortonUnhashLat(minHash);
- this.maxLon = GeoEncodingUtils.mortonUnhashLon(maxHash);
this.maxLat = GeoEncodingUtils.mortonUnhashLat(maxHash);
+ this.minLon = GeoEncodingUtils.mortonUnhashLon(minHash);
+ this.maxLon = GeoEncodingUtils.mortonUnhashLon(maxHash);
this.maxShift = computeMaxShift();
this.termEncoding = termEncoding;
@@ -133,34 +133,34 @@ abstract class GeoPointMultiTermQuery extends MultiTermQuery {
/**
* Primary driver for cells intersecting shape boundaries
*/
- protected boolean cellIntersectsMBR(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return GeoRelationUtils.rectIntersects(minLon, minLat, maxLon, maxLat, geoPointQuery.minLon, geoPointQuery.minLat,
- geoPointQuery.maxLon, geoPointQuery.maxLat);
+ protected boolean cellIntersectsMBR(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return GeoRelationUtils.rectIntersects(minLat, maxLat, minLon, maxLon, geoPointQuery.minLat, geoPointQuery.maxLat,
+ geoPointQuery.minLon, geoPointQuery.maxLon);
}
/**
* Return whether quad-cell contains the bounding box of this shape
*/
- protected boolean cellContains(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return GeoRelationUtils.rectWithin(geoPointQuery.minLon, geoPointQuery.minLat, geoPointQuery.maxLon,
- geoPointQuery.maxLat, minLon, minLat, maxLon, maxLat);
+ protected boolean cellContains(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return GeoRelationUtils.rectWithin(geoPointQuery.minLat, geoPointQuery.maxLat, geoPointQuery.minLon,
+ geoPointQuery.maxLon, minLat, maxLat, minLon, maxLon);
}
/**
* Determine whether the quad-cell crosses the shape
*/
- abstract protected boolean cellCrosses(final double minLon, final double minLat, final double maxLon, final double maxLat);
+ abstract protected boolean cellCrosses(final double minLat, final double maxLat, final double minLon, final double maxLon);
/**
* Determine whether quad-cell is within the shape
*/
- abstract protected boolean cellWithin(final double minLon, final double minLat, final double maxLon, final double maxLat);
+ abstract protected boolean cellWithin(final double minLat, final double maxLat, final double minLon, final double maxLon);
/**
* Default shape is a rectangle, so this returns the same as {@code cellIntersectsMBR}
*/
- abstract protected boolean cellIntersectsShape(final double minLon, final double minLat, final double maxLon, final double maxLat);
+ abstract protected boolean cellIntersectsShape(final double minLat, final double maxLat, final double minLon, final double maxLon);
- abstract protected boolean postFilter(final double lon, final double lat);
+ abstract protected boolean postFilter(final double lat, final double lon);
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointNumericTermsEnum.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointNumericTermsEnum.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointNumericTermsEnum.java
index 120df7d..071ab1e 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointNumericTermsEnum.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointNumericTermsEnum.java
@@ -87,8 +87,8 @@ final class GeoPointNumericTermsEnum extends GeoPointTermsEnum {
final short level = (short)((GeoEncodingUtils.BITS<<1)-res>>>1);
// if cell is within and a factor of the precision step, or it crosses the edge of the shape add the range
- final boolean within = res % GeoPointField.PRECISION_STEP == 0 && relationImpl.cellWithin(minLon, minLat, maxLon, maxLat);
- if (within || (level == DETAIL_LEVEL && relationImpl.cellIntersectsShape(minLon, minLat, maxLon, maxLat))) {
+ final boolean within = res % GeoPointField.PRECISION_STEP == 0 && relationImpl.cellWithin(minLat, maxLat, minLon, maxLon);
+ if (within || (level == DETAIL_LEVEL && relationImpl.cellIntersectsShape(minLat, maxLat, minLon, maxLon))) {
final short nextRes = (short)(res-1);
if (nextRes % GeoPointField.PRECISION_STEP == 0) {
rangeBounds.add(new Range(start, nextRes, !within));
@@ -96,7 +96,7 @@ final class GeoPointNumericTermsEnum extends GeoPointTermsEnum {
} else {
rangeBounds.add(new Range(start, res, !within));
}
- } else if (level < DETAIL_LEVEL && relationImpl.cellIntersectsMBR(minLon, minLat, maxLon, maxLat)) {
+ } else if (level < DETAIL_LEVEL && relationImpl.cellIntersectsMBR(minLat, maxLat, minLon, maxLon)) {
computeRange(start, (short) (res - 1));
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointPrefixTermsEnum.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointPrefixTermsEnum.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointPrefixTermsEnum.java
index fbaf68e..eeb58b2 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointPrefixTermsEnum.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointPrefixTermsEnum.java
@@ -58,7 +58,7 @@ final class GeoPointPrefixTermsEnum extends GeoPointTermsEnum {
public GeoPointPrefixTermsEnum(final TermsEnum tenum, final GeoPointMultiTermQuery query) {
super(tenum, query);
- this.start = mortonHash(query.minLon, query.minLat);
+ this.start = mortonHash(query.minLat, query.minLon);
this.currentRange = new Range(0, shift, true);
// start shift at maxShift value (from computeMaxShift)
this.shift = maxShift;
@@ -67,12 +67,12 @@ final class GeoPointPrefixTermsEnum extends GeoPointTermsEnum {
this.currEnd = currStart | mask;
}
- private boolean within(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return relationImpl.cellWithin(minLon, minLat, maxLon, maxLat);
+ private boolean within(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return relationImpl.cellWithin(minLat, maxLat, minLon, maxLon);
}
- private boolean boundary(final double minLon, final double minLat, final double maxLon, final double maxLat) {
- return shift == maxShift && relationImpl.cellIntersectsShape(minLon, minLat, maxLon, maxLat);
+ private boolean boundary(final double minLat, final double maxLat, final double minLon, final double maxLon) {
+ return shift == maxShift && relationImpl.cellIntersectsShape(minLat, maxLat, minLon, maxLon);
}
private boolean nextWithin() {
@@ -100,7 +100,7 @@ final class GeoPointPrefixTermsEnum extends GeoPointTermsEnum {
maxLat = mortonUnhashLat(currEnd);
// within or a boundary
- if ((isWithin = within(minLon, minLat, maxLon, maxLat) == true) || boundary(minLon, minLat, maxLon, maxLat) == true) {
+ if ((isWithin = within(minLat, maxLat, minLon, maxLon) == true) || boundary(minLat, maxLat, minLon, maxLon) == true) {
final int m;
if (isWithin == false || (m = shift % GeoPointField.PRECISION_STEP) == 0) {
setNextRange(isWithin == false);
@@ -116,7 +116,7 @@ final class GeoPointPrefixTermsEnum extends GeoPointTermsEnum {
}
// within cell but not at a depth factor of PRECISION_STEP
- if (isWithin == true || (relationImpl.cellIntersectsMBR(minLon, minLat, maxLon , maxLat) == true && shift != maxShift)) {
+ if (isWithin == true || (relationImpl.cellIntersectsMBR(minLat, maxLat, minLon, maxLon) == true && shift != maxShift)) {
// descend: currStart need not change since shift handles end of range
currEnd = currStart | (1L<<--shift) - 1;
} else {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermQueryConstantScoreWrapper.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermQueryConstantScoreWrapper.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermQueryConstantScoreWrapper.java
index 6eea8df..7e97f16 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermQueryConstantScoreWrapper.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermQueryConstantScoreWrapper.java
@@ -140,7 +140,7 @@ final class GeoPointTermQueryConstantScoreWrapper <Q extends GeoPointMultiTermQu
int count = sdv.count();
for (int i = 0; i < count; i++) {
long hash = sdv.valueAt(i);
- if (termsEnum.postFilter(mortonUnhashLon(hash), mortonUnhashLat(hash))) {
+ if (termsEnum.postFilter(mortonUnhashLat(hash), mortonUnhashLon(hash))) {
return true;
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermsEnum.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermsEnum.java b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermsEnum.java
index 9f9e251..d82b340 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermsEnum.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/geopoint/search/GeoPointTermsEnum.java
@@ -98,8 +98,8 @@ abstract class GeoPointTermsEnum extends FilteredTermsEnum {
return AcceptStatus.YES;
}
- protected boolean postFilter(final double lon, final double lat) {
- return relationImpl.postFilter(lon, lat);
+ protected boolean postFilter(final double lat, final double lon) {
+ return relationImpl.postFilter(lat, lon);
}
/**
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoDistanceUtils.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoDistanceUtils.java b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoDistanceUtils.java
index 482ed0f..8956c4b 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoDistanceUtils.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoDistanceUtils.java
@@ -34,68 +34,6 @@ public class GeoDistanceUtils {
}
/**
- * Compute the distance between two geo-points using vincenty distance formula
- * Vincenty uses the oblate spheroid whereas haversine uses unit sphere, this will give roughly
- * 22m better accuracy (in worst case) than haversine
- *
- * @param lonA longitudinal coordinate of point A (in degrees)
- * @param latA latitudinal coordinate of point A (in degrees)
- * @param lonB longitudinal coordinate of point B (in degrees)
- * @param latB latitudinal coordinate of point B (in degrees)
- * @return distance (in meters) between point A and point B
- */
- public static final double vincentyDistance(final double lonA, final double latA, final double lonB, final double latB) {
- final double L = StrictMath.toRadians(lonB - lonA);
- final double oF = 1 - GeoProjectionUtils.FLATTENING;
- final double U1 = StrictMath.atan(oF * StrictMath.tan(StrictMath.toRadians(latA)));
- final double U2 = StrictMath.atan(oF * StrictMath.tan(StrictMath.toRadians(latB)));
- final double sU1 = StrictMath.sin(U1);
- final double cU1 = StrictMath.cos(U1);
- final double sU2 = StrictMath.sin(U2);
- final double cU2 = StrictMath.cos(U2);
-
- double sigma, sinSigma, cosSigma;
- double sinAlpha, cos2Alpha, cos2SigmaM;
- double lambda = L;
- double lambdaP;
- double iters = 100;
- double sinLambda, cosLambda, c;
-
- do {
- sinLambda = StrictMath.sin(lambda);
- cosLambda = Math.cos(lambda);
- sinSigma = Math.sqrt((cU2 * sinLambda) * (cU2 * sinLambda) + (cU1 * sU2 - sU1 * cU2 * cosLambda)
- * (cU1 * sU2 - sU1 * cU2 * cosLambda));
- if (sinSigma == 0) {
- return 0;
- }
-
- cosSigma = sU1 * sU2 + cU1 * cU2 * cosLambda;
- sigma = Math.atan2(sinSigma, cosSigma);
- sinAlpha = cU1 * cU2 * sinLambda / sinSigma;
- cos2Alpha = 1 - sinAlpha * sinAlpha;
- cos2SigmaM = cosSigma - 2 * sU1 * sU2 / cos2Alpha;
-
- c = GeoProjectionUtils.FLATTENING/16 * cos2Alpha * (4 + GeoProjectionUtils.FLATTENING * (4 - 3 * cos2Alpha));
- lambdaP = lambda;
- lambda = L + (1 - c) * GeoProjectionUtils.FLATTENING * sinAlpha * (sigma + c * sinSigma * (cos2SigmaM + c * cosSigma *
- (-1 + 2 * cos2SigmaM * cos2SigmaM)));
- } while (StrictMath.abs(lambda - lambdaP) > 1E-12 && --iters > 0);
-
- if (iters == 0) {
- return 0;
- }
-
- final double uSq = cos2Alpha * (GeoProjectionUtils.SEMIMAJOR_AXIS2 - GeoProjectionUtils.SEMIMINOR_AXIS2) / (GeoProjectionUtils.SEMIMINOR_AXIS2);
- final double A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
- final double B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
- final double deltaSigma = B * sinSigma * (cos2SigmaM + B/4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - B/6 * cos2SigmaM
- * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)));
-
- return (GeoProjectionUtils.SEMIMINOR_AXIS * A * (sigma - deltaSigma));
- }
-
- /**
* Computes distance between two points in a cartesian (x, y, {z - optional}) coordinate system
*/
public static double linearDistance(double[] pt1, double[] pt2) {
@@ -133,11 +71,11 @@ public class GeoDistanceUtils {
/**
* Finds the closest point within a rectangle (defined by rMinX, rMinY, rMaxX, rMaxY) to the given (lon, lat) point
- * the result is provided in closestPt. When the point is outside the rectangle, the closest point is on an edge
+ * the result is provided in closestPt (lat, lon). When the point is outside the rectangle, the closest point is on an edge
* or corner of the rectangle; else, the closest point is the point itself.
*/
- public static void closestPointOnBBox(final double rMinX, final double rMinY, final double rMaxX, final double rMaxY,
- final double lon, final double lat, double[] closestPt) {
+ public static void closestPointOnBBox(final double rMinY, final double rMaxY, final double rMinX, final double rMaxX,
+ final double lat, final double lon, double[] closestPt) {
assert closestPt != null && closestPt.length == 2;
closestPt[0] = 0;
@@ -147,32 +85,32 @@ public class GeoDistanceUtils {
boolean ySet = true;
if (lon > rMaxX) {
- closestPt[0] = rMaxX;
+ closestPt[1] = rMaxX;
} else if (lon < rMinX) {
- closestPt[0] = rMinX;
+ closestPt[1] = rMinX;
} else {
xSet = false;
}
if (lat > rMaxY) {
- closestPt[1] = rMaxY;
+ closestPt[0] = rMaxY;
} else if (lat < rMinY) {
- closestPt[1] = rMinY;
+ closestPt[0] = rMinY;
} else {
ySet = false;
}
- if (closestPt[0] == 0 && xSet == false) {
- closestPt[0] = lon;
+ if (closestPt[0] == 0 && ySet == false) {
+ closestPt[0] = lat;
}
- if (closestPt[1] == 0 && ySet == false) {
- closestPt[1] = lat;
+ if (closestPt[1] == 0 && xSet == false) {
+ closestPt[1] = lon;
}
}
/** Returns the maximum distance/radius (in meters) from the point 'center' before overlapping */
- public static double maxRadialDistanceMeters(final double centerLon, final double centerLat) {
+ public static double maxRadialDistanceMeters(final double centerLat, final double centerLon) {
if (Math.abs(centerLat) == GeoUtils.MAX_LAT_INCL) {
return SloppyMath.haversinMeters(centerLat, centerLon, 0, centerLon);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoEncodingUtils.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoEncodingUtils.java b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoEncodingUtils.java
index 451688d..38eef04 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoEncodingUtils.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoEncodingUtils.java
@@ -32,8 +32,9 @@ import static org.apache.lucene.spatial.util.GeoUtils.MIN_LAT_INCL;
public final class GeoEncodingUtils {
/** number of bits used for quantizing latitude and longitude values */
public static final short BITS = 31;
- private static final double LON_SCALE = (0x1L<<BITS)/360.0D;
+
private static final double LAT_SCALE = (0x1L<<BITS)/180.0D;
+ private static final double LON_SCALE = (0x1L<<BITS)/360.0D;
/**
* The maximum term length (used for <code>byte[]</code> buffer size)
@@ -50,10 +51,10 @@ public final class GeoEncodingUtils {
}
/**
- * encode longitude, latitude geopoint values using morton encoding method
+ * encode latitude, longitude geopoint values using morton encoding method
* https://en.wikipedia.org/wiki/Z-order_curve
*/
- public static final Long mortonHash(final double lon, final double lat) {
+ public static final Long mortonHash(final double lat, final double lon) {
return BitUtil.interleave(scaleLon(lon), scaleLat(lat));
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c5da271b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoHashUtils.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoHashUtils.java b/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoHashUtils.java
deleted file mode 100644
index 49a7571..0000000
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/util/GeoHashUtils.java
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.spatial.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.apache.lucene.util.BitUtil;
-
-/**
- * Utilities for converting to/from the GeoHash standard
- *
- * The geohash long format is represented as lon/lat (x/y) interleaved with the 4 least significant bits
- * representing the level (1-12) [xyxy...xyxyllll]
- *
- * This differs from a morton encoded value which interleaves lat/lon (y/x).
- *
- * @lucene.experimental
- */
-public class GeoHashUtils {
- private static final char[] BASE_32 = {'0', '1', '2', '3', '4', '5', '6',
- '7', '8', '9', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n',
- 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
-
- private static final String BASE_32_STRING = new String(BASE_32);
-
- /** maximum precision for geohash strings */
- public static final int PRECISION = 12;
- private static final short MORTON_OFFSET = (GeoEncodingUtils.BITS<<1) - (PRECISION*5);
-
- // No instance:
- private GeoHashUtils() {
- }
-
- /**
- * Encode lon/lat to the geohash based long format (lon/lat interleaved, 4 least significant bits = level)
- */
- public static final long longEncode(final double lon, final double lat, final int level) {
- // shift to appropriate level
- final short msf = (short)(((12 - level) * 5) + MORTON_OFFSET);
- return ((BitUtil.flipFlop(GeoEncodingUtils.mortonHash(lon, lat)) >>> msf) << 4) | level;
- }
-
- /**
- * Encode from geohash string to the geohash based long format (lon/lat interleaved, 4 least significant bits = level)
- */
- public static final long longEncode(final String hash) {
- int level = hash.length()-1;
- long b;
- long l = 0L;
- for(char c : hash.toCharArray()) {
- b = (long)(BASE_32_STRING.indexOf(c));
- l |= (b<<(level--*5));
- }
- return (l<<4)|hash.length();
- }
-
- /**
- * Encode an existing geohash long to the provided precision
- */
- public static long longEncode(long geohash, int level) {
- final short precision = (short)(geohash & 15);
- if (precision == level) {
- return geohash;
- } else if (precision > level) {
- return ((geohash >>> (((precision - level) * 5) + 4)) << 4) | level;
- }
- return ((geohash >>> 4) << (((level - precision) * 5) + 4) | level);
- }
-
- /**
- * Convert from a morton encoded long from a geohash encoded long
- */
- public static long fromMorton(long morton, int level) {
- long mFlipped = BitUtil.flipFlop(morton);
- mFlipped >>>= (((GeoHashUtils.PRECISION - level) * 5) + MORTON_OFFSET);
- return (mFlipped << 4) | level;
- }
-
- /**
- * Encode to a geohash string from the geohash based long format
- */
- public static final String stringEncode(long geoHashLong) {
- int level = (int)geoHashLong&15;
- geoHashLong >>>= 4;
- char[] chars = new char[level];
- do {
- chars[--level] = BASE_32[(int) (geoHashLong&31L)];
- geoHashLong>>>=5;
- } while(level > 0);
-
- return new String(chars);
- }
-
- /**
- * Encode to a geohash string from full resolution longitude, latitude)
- */
- public static final String stringEncode(final double lon, final double lat) {
- return stringEncode(lon, lat, 12);
- }
-
- /**
- * Encode to a level specific geohash string from full resolution longitude, latitude
- */
- public static final String stringEncode(final double lon, final double lat, final int level) {
- // convert to geohashlong
- final long ghLong = fromMorton(GeoEncodingUtils.mortonHash(lon, lat), level);
- return stringEncode(ghLong);
-
- }
-
- /**
- * Encode to a full precision geohash string from a given morton encoded long value
- */
- public static final String stringEncodeFromMortonLong(final long hashedVal) throws Exception {
- return stringEncode(hashedVal, PRECISION);
- }
-
- /**
- * Encode to a geohash string at a given level from a morton long
- */
- public static final String stringEncodeFromMortonLong(long hashedVal, final int level) {
- // bit twiddle to geohash (since geohash is a swapped (lon/lat) encoding)
- hashedVal = BitUtil.flipFlop(hashedVal);
-
- StringBuilder geoHash = new StringBuilder();
- short precision = 0;
- final short msf = (GeoEncodingUtils.BITS<<1)-5;
- long mask = 31L<<msf;
- do {
- geoHash.append(BASE_32[(int)((mask & hashedVal)>>>(msf-(precision*5)))]);
- // next 5 bits
- mask >>>= 5;
- } while (++precision < level);
- return geoHash.toString();
- }
-
- /**
- * Encode to a morton long value from a given geohash string
- */
- public static final long mortonEncode(final String hash) {
- int level = 11;
- long b;
- long l = 0L;
- for(char c : hash.toCharArray()) {
- b = (long)(BASE_32_STRING.indexOf(c));
- l |= (b<<((level--*5) + MORTON_OFFSET));
- }
- return BitUtil.flipFlop(l);
- }
-
- /**
- * Encode to a morton long value from a given geohash long value
- */
- public static final long mortonEncode(final long geoHashLong) {
- final int level = (int)(geoHashLong&15);
- final short odd = (short)(level & 1);
-
- return BitUtil.flipFlop(((geoHashLong >>> 4) << odd) << (((12 - level) * 5) + (MORTON_OFFSET - odd)));
- }
-
- private static final char encode(int x, int y) {
- return BASE_32[((x & 1) + ((y & 1) * 2) + ((x & 2) * 2) + ((y & 2) * 4) + ((x & 4) * 4)) % 32];
- }
-
- /**
- * Calculate all neighbors of a given geohash cell.
- *
- * @param geohash Geohash of the defined cell
- * @return geohashes of all neighbor cells
- */
- public static Collection<? extends CharSequence> neighbors(String geohash) {
- return addNeighbors(geohash, geohash.length(), new ArrayList<CharSequence>(8));
- }
-
- /**
- * Calculate the geohash of a neighbor of a geohash
- *
- * @param geohash the geohash of a cell
- * @param level level of the geohash
- * @param dx delta of the first grid coordinate (must be -1, 0 or +1)
- * @param dy delta of the second grid coordinate (must be -1, 0 or +1)
- * @return geohash of the defined cell
- */
- public final static String neighbor(String geohash, int level, int dx, int dy) {
- int cell = BASE_32_STRING.indexOf(geohash.charAt(level -1));
-
- // Decoding the Geohash bit pattern to determine grid coordinates
- int x0 = cell & 1; // first bit of x
- int y0 = cell & 2; // first bit of y
- int x1 = cell & 4; // second bit of x
- int y1 = cell & 8; // second bit of y
- int x2 = cell & 16; // third bit of x
-
- // combine the bitpattern to grid coordinates.
- // note that the semantics of x and y are swapping
- // on each level
- int x = x0 + (x1 / 2) + (x2 / 4);
- int y = (y0 / 2) + (y1 / 4);
-
- if (level == 1) {
- // Root cells at north (namely "bcfguvyz") or at
- // south (namely "0145hjnp") do not have neighbors
- // in north/south direction
- if ((dy < 0 && y == 0) || (dy > 0 && y == 3)) {
- return null;
- } else {
- return Character.toString(encode(x + dx, y + dy));
- }
- } else {
- // define grid coordinates for next level
- final int nx = ((level % 2) == 1) ? (x + dx) : (x + dy);
- final int ny = ((level % 2) == 1) ? (y + dy) : (y + dx);
-
- // if the defined neighbor has the same parent a the current cell
- // encode the cell directly. Otherwise find the cell next to this
- // cell recursively. Since encoding wraps around within a cell
- // it can be encoded here.
- // xLimit and YLimit must always be respectively 7 and 3
- // since x and y semantics are swapping on each level.
- if (nx >= 0 && nx <= 7 && ny >= 0 && ny <= 3) {
- return geohash.substring(0, level - 1) + encode(nx, ny);
- } else {
- String neighbor = neighbor(geohash, level - 1, dx, dy);
- return (neighbor != null) ? neighbor + encode(nx, ny) : neighbor;
- }
- }
- }
-
- /**
- * Add all geohashes of the cells next to a given geohash to a list.
- *
- * @param geohash Geohash of a specified cell
- * @param neighbors list to add the neighbors to
- * @return the given list
- */
- public static final <E extends Collection<? super String>> E addNeighbors(String geohash, E neighbors) {
- return addNeighbors(geohash, geohash.length(), neighbors);
- }
-
- /**
- * Add all geohashes of the cells next to a given geohash to a list.
- *
- * @param geohash Geohash of a specified cell
- * @param length level of the given geohash
- * @param neighbors list to add the neighbors to
- * @return the given list
- */
- public static final <E extends Collection<? super String>> E addNeighbors(String geohash, int length, E neighbors) {
- String south = neighbor(geohash, length, 0, -1);
- String north = neighbor(geohash, length, 0, +1);
- if (north != null) {
- neighbors.add(neighbor(north, length, -1, 0));
- neighbors.add(north);
- neighbors.add(neighbor(north, length, +1, 0));
- }
-
- neighbors.add(neighbor(geohash, length, -1, 0));
- neighbors.add(neighbor(geohash, length, +1, 0));
-
- if (south != null) {
- neighbors.add(neighbor(south, length, -1, 0));
- neighbors.add(south);
- neighbors.add(neighbor(south, length, +1, 0));
- }
-
- return neighbors;
- }
-}