|
@@ -10,8 +10,6 @@ package org.elasticsearch.xpack.ql.util;
|
|
|
import org.apache.lucene.geo.GeoEncodingUtils;
|
|
|
import org.apache.lucene.geo.XYEncodingUtils;
|
|
|
import org.apache.lucene.util.BytesRef;
|
|
|
-import org.elasticsearch.common.geo.GeoPoint;
|
|
|
-import org.elasticsearch.common.geo.SpatialPoint;
|
|
|
import org.elasticsearch.geometry.Geometry;
|
|
|
import org.elasticsearch.geometry.Point;
|
|
|
import org.elasticsearch.geometry.utils.GeometryValidator;
|
|
@@ -25,8 +23,8 @@ import static org.apache.lucene.geo.GeoEncodingUtils.encodeLongitude;
|
|
|
|
|
|
public enum SpatialCoordinateTypes {
|
|
|
GEO {
|
|
|
- public SpatialPoint longAsPoint(long encoded) {
|
|
|
- return new GeoPoint(GeoEncodingUtils.decodeLatitude((int) (encoded >>> 32)), GeoEncodingUtils.decodeLongitude((int) encoded));
|
|
|
+ public Point longAsPoint(long encoded) {
|
|
|
+ return new Point(GeoEncodingUtils.decodeLongitude((int) encoded), GeoEncodingUtils.decodeLatitude((int) (encoded >>> 32)));
|
|
|
}
|
|
|
|
|
|
public long pointAsLong(double x, double y) {
|
|
@@ -36,14 +34,8 @@ public enum SpatialCoordinateTypes {
|
|
|
}
|
|
|
},
|
|
|
CARTESIAN {
|
|
|
- public SpatialPoint longAsPoint(long encoded) {
|
|
|
- try {
|
|
|
- final double x = XYEncodingUtils.decode((int) (encoded >>> 32));
|
|
|
- final double y = XYEncodingUtils.decode((int) (encoded & 0xFFFFFFFF));
|
|
|
- return makePoint(x, y);
|
|
|
- } catch (Error e) {
|
|
|
- throw new IllegalArgumentException("Failed to convert invalid encoded value to cartesian point");
|
|
|
- }
|
|
|
+ public Point longAsPoint(long encoded) {
|
|
|
+ return new Point(XYEncodingUtils.decode((int) (encoded >>> 32)), XYEncodingUtils.decode((int) (encoded & 0xFFFFFFFF)));
|
|
|
}
|
|
|
|
|
|
public long pointAsLong(double x, double y) {
|
|
@@ -51,70 +43,14 @@ public enum SpatialCoordinateTypes {
|
|
|
final long yi = XYEncodingUtils.encode((float) y);
|
|
|
return (yi & 0xFFFFFFFFL) | xi << 32;
|
|
|
}
|
|
|
-
|
|
|
- private SpatialPoint makePoint(double x, double y) {
|
|
|
- return new SpatialPoint() {
|
|
|
- @Override
|
|
|
- public double getX() {
|
|
|
- return x;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public double getY() {
|
|
|
- return y;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int hashCode() {
|
|
|
- return 31 * Double.hashCode(x) + Double.hashCode(y);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean equals(Object obj) {
|
|
|
- if (obj == null) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (obj instanceof SpatialPoint other) {
|
|
|
- return x == other.getX() && y == other.getY();
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String toString() {
|
|
|
- return toWKT();
|
|
|
- }
|
|
|
- };
|
|
|
- }
|
|
|
};
|
|
|
|
|
|
- public abstract SpatialPoint longAsPoint(long encoded);
|
|
|
-
|
|
|
- public long pointAsLong(SpatialPoint point) {
|
|
|
- return pointAsLong(point.getX(), point.getY());
|
|
|
- }
|
|
|
+ public abstract Point longAsPoint(long encoded);
|
|
|
|
|
|
public abstract long pointAsLong(double x, double y);
|
|
|
|
|
|
- public String pointAsString(SpatialPoint point) {
|
|
|
- return point.toWKT();
|
|
|
- }
|
|
|
-
|
|
|
- public Point stringAsPoint(String string) {
|
|
|
- try {
|
|
|
- Geometry geometry = WellKnownText.fromWKT(GeometryValidator.NOOP, false, string);
|
|
|
- if (geometry instanceof Point point) {
|
|
|
- return point;
|
|
|
- } else {
|
|
|
- throw new IllegalArgumentException("Unsupported geometry type " + geometry.type());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw new IllegalArgumentException("Failed to parse WKT: " + e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public BytesRef pointAsWKB(SpatialPoint point) {
|
|
|
- return pointAsWKB(new Point(point.getX(), point.getY()));
|
|
|
+ public String pointAsString(Point point) {
|
|
|
+ return WellKnownText.toWKT(point);
|
|
|
}
|
|
|
|
|
|
public BytesRef pointAsWKB(Point point) {
|