mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-25 09:28:27 +00:00
Geo: Change order of parameter in Geometries to lon, lat 7.x (#45618)
Changes the order of parameters in Geometries from lat, lon to lon, lat and moves all Geometry classes are moved to the org.elasticsearch.geomtery package. Backport of #45332 Closes #45048
This commit is contained in:
parent
742213d710
commit
98c850c08b
@ -57,3 +57,11 @@ The client method `termVector`, deprecated in 2.0, has been removed. The method
|
||||
|
||||
The constructor `AbstractLifecycleComponent(Settings settings)`, deprecated in 6.7
|
||||
has been removed. The parameterless constructor should be used instead.
|
||||
|
||||
[float]
|
||||
==== Changes to Geometry classes
|
||||
|
||||
Geometry classes used to represent geo values in SQL have been moved from the
|
||||
`org.elasticsearch.geo.geometry` package to the `org.elasticsearch.geometry`
|
||||
package and the order of the constructor parameters has changed from `lat`, `lon`
|
||||
to `lon`, `lat`.
|
||||
|
@ -17,7 +17,9 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
/**
|
||||
* Circle geometry (not part of WKT standard, but used in elasticsearch) defined by lat/lon coordinates of the center in degrees
|
||||
@ -25,27 +27,27 @@ package org.elasticsearch.geo.geometry;
|
||||
*/
|
||||
public class Circle implements Geometry {
|
||||
public static final Circle EMPTY = new Circle();
|
||||
private final double lat;
|
||||
private final double lon;
|
||||
private final double alt;
|
||||
private final double y;
|
||||
private final double x;
|
||||
private final double z;
|
||||
private final double radiusMeters;
|
||||
|
||||
private Circle() {
|
||||
lat = 0;
|
||||
lon = 0;
|
||||
alt = Double.NaN;
|
||||
y = 0;
|
||||
x = 0;
|
||||
z = Double.NaN;
|
||||
radiusMeters = -1;
|
||||
}
|
||||
|
||||
public Circle(final double lat, final double lon, final double radiusMeters) {
|
||||
this(lat, lon, Double.NaN, radiusMeters);
|
||||
public Circle(final double x, final double y, final double radiusMeters) {
|
||||
this(x, y, Double.NaN, radiusMeters);
|
||||
}
|
||||
|
||||
public Circle(final double lat, final double lon, final double alt, final double radiusMeters) {
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
public Circle(final double x, final double y, final double z, final double radiusMeters) {
|
||||
this.y = y;
|
||||
this.x = x;
|
||||
this.radiusMeters = radiusMeters;
|
||||
this.alt = alt;
|
||||
this.z = z;
|
||||
if (radiusMeters < 0 ) {
|
||||
throw new IllegalArgumentException("Circle radius [" + radiusMeters + "] cannot be negative");
|
||||
}
|
||||
@ -56,20 +58,32 @@ public class Circle implements Geometry {
|
||||
return ShapeType.CIRCLE;
|
||||
}
|
||||
|
||||
public double getLat() {
|
||||
return lat;
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public double getLon() {
|
||||
return lon;
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getRadiusMeters() {
|
||||
return radiusMeters;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public double getLat() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public double getLon() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getAlt() {
|
||||
return alt;
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -78,23 +92,23 @@ public class Circle implements Geometry {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Circle circle = (Circle) o;
|
||||
if (Double.compare(circle.lat, lat) != 0) return false;
|
||||
if (Double.compare(circle.lon, lon) != 0) return false;
|
||||
if (Double.compare(circle.y, y) != 0) return false;
|
||||
if (Double.compare(circle.x, x) != 0) return false;
|
||||
if (Double.compare(circle.radiusMeters, radiusMeters) != 0) return false;
|
||||
return (Double.compare(circle.alt, alt) == 0);
|
||||
return (Double.compare(circle.z, z) == 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(lat);
|
||||
temp = Double.doubleToLongBits(y);
|
||||
result = (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(lon);
|
||||
temp = Double.doubleToLongBits(x);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(radiusMeters);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(alt);
|
||||
temp = Double.doubleToLongBits(z);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
@ -111,11 +125,11 @@ public class Circle implements Geometry {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "lat=" + lat + ", lon=" + lon + ", radius=" + radiusMeters + (Double.isNaN(alt) ? ", alt=" + alt : "");
|
||||
return WellKnownText.INSTANCE.toWKT(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAlt() {
|
||||
return Double.isNaN(alt) == false;
|
||||
public boolean hasZ() {
|
||||
return Double.isNaN(z) == false;
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
/**
|
||||
* Base class for all Geometry objects supported by elasticsearch
|
||||
@ -30,7 +30,11 @@ public interface Geometry {
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
default boolean hasAlt() {
|
||||
default boolean hasZ() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean hasAlt() {
|
||||
return hasZ();
|
||||
}
|
||||
}
|
@ -16,12 +16,13 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -42,9 +43,9 @@ public class GeometryCollection<G extends Geometry> implements Geometry, Iterabl
|
||||
if (shapes == null || shapes.isEmpty()) {
|
||||
throw new IllegalArgumentException("the list of shapes cannot be null or empty");
|
||||
}
|
||||
hasAlt = shapes.get(0).hasAlt();
|
||||
hasAlt = shapes.get(0).hasZ();
|
||||
for (G shape : shapes) {
|
||||
if (shape.hasAlt() != hasAlt) {
|
||||
if (shape.hasZ() != hasAlt) {
|
||||
throw new IllegalArgumentException("all elements of the collection should have the same number of dimension");
|
||||
}
|
||||
}
|
||||
@ -93,16 +94,12 @@ public class GeometryCollection<G extends Geometry> implements Geometry, Iterabl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAlt() {
|
||||
public boolean hasZ() {
|
||||
return hasAlt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(type().name().toLowerCase(Locale.ROOT)).append("(shapes=");
|
||||
sb.append(shapes);
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
return WellKnownText.INSTANCE.toWKT(this);
|
||||
}
|
||||
}
|
@ -17,7 +17,9 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
/**
|
||||
* Support class for creating Geometry Visitors.
|
||||
@ -40,7 +42,7 @@ package org.elasticsearch.geo.geometry;
|
||||
* The Visitor Pattern replaces this structure with Interface inheritance making it easier to identify all places that are using this
|
||||
* structure, and making a shape a compile-time failure instead of runtime.
|
||||
* <p>
|
||||
* See {@link org.elasticsearch.geo.utils.WellKnownText#toWKT(Geometry, StringBuilder)} for an example of how this interface is used.
|
||||
* See {@link WellKnownText#toWKT(Geometry, StringBuilder)} for an example of how this interface is used.
|
||||
*
|
||||
* @see <a href="https://en.wikipedia.org/wiki/Visitor_pattern">Visitor Pattern</a>
|
||||
*/
|
@ -17,7 +17,9 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -26,71 +28,99 @@ import java.util.Arrays;
|
||||
*/
|
||||
public class Line implements Geometry {
|
||||
public static final Line EMPTY = new Line();
|
||||
private final double[] lats;
|
||||
private final double[] lons;
|
||||
private final double[] alts;
|
||||
private final double[] y;
|
||||
private final double[] x;
|
||||
private final double[] z;
|
||||
|
||||
protected Line() {
|
||||
lats = new double[0];
|
||||
lons = new double[0];
|
||||
alts = null;
|
||||
y = new double[0];
|
||||
x = new double[0];
|
||||
z = null;
|
||||
}
|
||||
|
||||
public Line(double[] lats, double[] lons) {
|
||||
this(lats, lons, null);
|
||||
public Line(double[] x, double[] y) {
|
||||
this(x, y, null);
|
||||
}
|
||||
|
||||
public Line(double[] lats, double[] lons, double[] alts) {
|
||||
this.lats = lats;
|
||||
this.lons = lons;
|
||||
this.alts = alts;
|
||||
if (lats == null) {
|
||||
throw new IllegalArgumentException("lats must not be null");
|
||||
public Line(double[] x, double[] y, double[] z) {
|
||||
this.y = y;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
if (y == null) {
|
||||
throw new IllegalArgumentException("y must not be null");
|
||||
}
|
||||
if (lons == null) {
|
||||
throw new IllegalArgumentException("lons must not be null");
|
||||
if (x == null) {
|
||||
throw new IllegalArgumentException("x must not be null");
|
||||
}
|
||||
if (lats.length != lons.length) {
|
||||
throw new IllegalArgumentException("lats and lons must be equal length");
|
||||
if (y.length != x.length) {
|
||||
throw new IllegalArgumentException("x and y must be equal length");
|
||||
}
|
||||
if (lats.length < 2) {
|
||||
if (y.length < 2) {
|
||||
throw new IllegalArgumentException("at least two points in the line is required");
|
||||
}
|
||||
if (alts != null && alts.length != lats.length) {
|
||||
throw new IllegalArgumentException("alts and lats must be equal length");
|
||||
if (z != null && z.length != x.length) {
|
||||
throw new IllegalArgumentException("z and x must be equal length");
|
||||
}
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return lats.length;
|
||||
return y.length;
|
||||
}
|
||||
|
||||
public double getY(int i) {
|
||||
return y[i];
|
||||
}
|
||||
|
||||
public double getX(int i) {
|
||||
return x[i];
|
||||
}
|
||||
|
||||
public double getZ(int i) {
|
||||
if (z != null) {
|
||||
return z[i];
|
||||
} else {
|
||||
return Double.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
public double[] getY() {
|
||||
return y.clone();
|
||||
}
|
||||
|
||||
public double[] getX() {
|
||||
return x.clone();
|
||||
}
|
||||
|
||||
public double[] getZ() {
|
||||
return z == null ? null : z.clone();
|
||||
}
|
||||
|
||||
public double getLat(int i) {
|
||||
return lats[i];
|
||||
return y[i];
|
||||
}
|
||||
|
||||
public double getLon(int i) {
|
||||
return lons[i];
|
||||
return x[i];
|
||||
}
|
||||
|
||||
public double getAlt(int i) {
|
||||
if (alts != null) {
|
||||
return alts[i];
|
||||
if (z != null) {
|
||||
return z[i];
|
||||
} else {
|
||||
return Double.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
public double[] getLats() {
|
||||
return lats.clone();
|
||||
return y.clone();
|
||||
}
|
||||
|
||||
public double[] getLons() {
|
||||
return lons.clone();
|
||||
return x.clone();
|
||||
}
|
||||
|
||||
public double[] getAlts() {
|
||||
return alts == null ? null : alts.clone();
|
||||
return z == null ? null : z.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -105,7 +135,7 @@ public class Line implements Geometry {
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return lats.length == 0;
|
||||
return y.length == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,27 +143,25 @@ public class Line implements Geometry {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Line line = (Line) o;
|
||||
return Arrays.equals(lats, line.lats) &&
|
||||
Arrays.equals(lons, line.lons) && Arrays.equals(alts, line.alts);
|
||||
return Arrays.equals(y, line.y) &&
|
||||
Arrays.equals(x, line.x) && Arrays.equals(z, line.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = Arrays.hashCode(lats);
|
||||
result = 31 * result + Arrays.hashCode(lons);
|
||||
result = 31 * result + Arrays.hashCode(alts);
|
||||
int result = Arrays.hashCode(y);
|
||||
result = 31 * result + Arrays.hashCode(x);
|
||||
result = 31 * result + Arrays.hashCode(z);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAlt() {
|
||||
return alts != null;
|
||||
public boolean hasZ() {
|
||||
return z != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "lats=" + Arrays.toString(lats) +
|
||||
", lons=" + Arrays.toString(lons) +
|
||||
(hasAlt() ? ", alts=" + Arrays.toString(alts) : "");
|
||||
return WellKnownText.INSTANCE.toWKT(this);
|
||||
}
|
||||
}
|
@ -17,7 +17,9 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Represents a closed line on the earth's surface in lat/lon decimal degrees and optional altitude in meters.
|
||||
@ -30,21 +32,21 @@ public class LinearRing extends Line {
|
||||
private LinearRing() {
|
||||
}
|
||||
|
||||
public LinearRing(double[] lats, double[] lons) {
|
||||
this(lats, lons, null);
|
||||
public LinearRing(double[] x, double[] y) {
|
||||
this(x, y, null);
|
||||
}
|
||||
|
||||
public LinearRing(double[] lats, double[] lons, double[] alts) {
|
||||
super(lats, lons, alts);
|
||||
if (lats.length < 2) {
|
||||
throw new IllegalArgumentException("linear ring cannot contain less than 2 points, found " + lats.length);
|
||||
public LinearRing(double[] x, double[] y, double[] z) {
|
||||
super(x, y, z);
|
||||
if (x.length < 2) {
|
||||
throw new IllegalArgumentException("linear ring cannot contain less than 2 points, found " + x.length);
|
||||
}
|
||||
int last = lats.length - 1;
|
||||
if (lats[0] != lats[last] || lons[0] != lons[last] || (alts != null && alts[0] != alts[last])) {
|
||||
int last = x.length - 1;
|
||||
if (x[0] != x[last] || y[0] != y[last] || (z != null && z[0] != z[last])) {
|
||||
throw new IllegalArgumentException("first and last points of the linear ring must be the same (it must close itself):" +
|
||||
" lats[0]=" + lats[0] + " lats[" + last + "]=" + lats[last] +
|
||||
" lons[0]=" + lons[0] + " lons[" + last + "]=" + lons[last] +
|
||||
(alts == null ? "" : " alts[0]=" + alts[0] + " alts[" + last + "]=" + alts[last] ));
|
||||
" x[0]=" + x[0] + " x[" + last + "]=" + x[last] +
|
||||
" y[0]=" + y[0] + " y[" + last + "]=" + y[last] +
|
||||
(z == null ? "" : " z[0]=" + z[0] + " z[" + last + "]=" + z[last] ));
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,4 +59,11 @@ public class LinearRing extends Line {
|
||||
public <T, E extends Exception> T visit(GeometryVisitor<T, E> visitor) throws E {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "linearring(x=" + Arrays.toString(getX()) +
|
||||
", y=" + Arrays.toString(getY()) +
|
||||
(hasZ() ? ", z=" + Arrays.toString(getZ()) : "");
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -17,7 +17,9 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
/**
|
||||
* Represents a Point on the earth's surface in decimal degrees and optional altitude in meters.
|
||||
@ -25,26 +27,26 @@ package org.elasticsearch.geo.geometry;
|
||||
public class Point implements Geometry {
|
||||
public static final Point EMPTY = new Point();
|
||||
|
||||
private final double lat;
|
||||
private final double lon;
|
||||
private final double alt;
|
||||
private final double y;
|
||||
private final double x;
|
||||
private final double z;
|
||||
private final boolean empty;
|
||||
|
||||
private Point() {
|
||||
lat = 0;
|
||||
lon = 0;
|
||||
alt = Double.NaN;
|
||||
y = 0;
|
||||
x = 0;
|
||||
z = Double.NaN;
|
||||
empty = true;
|
||||
}
|
||||
|
||||
public Point(double lat, double lon) {
|
||||
this(lat, lon, Double.NaN);
|
||||
public Point(double x, double y) {
|
||||
this(x, y, Double.NaN);
|
||||
}
|
||||
|
||||
public Point(double lat, double lon, double alt) {
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
this.alt = alt;
|
||||
public Point(double x, double y, double z) {
|
||||
this.y = y;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.empty = false;
|
||||
}
|
||||
|
||||
@ -53,16 +55,28 @@ public class Point implements Geometry {
|
||||
return ShapeType.POINT;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public double getLat() {
|
||||
return lat;
|
||||
return y;
|
||||
}
|
||||
|
||||
public double getLon() {
|
||||
return lon;
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getAlt() {
|
||||
return alt;
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,20 +86,20 @@ public class Point implements Geometry {
|
||||
|
||||
Point point = (Point) o;
|
||||
if (point.empty != empty) return false;
|
||||
if (Double.compare(point.lat, lat) != 0) return false;
|
||||
if (Double.compare(point.lon, lon) != 0) return false;
|
||||
return Double.compare(point.alt, alt) == 0;
|
||||
if (Double.compare(point.y, y) != 0) return false;
|
||||
if (Double.compare(point.x, x) != 0) return false;
|
||||
return Double.compare(point.z, z) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(lat);
|
||||
temp = Double.doubleToLongBits(y);
|
||||
result = (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(lon);
|
||||
temp = Double.doubleToLongBits(x);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(alt);
|
||||
temp = Double.doubleToLongBits(z);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
@ -101,12 +115,13 @@ public class Point implements Geometry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAlt() {
|
||||
return Double.isNaN(alt) == false;
|
||||
public boolean hasZ() {
|
||||
return Double.isNaN(z) == false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "lat=" + lat + ", lon=" + lon + (hasAlt() ? ", alt=" + alt : "");
|
||||
return WellKnownText.INSTANCE.toWKT(this);
|
||||
}
|
||||
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -47,10 +47,10 @@ public final class Polygon implements Geometry {
|
||||
if (holes == null) {
|
||||
throw new IllegalArgumentException("holes must not be null");
|
||||
}
|
||||
boolean hasAlt = polygon.hasAlt();
|
||||
boolean hasAlt = polygon.hasZ();
|
||||
checkRing(polygon);
|
||||
for (LinearRing hole : holes) {
|
||||
if (hole.hasAlt() != hasAlt) {
|
||||
if (hole.hasZ() != hasAlt) {
|
||||
throw new IllegalArgumentException("holes must have the same number of dimensions as the polygon");
|
||||
}
|
||||
checkRing(hole);
|
||||
@ -102,7 +102,7 @@ public final class Polygon implements Geometry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAlt() {
|
||||
public boolean hasZ() {
|
||||
return hasAlt;
|
||||
}
|
||||
|
@ -17,7 +17,9 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
/**
|
||||
* Represents a lat/lon rectangle in decimal degrees and optional altitude in meters.
|
||||
@ -25,90 +27,114 @@ package org.elasticsearch.geo.geometry;
|
||||
public class Rectangle implements Geometry {
|
||||
public static final Rectangle EMPTY = new Rectangle();
|
||||
/**
|
||||
* maximum longitude value (in degrees)
|
||||
* minimum latitude value (in degrees)
|
||||
*/
|
||||
private final double minLat;
|
||||
private final double minY;
|
||||
/**
|
||||
* minimum longitude value (in degrees)
|
||||
*/
|
||||
private final double minLon;
|
||||
private final double minX;
|
||||
/**
|
||||
* maximum altitude value (in meters)
|
||||
*/
|
||||
private final double minAlt;
|
||||
private final double minZ;
|
||||
/**
|
||||
* maximum latitude value (in degrees)
|
||||
*/
|
||||
private final double maxLat;
|
||||
private final double maxY;
|
||||
/**
|
||||
* minimum latitude value (in degrees)
|
||||
* minimum longitude value (in degrees)
|
||||
*/
|
||||
private final double maxLon;
|
||||
private final double maxX;
|
||||
/**
|
||||
* minimum altitude value (in meters)
|
||||
*/
|
||||
private final double maxAlt;
|
||||
private final double maxZ;
|
||||
|
||||
private final boolean empty;
|
||||
|
||||
private Rectangle() {
|
||||
minLat = 0;
|
||||
minLon = 0;
|
||||
maxLat = 0;
|
||||
maxLon = 0;
|
||||
minAlt = Double.NaN;
|
||||
maxAlt = Double.NaN;
|
||||
minY = 0;
|
||||
minX = 0;
|
||||
maxY = 0;
|
||||
maxX = 0;
|
||||
minZ = Double.NaN;
|
||||
maxZ = Double.NaN;
|
||||
empty = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a bounding box by first validating the provided latitude and longitude coordinates
|
||||
*/
|
||||
public Rectangle(double minLat, double maxLat, double minLon, double maxLon) {
|
||||
this(minLat, maxLat, minLon, maxLon, Double.NaN, Double.NaN);
|
||||
public Rectangle(double minX, double maxX, double maxY, double minY) {
|
||||
this(minX, maxX, maxY, minY, Double.NaN, Double.NaN);
|
||||
}
|
||||
/**
|
||||
* Constructs a bounding box by first validating the provided latitude and longitude coordinates
|
||||
*/
|
||||
public Rectangle(double minLat, double maxLat, double minLon, double maxLon, double minAlt, double maxAlt) {
|
||||
this.minLon = minLon;
|
||||
this.maxLon = maxLon;
|
||||
this.minLat = minLat;
|
||||
this.maxLat = maxLat;
|
||||
this.minAlt = minAlt;
|
||||
this.maxAlt = maxAlt;
|
||||
public Rectangle(double minX, double maxX, double maxY, double minY, double minZ, double maxZ) {
|
||||
this.minX = minX;
|
||||
this.maxX = maxX;
|
||||
this.minY = minY;
|
||||
this.maxY = maxY;
|
||||
this.minZ = minZ;
|
||||
this.maxZ = maxZ;
|
||||
empty = false;
|
||||
if (maxLat < minLat) {
|
||||
throw new IllegalArgumentException("max lat cannot be less than min lat");
|
||||
if (maxY < minY) {
|
||||
throw new IllegalArgumentException("max y cannot be less than min x");
|
||||
}
|
||||
if (Double.isNaN(minAlt) != Double.isNaN(maxAlt)) {
|
||||
throw new IllegalArgumentException("only one altitude value is specified");
|
||||
if (Double.isNaN(minZ) != Double.isNaN(maxZ)) {
|
||||
throw new IllegalArgumentException("only one z value is specified");
|
||||
}
|
||||
}
|
||||
|
||||
public double getMinY() {
|
||||
return minY;
|
||||
}
|
||||
|
||||
public double getMinX() {
|
||||
return minX;
|
||||
}
|
||||
|
||||
public double getMinZ() {
|
||||
return minZ;
|
||||
}
|
||||
|
||||
public double getMaxY() {
|
||||
return maxY;
|
||||
}
|
||||
|
||||
public double getMaxX() {
|
||||
return maxX;
|
||||
}
|
||||
|
||||
public double getMaxZ() {
|
||||
return maxZ;
|
||||
}
|
||||
|
||||
public double getMinLat() {
|
||||
return minLat;
|
||||
return minY;
|
||||
}
|
||||
|
||||
public double getMinLon() {
|
||||
return minLon;
|
||||
return minX;
|
||||
}
|
||||
|
||||
|
||||
public double getMinAlt() {
|
||||
return minAlt;
|
||||
return minZ;
|
||||
}
|
||||
|
||||
public double getMaxLat() {
|
||||
return maxLat;
|
||||
return maxY;
|
||||
}
|
||||
|
||||
public double getMaxLon() {
|
||||
return maxLon;
|
||||
return maxX;
|
||||
}
|
||||
|
||||
public double getMaxAlt() {
|
||||
return maxAlt;
|
||||
return maxZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -118,29 +144,10 @@ public class Rectangle implements Geometry {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("Rectangle(lat=");
|
||||
b.append(minLat);
|
||||
b.append(" TO ");
|
||||
b.append(maxLat);
|
||||
b.append(" lon=");
|
||||
b.append(minLon);
|
||||
b.append(" TO ");
|
||||
b.append(maxLon);
|
||||
if (maxLon < minLon) {
|
||||
b.append(" [crosses dateline!]");
|
||||
}
|
||||
if (hasAlt()) {
|
||||
b.append(" alt=");
|
||||
b.append(minAlt);
|
||||
b.append(" TO ");
|
||||
b.append(maxAlt);
|
||||
}
|
||||
b.append(")");
|
||||
|
||||
return b.toString();
|
||||
return WellKnownText.INSTANCE.toWKT(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -148,12 +155,12 @@ public class Rectangle implements Geometry {
|
||||
|
||||
Rectangle rectangle = (Rectangle) o;
|
||||
|
||||
if (Double.compare(rectangle.minLat, minLat) != 0) return false;
|
||||
if (Double.compare(rectangle.minLon, minLon) != 0) return false;
|
||||
if (Double.compare(rectangle.maxLat, maxLat) != 0) return false;
|
||||
if (Double.compare(rectangle.maxLon, maxLon) != 0) return false;
|
||||
if (Double.compare(rectangle.minAlt, minAlt) != 0) return false;
|
||||
return Double.compare(rectangle.maxAlt, maxAlt) == 0;
|
||||
if (Double.compare(rectangle.minY, minY) != 0) return false;
|
||||
if (Double.compare(rectangle.minX, minX) != 0) return false;
|
||||
if (Double.compare(rectangle.maxY, maxY) != 0) return false;
|
||||
if (Double.compare(rectangle.maxX, maxX) != 0) return false;
|
||||
if (Double.compare(rectangle.minZ, minZ) != 0) return false;
|
||||
return Double.compare(rectangle.maxZ, maxZ) == 0;
|
||||
|
||||
}
|
||||
|
||||
@ -161,17 +168,17 @@ public class Rectangle implements Geometry {
|
||||
public int hashCode() {
|
||||
int result;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(minLat);
|
||||
temp = Double.doubleToLongBits(minY);
|
||||
result = (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(minLon);
|
||||
temp = Double.doubleToLongBits(minX);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(maxLat);
|
||||
temp = Double.doubleToLongBits(maxY);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(maxLon);
|
||||
temp = Double.doubleToLongBits(maxX);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(minAlt);
|
||||
temp = Double.doubleToLongBits(minZ);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(maxAlt);
|
||||
temp = Double.doubleToLongBits(maxZ);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
@ -187,7 +194,7 @@ public class Rectangle implements Geometry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAlt() {
|
||||
return Double.isNaN(maxAlt) == false;
|
||||
public boolean hasZ() {
|
||||
return Double.isNaN(maxZ) == false;
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import java.util.Locale;
|
||||
|
@ -19,6 +19,6 @@
|
||||
|
||||
|
||||
/**
|
||||
* Common Geo classes
|
||||
* Common Geometry classes
|
||||
*/
|
||||
package org.elasticsearch.geo;
|
||||
package org.elasticsearch.geometry;
|
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.geo.utils;
|
||||
package org.elasticsearch.geometry.utils;
|
||||
|
||||
/**
|
||||
* Utilities for common Bit twiddling methods. Borrowed heavily from Lucene (org.apache.lucene.util.BitUtil).
|
@ -17,20 +17,20 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.utils;
|
||||
package org.elasticsearch.geometry.utils;
|
||||
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Polygon;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
|
||||
/**
|
||||
* Validator that checks that lats are between -90 and +90 and lons are between -180 and +180 and altitude is present only if
|
||||
@ -97,9 +97,9 @@ public class GeographyValidator implements GeometryValidator {
|
||||
|
||||
@Override
|
||||
public Void visit(Circle circle) throws RuntimeException {
|
||||
checkLatitude(circle.getLat());
|
||||
checkLongitude(circle.getLon());
|
||||
checkAltitude(circle.getAlt());
|
||||
checkLatitude(circle.getY());
|
||||
checkLongitude(circle.getX());
|
||||
checkAltitude(circle.getZ());
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -114,9 +114,9 @@ public class GeographyValidator implements GeometryValidator {
|
||||
@Override
|
||||
public Void visit(Line line) throws RuntimeException {
|
||||
for (int i = 0; i < line.length(); i++) {
|
||||
checkLatitude(line.getLat(i));
|
||||
checkLongitude(line.getLon(i));
|
||||
checkAltitude(line.getAlt(i));
|
||||
checkLatitude(line.getY(i));
|
||||
checkLongitude(line.getX(i));
|
||||
checkAltitude(line.getZ(i));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -124,9 +124,9 @@ public class GeographyValidator implements GeometryValidator {
|
||||
@Override
|
||||
public Void visit(LinearRing ring) throws RuntimeException {
|
||||
for (int i = 0; i < ring.length(); i++) {
|
||||
checkLatitude(ring.getLat(i));
|
||||
checkLongitude(ring.getLon(i));
|
||||
checkAltitude(ring.getAlt(i));
|
||||
checkLatitude(ring.getY(i));
|
||||
checkLongitude(ring.getX(i));
|
||||
checkAltitude(ring.getZ(i));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -148,9 +148,9 @@ public class GeographyValidator implements GeometryValidator {
|
||||
|
||||
@Override
|
||||
public Void visit(Point point) throws RuntimeException {
|
||||
checkLatitude(point.getLat());
|
||||
checkLongitude(point.getLon());
|
||||
checkAltitude(point.getAlt());
|
||||
checkLatitude(point.getY());
|
||||
checkLongitude(point.getX());
|
||||
checkAltitude(point.getZ());
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -165,12 +165,12 @@ public class GeographyValidator implements GeometryValidator {
|
||||
|
||||
@Override
|
||||
public Void visit(Rectangle rectangle) throws RuntimeException {
|
||||
checkLatitude(rectangle.getMinLat());
|
||||
checkLatitude(rectangle.getMaxLat());
|
||||
checkLongitude(rectangle.getMinLon());
|
||||
checkLongitude(rectangle.getMaxLon());
|
||||
checkAltitude(rectangle.getMinAlt());
|
||||
checkAltitude(rectangle.getMaxAlt());
|
||||
checkLatitude(rectangle.getMinY());
|
||||
checkLatitude(rectangle.getMaxY());
|
||||
checkLongitude(rectangle.getMinX());
|
||||
checkLongitude(rectangle.getMaxX());
|
||||
checkAltitude(rectangle.getMinZ());
|
||||
checkAltitude(rectangle.getMaxZ());
|
||||
return null;
|
||||
}
|
||||
});
|
@ -16,10 +16,10 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.geo.utils;
|
||||
package org.elasticsearch.geometry.utils;
|
||||
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -61,7 +61,7 @@ public class Geohash {
|
||||
/** Returns a {@link Point} instance from a geohash string */
|
||||
public static Point toPoint(final String geohash) throws IllegalArgumentException {
|
||||
final long hash = mortonEncode(geohash);
|
||||
return new Point(decodeLatitude(hash), decodeLongitude(hash));
|
||||
return new Point(decodeLongitude(hash), decodeLatitude(hash));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,15 +85,15 @@ public class Geohash {
|
||||
// add 1 to lat and lon to get topRight
|
||||
ghLong = BitUtil.interleave((int)(lat + 1), (int)(lon + 1)) << 4 | len;
|
||||
final long mortonHash = BitUtil.flipFlop((ghLong >>> 4) << shift);
|
||||
Point topRight = new Point(decodeLatitude(mortonHash), decodeLongitude(mortonHash));
|
||||
return new Rectangle(bottomLeft.getLat(), topRight.getLat(), bottomLeft.getLon(), topRight.getLon());
|
||||
Point topRight = new Point(decodeLongitude(mortonHash), decodeLatitude(mortonHash));
|
||||
return new Rectangle(bottomLeft.getX(), topRight.getX(), topRight.getY(), bottomLeft.getY());
|
||||
} else {
|
||||
// We cannot go north of north pole, so just using 90 degrees instead of calculating it using
|
||||
// add 1 to lon to get lon of topRight, we are going to use 90 for lat
|
||||
ghLong = BitUtil.interleave((int)lat, (int)(lon + 1)) << 4 | len;
|
||||
final long mortonHash = BitUtil.flipFlop((ghLong >>> 4) << shift);
|
||||
Point topRight = new Point(decodeLatitude(mortonHash), decodeLongitude(mortonHash));
|
||||
return new Rectangle(bottomLeft.getLat(), 90D, bottomLeft.getLon(), topRight.getLon());
|
||||
Point topRight = new Point(decodeLongitude(mortonHash), decodeLatitude(mortonHash));
|
||||
return new Rectangle(bottomLeft.getX(), topRight.getX(), 90D, bottomLeft.getY());
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,9 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.utils;
|
||||
package org.elasticsearch.geometry.utils;
|
||||
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
|
||||
/**
|
||||
* Generic geometry validator that can be used by the parser to verify the validity of the parsed geometry
|
@ -17,20 +17,20 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.utils;
|
||||
package org.elasticsearch.geometry.utils;
|
||||
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Polygon;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
|
||||
/**
|
||||
* Validator that only checks that altitude only shows up if ignoreZValue is set to true.
|
||||
@ -43,7 +43,7 @@ public class StandardValidator implements GeometryValidator {
|
||||
this.ignoreZValue = ignoreZValue;
|
||||
}
|
||||
|
||||
protected void checkAltitude(double zValue) {
|
||||
protected void checkZ(double zValue) {
|
||||
if (ignoreZValue == false && Double.isNaN(zValue) == false) {
|
||||
throw new IllegalArgumentException("found Z value [" + zValue + "] but [ignore_z_value] "
|
||||
+ "parameter is [" + ignoreZValue + "]");
|
||||
@ -57,7 +57,7 @@ public class StandardValidator implements GeometryValidator {
|
||||
|
||||
@Override
|
||||
public Void visit(Circle circle) throws RuntimeException {
|
||||
checkAltitude(circle.getAlt());
|
||||
checkZ(circle.getZ());
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ public class StandardValidator implements GeometryValidator {
|
||||
@Override
|
||||
public Void visit(Line line) throws RuntimeException {
|
||||
for (int i = 0; i < line.length(); i++) {
|
||||
checkAltitude(line.getAlt(i));
|
||||
checkZ(line.getZ(i));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -80,7 +80,7 @@ public class StandardValidator implements GeometryValidator {
|
||||
@Override
|
||||
public Void visit(LinearRing ring) throws RuntimeException {
|
||||
for (int i = 0; i < ring.length(); i++) {
|
||||
checkAltitude(ring.getAlt(i));
|
||||
checkZ(ring.getZ(i));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -102,7 +102,7 @@ public class StandardValidator implements GeometryValidator {
|
||||
|
||||
@Override
|
||||
public Void visit(Point point) throws RuntimeException {
|
||||
checkAltitude(point.getAlt());
|
||||
checkZ(point.getZ());
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -117,8 +117,8 @@ public class StandardValidator implements GeometryValidator {
|
||||
|
||||
@Override
|
||||
public Void visit(Rectangle rectangle) throws RuntimeException {
|
||||
checkAltitude(rectangle.getMinAlt());
|
||||
checkAltitude(rectangle.getMaxAlt());
|
||||
checkZ(rectangle.getMinZ());
|
||||
checkZ(rectangle.getMaxZ());
|
||||
return null;
|
||||
}
|
||||
});
|
@ -17,20 +17,20 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.utils;
|
||||
package org.elasticsearch.geometry.utils;
|
||||
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Polygon;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StreamTokenizer;
|
||||
@ -45,6 +45,9 @@ import java.util.Locale;
|
||||
* Utility class for converting to and from WKT
|
||||
*/
|
||||
public class WellKnownText {
|
||||
/* The instance of WKT serializer that coerces values and accepts Z component */
|
||||
public static final WellKnownText INSTANCE = new WellKnownText(true, new StandardValidator(true));
|
||||
|
||||
public static final String EMPTY = "EMPTY";
|
||||
public static final String SPACE = " ";
|
||||
public static final String LPAREN = "(";
|
||||
@ -80,12 +83,12 @@ public class WellKnownText {
|
||||
@Override
|
||||
public Void visit(Circle circle) {
|
||||
sb.append(LPAREN);
|
||||
visitPoint(circle.getLon(), circle.getLat(), Double.NaN);
|
||||
visitPoint(circle.getX(), circle.getY(), Double.NaN);
|
||||
sb.append(SPACE);
|
||||
sb.append(circle.getRadiusMeters());
|
||||
if (circle.hasAlt()) {
|
||||
if (circle.hasZ()) {
|
||||
sb.append(SPACE);
|
||||
sb.append(circle.getAlt());
|
||||
sb.append(circle.getZ());
|
||||
}
|
||||
sb.append(RPAREN);
|
||||
return null;
|
||||
@ -110,11 +113,11 @@ public class WellKnownText {
|
||||
@Override
|
||||
public Void visit(Line line) {
|
||||
sb.append(LPAREN);
|
||||
visitPoint(line.getLon(0), line.getLat(0), line.getAlt(0));
|
||||
visitPoint(line.getX(0), line.getY(0), line.getZ(0));
|
||||
for (int i = 1; i < line.length(); ++i) {
|
||||
sb.append(COMMA);
|
||||
sb.append(SPACE);
|
||||
visitPoint(line.getLon(i), line.getLat(i), line.getAlt(i));
|
||||
visitPoint(line.getX(i), line.getY(i), line.getZ(i));
|
||||
}
|
||||
sb.append(RPAREN);
|
||||
return null;
|
||||
@ -139,12 +142,12 @@ public class WellKnownText {
|
||||
}
|
||||
// walk through coordinates:
|
||||
sb.append(LPAREN);
|
||||
visitPoint(multiPoint.get(0).getLon(), multiPoint.get(0).getLat(), multiPoint.get(0).getAlt());
|
||||
visitPoint(multiPoint.get(0).getX(), multiPoint.get(0).getY(), multiPoint.get(0).getZ());
|
||||
for (int i = 1; i < multiPoint.size(); ++i) {
|
||||
sb.append(COMMA);
|
||||
sb.append(SPACE);
|
||||
Point point = multiPoint.get(i);
|
||||
visitPoint(point.getLon(), point.getLat(), point.getAlt());
|
||||
visitPoint(point.getX(), point.getY(), point.getZ());
|
||||
}
|
||||
sb.append(RPAREN);
|
||||
return null;
|
||||
@ -162,7 +165,7 @@ public class WellKnownText {
|
||||
sb.append(EMPTY);
|
||||
} else {
|
||||
sb.append(LPAREN);
|
||||
visitPoint(point.getLon(), point.getLat(), point.getAlt());
|
||||
visitPoint(point.getX(), point.getY(), point.getZ());
|
||||
sb.append(RPAREN);
|
||||
}
|
||||
return null;
|
||||
@ -206,17 +209,24 @@ public class WellKnownText {
|
||||
public Void visit(Rectangle rectangle) {
|
||||
sb.append(LPAREN);
|
||||
// minX, maxX, maxY, minY
|
||||
// TODO: Add 3D support
|
||||
sb.append(rectangle.getMinLon());
|
||||
sb.append(rectangle.getMinX());
|
||||
sb.append(COMMA);
|
||||
sb.append(SPACE);
|
||||
sb.append(rectangle.getMaxLon());
|
||||
sb.append(rectangle.getMaxX());
|
||||
sb.append(COMMA);
|
||||
sb.append(SPACE);
|
||||
sb.append(rectangle.getMaxLat());
|
||||
sb.append(rectangle.getMaxY());
|
||||
sb.append(COMMA);
|
||||
sb.append(SPACE);
|
||||
sb.append(rectangle.getMinLat());
|
||||
sb.append(rectangle.getMinY());
|
||||
if (rectangle.hasZ()) {
|
||||
sb.append(COMMA);
|
||||
sb.append(SPACE);
|
||||
sb.append(rectangle.getMinZ());
|
||||
sb.append(COMMA);
|
||||
sb.append(SPACE);
|
||||
sb.append(rectangle.getMaxZ());
|
||||
}
|
||||
sb.append(RPAREN);
|
||||
return null;
|
||||
}
|
||||
@ -298,9 +308,9 @@ public class WellKnownText {
|
||||
double lat = nextNumber(stream);
|
||||
Point pt;
|
||||
if (isNumberNext(stream)) {
|
||||
pt = new Point(lat, lon, nextNumber(stream));
|
||||
pt = new Point(lon, lat, nextNumber(stream));
|
||||
} else {
|
||||
pt = new Point(lat, lon);
|
||||
pt = new Point(lon, lat);
|
||||
}
|
||||
nextCloser(stream);
|
||||
return pt;
|
||||
@ -338,9 +348,9 @@ public class WellKnownText {
|
||||
parseCoordinates(stream, lats, lons, alts);
|
||||
for (int i = 0; i < lats.size(); i++) {
|
||||
if (alts.isEmpty()) {
|
||||
points.add(new Point(lats.get(i), lons.get(i)));
|
||||
points.add(new Point(lons.get(i), lats.get(i)));
|
||||
} else {
|
||||
points.add(new Point(lats.get(i), lons.get(i), alts.get(i)));
|
||||
points.add(new Point(lons.get(i), lats.get(i), alts.get(i)));
|
||||
}
|
||||
}
|
||||
return new MultiPoint(Collections.unmodifiableList(points));
|
||||
@ -356,9 +366,9 @@ public class WellKnownText {
|
||||
ArrayList<Double> alts = new ArrayList<>();
|
||||
parseCoordinates(stream, lats, lons, alts);
|
||||
if (alts.isEmpty()) {
|
||||
return new Line(toArray(lats), toArray(lons));
|
||||
return new Line(toArray(lons), toArray(lats));
|
||||
} else {
|
||||
return new Line(toArray(lats), toArray(lons), toArray(alts));
|
||||
return new Line(toArray(lons), toArray(lats), toArray(alts));
|
||||
}
|
||||
}
|
||||
|
||||
@ -383,9 +393,9 @@ public class WellKnownText {
|
||||
parseCoordinates(stream, lats, lons, alts);
|
||||
closeLinearRingIfCoerced(lats, lons, alts);
|
||||
if (alts.isEmpty()) {
|
||||
return new LinearRing(toArray(lats), toArray(lons));
|
||||
return new LinearRing(toArray(lons), toArray(lats));
|
||||
} else {
|
||||
return new LinearRing(toArray(lats), toArray(lons), toArray(alts));
|
||||
return new LinearRing(toArray(lons), toArray(lats), toArray(alts));
|
||||
}
|
||||
}
|
||||
|
||||
@ -405,9 +415,9 @@ public class WellKnownText {
|
||||
closeLinearRingIfCoerced(lats, lons, alts);
|
||||
LinearRing shell;
|
||||
if (alts.isEmpty()) {
|
||||
shell = new LinearRing(toArray(lats), toArray(lons));
|
||||
shell = new LinearRing(toArray(lons), toArray(lats));
|
||||
} else {
|
||||
shell = new LinearRing(toArray(lats), toArray(lons), toArray(alts));
|
||||
shell = new LinearRing(toArray(lons), toArray(lats), toArray(alts));
|
||||
}
|
||||
if (holes.isEmpty()) {
|
||||
return new Polygon(shell);
|
||||
@ -460,7 +470,7 @@ public class WellKnownText {
|
||||
nextComma(stream);
|
||||
double minLat = nextNumber(stream);
|
||||
nextCloser(stream);
|
||||
return new Rectangle(minLat, maxLat, minLon, maxLon);
|
||||
return new Rectangle(minLon, maxLon, maxLat, minLat);
|
||||
}
|
||||
|
||||
|
||||
@ -475,7 +485,7 @@ public class WellKnownText {
|
||||
if (isNumberNext(stream) == true) {
|
||||
alt = nextNumber(stream);
|
||||
}
|
||||
Circle circle = new Circle(lat, lon, alt, radius);
|
||||
Circle circle = new Circle(lon, lat, alt, radius);
|
||||
nextCloser(stream);
|
||||
return circle;
|
||||
}
|
@ -17,13 +17,13 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
import org.elasticsearch.test.AbstractWireTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -36,7 +36,7 @@ abstract class BaseGeometryTestCase<T extends Geometry> extends AbstractWireTest
|
||||
protected final T createTestInstance() {
|
||||
boolean hasAlt = randomBoolean();
|
||||
T obj = createTestInstance(hasAlt);
|
||||
assertEquals(hasAlt, obj.hasAlt());
|
||||
assertEquals(hasAlt, obj.hasZ());
|
||||
return obj;
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ abstract class BaseGeometryTestCase<T extends Geometry> extends AbstractWireTest
|
||||
private Object verify(Geometry geometry, String expectedClass) {
|
||||
assertFalse("Visitor should be called only once", called.getAndSet(true));
|
||||
assertSame(geom, geometry);
|
||||
assertEquals(geometry.getClass().getName(), "org.elasticsearch.geo.geometry." + expectedClass);
|
||||
assertEquals(geometry.getClass().getName(), "org.elasticsearch.geometry." + expectedClass);
|
||||
return "result";
|
||||
}
|
||||
|
@ -17,12 +17,12 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.GeometryValidator;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.GeometryValidator;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
@ -31,20 +31,20 @@ public class CircleTests extends BaseGeometryTestCase<Circle> {
|
||||
@Override
|
||||
protected Circle createTestInstance(boolean hasAlt) {
|
||||
if (hasAlt) {
|
||||
return new Circle(randomDoubleBetween(-90, 90, true), randomDoubleBetween(-180, 180, true), randomDouble(),
|
||||
return new Circle(randomDoubleBetween(-180, 180, true), randomDoubleBetween(-90, 90, true), randomDouble(),
|
||||
randomDoubleBetween(0, 100, false));
|
||||
} else {
|
||||
return new Circle(randomDoubleBetween(-90, 90, true), randomDoubleBetween(-180, 180, true), randomDoubleBetween(0, 100, false));
|
||||
return new Circle(randomDoubleBetween(-180, 180, true), randomDoubleBetween(-90, 90, true), randomDoubleBetween(0, 100, false));
|
||||
}
|
||||
}
|
||||
|
||||
public void testBasicSerialization() throws IOException, ParseException {
|
||||
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
|
||||
assertEquals("circle (20.0 10.0 15.0)", wkt.toWKT(new Circle(10, 20, 15)));
|
||||
assertEquals(new Circle(10, 20, 15), wkt.fromWKT("circle (20.0 10.0 15.0)"));
|
||||
assertEquals("circle (20.0 10.0 15.0)", wkt.toWKT(new Circle(20, 10, 15)));
|
||||
assertEquals(new Circle(20, 10, 15), wkt.fromWKT("circle (20.0 10.0 15.0)"));
|
||||
|
||||
assertEquals("circle (20.0 10.0 15.0 25.0)", wkt.toWKT(new Circle(10, 20, 25, 15)));
|
||||
assertEquals(new Circle(10, 20, 25, 15), wkt.fromWKT("circle (20.0 10.0 15.0 25.0)"));
|
||||
assertEquals("circle (20.0 10.0 15.0 25.0)", wkt.toWKT(new Circle(20, 10, 25, 15)));
|
||||
assertEquals(new Circle(20, 10, 25, 15), wkt.fromWKT("circle (20.0 10.0 15.0 25.0)"));
|
||||
|
||||
assertEquals("circle EMPTY", wkt.toWKT(Circle.EMPTY));
|
||||
assertEquals(Circle.EMPTY, wkt.fromWKT("circle EMPTY)"));
|
||||
@ -52,18 +52,18 @@ public class CircleTests extends BaseGeometryTestCase<Circle> {
|
||||
|
||||
public void testInitValidation() {
|
||||
GeometryValidator validator = new GeographyValidator(true);
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Circle(10, 20, -1)));
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Circle(20, 10, -1)));
|
||||
assertEquals("Circle radius [-1.0] cannot be negative", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Circle(100, 20, 1)));
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Circle(20, 100, 1)));
|
||||
assertEquals("invalid latitude 100.0; must be between -90.0 and 90.0", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Circle(10, 200, 1)));
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Circle(200, 10, 1)));
|
||||
assertEquals("invalid longitude 200.0; must be between -180.0 and 180.0", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(new Circle(10, 200, 1, 20)));
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(new Circle(200, 10, 1, 20)));
|
||||
assertEquals("found Z value [1.0] but [ignore_z_value] parameter is [false]", ex.getMessage());
|
||||
|
||||
new StandardValidator(true).validate(new Circle(10, 200, 1, 20));
|
||||
new StandardValidator(true).validate(new Circle(200, 10, 1, 20));
|
||||
}
|
||||
}
|
@ -17,12 +17,12 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geo.GeometryTestUtils;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
@ -35,14 +35,12 @@ public class GeometryCollectionTests extends BaseGeometryTestCase<GeometryCollec
|
||||
return GeometryTestUtils.randomGeometryCollection(hasAlt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testBasicSerialization() throws IOException, ParseException {
|
||||
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
|
||||
assertEquals("geometrycollection (point (20.0 10.0),point EMPTY)",
|
||||
wkt.toWKT(new GeometryCollection<Geometry>(Arrays.asList(new Point(10, 20), Point.EMPTY))));
|
||||
wkt.toWKT(new GeometryCollection<Geometry>(Arrays.asList(new Point(20, 10), Point.EMPTY))));
|
||||
|
||||
assertEquals(new GeometryCollection<Geometry>(Arrays.asList(new Point(10, 20), Point.EMPTY)),
|
||||
assertEquals(new GeometryCollection<Geometry>(Arrays.asList(new Point(20, 10), Point.EMPTY)),
|
||||
wkt.fromWKT("geometrycollection (point (20.0 10.0),point EMPTY)"));
|
||||
|
||||
assertEquals("geometrycollection EMPTY", wkt.toWKT(GeometryCollection.EMPTY));
|
||||
@ -58,13 +56,13 @@ public class GeometryCollectionTests extends BaseGeometryTestCase<GeometryCollec
|
||||
assertEquals("the list of shapes cannot be null or empty", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> new GeometryCollection<>(
|
||||
Arrays.asList(new Point(10, 20), new Point(10, 20, 30))));
|
||||
Arrays.asList(new Point(20, 10), new Point(20, 10, 30))));
|
||||
assertEquals("all elements of the collection should have the same number of dimension", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(
|
||||
new GeometryCollection<Geometry>(Collections.singletonList(new Point(10, 20, 30)))));
|
||||
new GeometryCollection<Geometry>(Collections.singletonList(new Point(20, 10, 30)))));
|
||||
assertEquals("found Z value [30.0] but [ignore_z_value] parameter is [false]", ex.getMessage());
|
||||
|
||||
new StandardValidator(true).validate(new GeometryCollection<Geometry>(Collections.singletonList(new Point(10, 20, 30))));
|
||||
new StandardValidator(true).validate(new GeometryCollection<Geometry>(Collections.singletonList(new Point(20, 10, 30))));
|
||||
}
|
||||
}
|
@ -17,11 +17,11 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.GeometryValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.GeometryValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
public class GeometryValidatorTests extends ESTestCase {
|
@ -17,13 +17,13 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geo.GeometryTestUtils;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.GeometryValidator;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.GeometryValidator;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
@ -36,12 +36,12 @@ public class LineTests extends BaseGeometryTestCase<Line> {
|
||||
|
||||
public void testBasicSerialization() throws IOException, ParseException {
|
||||
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
|
||||
assertEquals("linestring (3.0 1.0, 4.0 2.0)", wkt.toWKT(new Line(new double[]{1, 2}, new double[]{3, 4})));
|
||||
assertEquals(new Line(new double[]{1, 2}, new double[]{3, 4}), wkt.fromWKT("linestring (3 1, 4 2)"));
|
||||
assertEquals("linestring (3.0 1.0, 4.0 2.0)", wkt.toWKT(new Line(new double[]{3, 4}, new double[]{1, 2})));
|
||||
assertEquals(new Line(new double[]{3, 4}, new double[]{1, 2}), wkt.fromWKT("linestring (3 1, 4 2)"));
|
||||
|
||||
assertEquals("linestring (3.0 1.0 5.0, 4.0 2.0 6.0)", wkt.toWKT(new Line(new double[]{1, 2}, new double[]{3, 4},
|
||||
assertEquals("linestring (3.0 1.0 5.0, 4.0 2.0 6.0)", wkt.toWKT(new Line(new double[]{3, 4}, new double[]{1, 2},
|
||||
new double[]{5, 6})));
|
||||
assertEquals(new Line(new double[]{1, 2}, new double[]{3, 4}, new double[]{6, 5}),
|
||||
assertEquals(new Line(new double[]{3, 4}, new double[]{1, 2}, new double[]{6, 5}),
|
||||
wkt.fromWKT("linestring (3 1 6, 4 2 5)"));
|
||||
|
||||
assertEquals("linestring EMPTY", wkt.toWKT(Line.EMPTY));
|
||||
@ -51,22 +51,22 @@ public class LineTests extends BaseGeometryTestCase<Line> {
|
||||
public void testInitValidation() {
|
||||
GeometryValidator validator = new GeographyValidator(true);
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> validator.validate(new Line(new double[]{1}, new double[]{3})));
|
||||
() -> validator.validate(new Line(new double[]{3}, new double[]{1})));
|
||||
assertEquals("at least two points in the line is required", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> validator.validate(new Line(new double[]{1, 2, 3, 1}, new double[]{3, 4, 500, 3})));
|
||||
() -> validator.validate(new Line(new double[]{3, 4, 500, 3}, new double[]{1, 2, 3, 1})));
|
||||
assertEquals("invalid longitude 500.0; must be between -180.0 and 180.0", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> validator.validate(new Line(new double[]{1, 100, 3, 1}, new double[]{3, 4, 5, 3})));
|
||||
() -> validator.validate(new Line(new double[]{3, 4, 5, 3}, new double[]{1, 100, 3, 1})));
|
||||
assertEquals("invalid latitude 100.0; must be between -90.0 and 90.0", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(
|
||||
new Line(new double[]{1, 2}, new double[]{3, 4}, new double[]{6, 5})));
|
||||
new Line(new double[]{3, 4}, new double[]{1, 2}, new double[]{6, 5})));
|
||||
assertEquals("found Z value [6.0] but [ignore_z_value] parameter is [false]", ex.getMessage());
|
||||
|
||||
new StandardValidator(true).validate(new Line(new double[]{1, 2}, new double[]{3, 4}, new double[]{6, 5}));
|
||||
new StandardValidator(true).validate(new Line(new double[]{3, 4}, new double[]{1, 2}, new double[]{6, 5}));
|
||||
}
|
||||
|
||||
public void testWKTValidation() {
|
@ -17,12 +17,12 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.GeometryValidator;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.GeometryValidator;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
public class LinearRingTests extends ESTestCase {
|
||||
@ -30,44 +30,44 @@ public class LinearRingTests extends ESTestCase {
|
||||
public void testBasicSerialization() {
|
||||
UnsupportedOperationException ex = expectThrows(UnsupportedOperationException.class,
|
||||
() -> new WellKnownText(true, new GeographyValidator(true))
|
||||
.toWKT(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3})));
|
||||
.toWKT(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1})));
|
||||
assertEquals("line ring cannot be serialized using WKT", ex.getMessage());
|
||||
}
|
||||
|
||||
public void testInitValidation() {
|
||||
GeometryValidator validator = new GeographyValidator(true);
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> validator.validate(new LinearRing(new double[]{1, 2, 3}, new double[]{3, 4, 5})));
|
||||
assertEquals("first and last points of the linear ring must be the same (it must close itself): lats[0]=1.0 lats[2]=3.0 " +
|
||||
"lons[0]=3.0 lons[2]=5.0",
|
||||
() -> validator.validate(new LinearRing(new double[]{3, 4, 5}, new double[]{1, 2, 3})));
|
||||
assertEquals("first and last points of the linear ring must be the same (it must close itself): x[0]=3.0 x[2]=5.0 y[0]=1.0 " +
|
||||
"y[2]=3.0",
|
||||
ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> validator.validate(new LinearRing(new double[]{1, 2, 1}, new double[]{3, 4, 3}, new double[]{1, 2, 3})));
|
||||
assertEquals("first and last points of the linear ring must be the same (it must close itself): lats[0]=1.0 lats[2]=1.0 " +
|
||||
"lons[0]=3.0 lons[2]=3.0 alts[0]=1.0 alts[2]=3.0",
|
||||
() -> validator.validate(new LinearRing(new double[]{3, 4, 3}, new double[]{1, 2, 1}, new double[]{1, 2, 3})));
|
||||
assertEquals("first and last points of the linear ring must be the same (it must close itself): x[0]=3.0 x[2]=3.0 y[0]=1.0 " +
|
||||
"y[2]=1.0 z[0]=1.0 z[2]=3.0",
|
||||
ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> validator.validate(new LinearRing(new double[]{1}, new double[]{3})));
|
||||
() -> validator.validate(new LinearRing(new double[]{3}, new double[]{1})));
|
||||
assertEquals("at least two points in the line is required", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> validator.validate(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 500, 3})));
|
||||
() -> validator.validate(new LinearRing(new double[]{3, 4, 500, 3}, new double[]{1, 2, 3, 1})));
|
||||
assertEquals("invalid longitude 500.0; must be between -180.0 and 180.0", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> validator.validate(new LinearRing(new double[]{1, 100, 3, 1}, new double[]{3, 4, 5, 3})));
|
||||
() -> validator.validate(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 100, 3, 1})));
|
||||
assertEquals("invalid latitude 100.0; must be between -90.0 and 90.0", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(
|
||||
new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}, new double[]{1, 1, 1, 1})));
|
||||
new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{1, 1, 1, 1})));
|
||||
assertEquals("found Z value [1.0] but [ignore_z_value] parameter is [false]", ex.getMessage());
|
||||
|
||||
new StandardValidator(true).validate(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}, new double[]{1, 1, 1, 1}));
|
||||
new StandardValidator(true).validate(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{1, 1, 1, 1}));
|
||||
}
|
||||
|
||||
public void testVisitor() {
|
||||
BaseGeometryTestCase.testVisitor(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}));
|
||||
BaseGeometryTestCase.testVisitor(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}));
|
||||
}
|
||||
}
|
@ -17,12 +17,12 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geo.GeometryTestUtils;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
@ -45,8 +45,8 @@ public class MultiLineTests extends BaseGeometryTestCase<MultiLine> {
|
||||
public void testBasicSerialization() throws IOException, ParseException {
|
||||
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
|
||||
assertEquals("multilinestring ((3.0 1.0, 4.0 2.0))", wkt.toWKT(
|
||||
new MultiLine(Collections.singletonList(new Line(new double[]{1, 2}, new double[]{3, 4})))));
|
||||
assertEquals(new MultiLine(Collections.singletonList(new Line(new double[]{1, 2}, new double[]{3, 4}))),
|
||||
new MultiLine(Collections.singletonList(new Line(new double[]{3, 4}, new double[]{1, 2})))));
|
||||
assertEquals(new MultiLine(Collections.singletonList(new Line(new double[]{3, 4}, new double[]{1, 2}))),
|
||||
wkt.fromWKT("multilinestring ((3 1, 4 2))"));
|
||||
|
||||
assertEquals("multilinestring EMPTY", wkt.toWKT(MultiLine.EMPTY));
|
||||
@ -55,10 +55,10 @@ public class MultiLineTests extends BaseGeometryTestCase<MultiLine> {
|
||||
|
||||
public void testValidation() {
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(
|
||||
new MultiLine(Collections.singletonList(new Line(new double[]{1, 2}, new double[]{3, 4}, new double[]{6, 5})))));
|
||||
new MultiLine(Collections.singletonList(new Line(new double[]{3, 4}, new double[]{1, 2}, new double[]{6, 5})))));
|
||||
assertEquals("found Z value [6.0] but [ignore_z_value] parameter is [false]", ex.getMessage());
|
||||
|
||||
new StandardValidator(true).validate(
|
||||
new MultiLine(Collections.singletonList(new Line(new double[]{1, 2}, new double[]{3, 4}, new double[]{6, 5}))));
|
||||
new MultiLine(Collections.singletonList(new Line(new double[]{3, 4}, new double[]{1, 2}, new double[]{6, 5}))));
|
||||
}
|
||||
}
|
@ -17,12 +17,12 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geo.GeometryTestUtils;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
@ -46,18 +46,18 @@ public class MultiPointTests extends BaseGeometryTestCase<MultiPoint> {
|
||||
public void testBasicSerialization() throws IOException, ParseException {
|
||||
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
|
||||
assertEquals("multipoint (2.0 1.0)", wkt.toWKT(
|
||||
new MultiPoint(Collections.singletonList(new Point(1, 2)))));
|
||||
assertEquals(new MultiPoint(Collections.singletonList(new Point(1 ,2))),
|
||||
new MultiPoint(Collections.singletonList(new Point(2, 1)))));
|
||||
assertEquals(new MultiPoint(Collections.singletonList(new Point(2, 1))),
|
||||
wkt.fromWKT("multipoint (2 1)"));
|
||||
|
||||
assertEquals("multipoint (2.0 1.0, 3.0 4.0)",
|
||||
wkt.toWKT(new MultiPoint(Arrays.asList(new Point(1, 2), new Point(4, 3)))));
|
||||
assertEquals(new MultiPoint(Arrays.asList(new Point(1, 2), new Point(4, 3))),
|
||||
wkt.toWKT(new MultiPoint(Arrays.asList(new Point(2, 1), new Point(3, 4)))));
|
||||
assertEquals(new MultiPoint(Arrays.asList(new Point(2, 1), new Point(3, 4))),
|
||||
wkt.fromWKT("multipoint (2 1, 3 4)"));
|
||||
|
||||
assertEquals("multipoint (2.0 1.0 10.0, 3.0 4.0 20.0)",
|
||||
wkt.toWKT(new MultiPoint(Arrays.asList(new Point(1, 2, 10), new Point(4, 3, 20)))));
|
||||
assertEquals(new MultiPoint(Arrays.asList(new Point(1, 2, 10), new Point(4, 3, 20))),
|
||||
wkt.toWKT(new MultiPoint(Arrays.asList(new Point(2, 1, 10), new Point(3, 4, 20)))));
|
||||
assertEquals(new MultiPoint(Arrays.asList(new Point(2, 1, 10), new Point(3, 4, 20))),
|
||||
wkt.fromWKT("multipoint (2 1 10, 3 4 20)"));
|
||||
|
||||
assertEquals("multipoint EMPTY", wkt.toWKT(MultiPoint.EMPTY));
|
||||
@ -66,9 +66,9 @@ public class MultiPointTests extends BaseGeometryTestCase<MultiPoint> {
|
||||
|
||||
public void testValidation() {
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(
|
||||
new MultiPoint(Collections.singletonList(new Point(1, 2 ,3)))));
|
||||
new MultiPoint(Collections.singletonList(new Point(2, 1, 3)))));
|
||||
assertEquals("found Z value [3.0] but [ignore_z_value] parameter is [false]", ex.getMessage());
|
||||
|
||||
new StandardValidator(true).validate(new MultiPoint(Collections.singletonList(new Point(1, 2 ,3))));
|
||||
new StandardValidator(true).validate(new MultiPoint(Collections.singletonList(new Point(2, 1, 3))));
|
||||
}
|
||||
}
|
@ -17,12 +17,12 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geo.GeometryTestUtils;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
@ -46,9 +46,9 @@ public class MultiPolygonTests extends BaseGeometryTestCase<MultiPolygon> {
|
||||
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
|
||||
assertEquals("multipolygon (((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0)))",
|
||||
wkt.toWKT(new MultiPolygon(Collections.singletonList(
|
||||
new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}))))));
|
||||
new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}))))));
|
||||
assertEquals(new MultiPolygon(Collections.singletonList(
|
||||
new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3})))),
|
||||
new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1})))),
|
||||
wkt.fromWKT("multipolygon (((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0)))"));
|
||||
|
||||
assertEquals("multipolygon EMPTY", wkt.toWKT(MultiPolygon.EMPTY));
|
||||
@ -58,12 +58,12 @@ public class MultiPolygonTests extends BaseGeometryTestCase<MultiPolygon> {
|
||||
public void testValidation() {
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(
|
||||
new MultiPolygon(Collections.singletonList(
|
||||
new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}))
|
||||
new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{1, 2, 3, 1}))
|
||||
))));
|
||||
assertEquals("found Z value [1.0] but [ignore_z_value] parameter is [false]", ex.getMessage());
|
||||
|
||||
new StandardValidator(true).validate(
|
||||
new MultiPolygon(Collections.singletonList(
|
||||
new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1})))));
|
||||
new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{1, 2, 3, 1})))));
|
||||
}
|
||||
}
|
@ -17,13 +17,13 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geo.GeometryTestUtils;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.GeometryValidator;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.GeometryValidator;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
@ -36,11 +36,11 @@ public class PointTests extends BaseGeometryTestCase<Point> {
|
||||
|
||||
public void testBasicSerialization() throws IOException, ParseException {
|
||||
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
|
||||
assertEquals("point (20.0 10.0)", wkt.toWKT(new Point(10, 20)));
|
||||
assertEquals(new Point(10, 20), wkt.fromWKT("point (20.0 10.0)"));
|
||||
assertEquals("point (20.0 10.0)", wkt.toWKT(new Point(20, 10)));
|
||||
assertEquals(new Point(20, 10), wkt.fromWKT("point (20.0 10.0)"));
|
||||
|
||||
assertEquals("point (20.0 10.0 100.0)", wkt.toWKT(new Point(10, 20, 100)));
|
||||
assertEquals(new Point(10, 20, 100), wkt.fromWKT("point (20.0 10.0 100.0)"));
|
||||
assertEquals("point (20.0 10.0 100.0)", wkt.toWKT(new Point(20, 10, 100)));
|
||||
assertEquals(new Point(20, 10, 100), wkt.fromWKT("point (20.0 10.0 100.0)"));
|
||||
|
||||
assertEquals("point EMPTY", wkt.toWKT(Point.EMPTY));
|
||||
assertEquals(Point.EMPTY, wkt.fromWKT("point EMPTY)"));
|
||||
@ -48,16 +48,16 @@ public class PointTests extends BaseGeometryTestCase<Point> {
|
||||
|
||||
public void testInitValidation() {
|
||||
GeometryValidator validator = new GeographyValidator(true);
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Point(100, 10)));
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Point(10, 100)));
|
||||
assertEquals("invalid latitude 100.0; must be between -90.0 and 90.0", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Point(10, 500)));
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Point(500, 10)));
|
||||
assertEquals("invalid longitude 500.0; must be between -180.0 and 180.0", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(new Point(1, 2, 3)));
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(new Point(2, 1, 3)));
|
||||
assertEquals("found Z value [3.0] but [ignore_z_value] parameter is [false]", ex.getMessage());
|
||||
|
||||
new StandardValidator(true).validate(new Point(1, 2, 3));
|
||||
new StandardValidator(true).validate(new Point(2, 1, 3));
|
||||
}
|
||||
|
||||
public void testWKTValidation() {
|
@ -17,12 +17,12 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geo.GeometryTestUtils;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
@ -37,22 +37,22 @@ public class PolygonTests extends BaseGeometryTestCase<Polygon> {
|
||||
public void testBasicSerialization() throws IOException, ParseException {
|
||||
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
|
||||
assertEquals("polygon ((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0))",
|
||||
wkt.toWKT(new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}))));
|
||||
assertEquals(new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3})),
|
||||
wkt.toWKT(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}))));
|
||||
assertEquals(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1})),
|
||||
wkt.fromWKT("polygon ((3 1, 4 2, 5 3, 3 1))"));
|
||||
|
||||
assertEquals("polygon ((3.0 1.0 5.0, 4.0 2.0 4.0, 5.0 3.0 3.0, 3.0 1.0 5.0))",
|
||||
wkt.toWKT(new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}, new double[]{5, 4, 3, 5}))));
|
||||
assertEquals(new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}, new double[]{5, 4, 3, 5})),
|
||||
wkt.toWKT(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{5, 4, 3, 5}))));
|
||||
assertEquals(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{5, 4, 3, 5})),
|
||||
wkt.fromWKT("polygon ((3 1 5, 4 2 4, 5 3 3, 3 1 5))"));
|
||||
|
||||
// Auto closing in coerce mode
|
||||
assertEquals(new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3})),
|
||||
assertEquals(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1})),
|
||||
wkt.fromWKT("polygon ((3 1, 4 2, 5 3))"));
|
||||
assertEquals(new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}, new double[]{5, 4, 3, 5})),
|
||||
assertEquals(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{5, 4, 3, 5})),
|
||||
wkt.fromWKT("polygon ((3 1 5, 4 2 4, 5 3 3))"));
|
||||
assertEquals(new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}),
|
||||
Collections.singletonList(new LinearRing(new double[]{1.5, 1.5, 1.0, 1.5}, new double[]{0.5, 2.5, 2.0, 0.5}))),
|
||||
assertEquals(new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}),
|
||||
Collections.singletonList(new LinearRing(new double[]{0.5, 2.5, 2.0, 0.5}, new double[]{1.5, 1.5, 1.0, 1.5}))),
|
||||
wkt.fromWKT("polygon ((3 1, 4 2, 5 3, 3 1), (0.5 1.5, 2.5 1.5, 2.0 1.0))"));
|
||||
|
||||
assertEquals("polygon EMPTY", wkt.toWKT(Polygon.EMPTY));
|
||||
@ -61,31 +61,31 @@ public class PolygonTests extends BaseGeometryTestCase<Polygon> {
|
||||
|
||||
public void testInitValidation() {
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> new Polygon(new LinearRing(new double[]{1, 2, 1}, new double[]{3, 4, 3})));
|
||||
() -> new Polygon(new LinearRing(new double[]{3, 4, 3}, new double[]{1, 2, 1})));
|
||||
assertEquals("at least 4 polygon points required", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}), null));
|
||||
() -> new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}), null));
|
||||
assertEquals("holes must not be null", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}, new double[]{5, 4, 3, 5}),
|
||||
Collections.singletonList(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}))));
|
||||
() -> new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{5, 4, 3, 5}),
|
||||
Collections.singletonList(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}))));
|
||||
assertEquals("holes must have the same number of dimensions as the polygon", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(
|
||||
new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}))));
|
||||
new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{1, 2, 3, 1}))));
|
||||
assertEquals("found Z value [1.0] but [ignore_z_value] parameter is [false]", ex.getMessage());
|
||||
|
||||
new StandardValidator(true).validate(
|
||||
new Polygon(new LinearRing(new double[]{1, 2, 3, 1}, new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1})));
|
||||
new Polygon(new LinearRing(new double[]{3, 4, 5, 3}, new double[]{1, 2, 3, 1}, new double[]{1, 2, 3, 1})));
|
||||
}
|
||||
|
||||
public void testWKTValidation() {
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> new WellKnownText(false, new GeographyValidator(true)).fromWKT("polygon ((3 1 5, 4 2 4, 5 3 3))"));
|
||||
assertEquals("first and last points of the linear ring must be the same (it must close itself): " +
|
||||
"lats[0]=1.0 lats[2]=3.0 lons[0]=3.0 lons[2]=5.0 alts[0]=5.0 alts[2]=3.0", ex.getMessage());
|
||||
"x[0]=3.0 x[2]=5.0 y[0]=1.0 y[2]=3.0 z[0]=5.0 z[2]=3.0", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> new WellKnownText(randomBoolean(), new GeographyValidator(false)).fromWKT("polygon ((3 1 5, 4 2 4, 5 3 3, 3 1 5))"));
|
||||
@ -95,6 +95,6 @@ public class PolygonTests extends BaseGeometryTestCase<Polygon> {
|
||||
() -> new WellKnownText(false, new GeographyValidator(randomBoolean())).fromWKT(
|
||||
"polygon ((3 1, 4 2, 5 3, 3 1), (0.5 1.5, 2.5 1.5, 2.0 1.0))"));
|
||||
assertEquals("first and last points of the linear ring must be the same (it must close itself): " +
|
||||
"lats[0]=1.5 lats[2]=1.0 lons[0]=0.5 lons[2]=2.0", ex.getMessage());
|
||||
"x[0]=0.5 x[2]=2.0 y[0]=1.5 y[2]=1.0", ex.getMessage());
|
||||
}
|
||||
}
|
@ -17,13 +17,13 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.geo.geometry;
|
||||
package org.elasticsearch.geometry;
|
||||
|
||||
import org.elasticsearch.geo.GeometryTestUtils;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.GeometryValidator;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.GeometryValidator;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
@ -37,8 +37,8 @@ public class RectangleTests extends BaseGeometryTestCase<Rectangle> {
|
||||
|
||||
public void testBasicSerialization() throws IOException, ParseException {
|
||||
WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
|
||||
assertEquals("bbox (10.0, 20.0, 40.0, 30.0)", wkt.toWKT(new Rectangle(30, 40, 10, 20)));
|
||||
assertEquals(new Rectangle(30, 40, 10, 20), wkt.fromWKT("bbox (10.0, 20.0, 40.0, 30.0)"));
|
||||
assertEquals("bbox (10.0, 20.0, 40.0, 30.0)", wkt.toWKT(new Rectangle(10, 20, 40, 30)));
|
||||
assertEquals(new Rectangle(10, 20, 40, 30), wkt.fromWKT("bbox (10.0, 20.0, 40.0, 30.0)"));
|
||||
|
||||
assertEquals("bbox EMPTY", wkt.toWKT(Rectangle.EMPTY));
|
||||
assertEquals(Rectangle.EMPTY, wkt.fromWKT("bbox EMPTY)"));
|
||||
@ -47,25 +47,25 @@ public class RectangleTests extends BaseGeometryTestCase<Rectangle> {
|
||||
public void testInitValidation() {
|
||||
GeometryValidator validator = new GeographyValidator(true);
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> validator.validate(new Rectangle(1, 100, 2, 3)));
|
||||
() -> validator.validate(new Rectangle(2, 3, 100, 1)));
|
||||
assertEquals("invalid latitude 100.0; must be between -90.0 and 90.0", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> validator.validate(new Rectangle(1, 2, 200, 3)));
|
||||
() -> validator.validate(new Rectangle(200, 3, 2, 1)));
|
||||
assertEquals("invalid longitude 200.0; must be between -180.0 and 180.0", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> validator.validate(new Rectangle(2, 1, 2, 3)));
|
||||
assertEquals("max lat cannot be less than min lat", ex.getMessage());
|
||||
() -> validator.validate(new Rectangle(2, 3, 1, 2)));
|
||||
assertEquals("max y cannot be less than min x", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> validator.validate(new Rectangle(1, 2, 2, 3, 5, Double.NaN)));
|
||||
assertEquals("only one altitude value is specified", ex.getMessage());
|
||||
() -> validator.validate(new Rectangle(2, 3, 2, 1, 5, Double.NaN)));
|
||||
assertEquals("only one z value is specified", ex.getMessage());
|
||||
|
||||
ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(
|
||||
new Rectangle(30, 40, 50, 10, 20, 60)));
|
||||
new Rectangle(50, 10, 40, 30, 20, 60)));
|
||||
assertEquals("found Z value [20.0] but [ignore_z_value] parameter is [false]", ex.getMessage());
|
||||
|
||||
new StandardValidator(true).validate(new Rectangle(30, 40, 50, 10, 20, 60));
|
||||
new StandardValidator(true).validate(new Rectangle(50, 10, 40, 30, 20, 60));
|
||||
}
|
||||
}
|
@ -16,14 +16,14 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.geo.utils;
|
||||
package org.elasticsearch.geometry.utils;
|
||||
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@link org.elasticsearch.geo.utils.Geohash}
|
||||
* Tests for {@link Geohash}
|
||||
*/
|
||||
public class GeoHashTests extends ESTestCase {
|
||||
public void testGeohashAsLongRoutines() {
|
||||
@ -67,9 +67,9 @@ public class GeoHashTests extends ESTestCase {
|
||||
// check that the length is as expected
|
||||
double expectedLonDiff = 360.0 / (Math.pow(8.0, (level + 1) / 2) * Math.pow(4.0, level / 2));
|
||||
double expectedLatDiff = 180.0 / (Math.pow(4.0, (level + 1) / 2) * Math.pow(8.0, level / 2));
|
||||
assertEquals(expectedLonDiff, bbox.getMaxLon() - bbox.getMinLon(), 0.00001);
|
||||
assertEquals(expectedLatDiff, bbox.getMaxLat() - bbox.getMinLat(), 0.00001);
|
||||
assertEquals(hash, Geohash.stringEncode(bbox.getMinLon(), bbox.getMinLat(), level));
|
||||
assertEquals(expectedLonDiff, bbox.getMaxX() - bbox.getMinX(), 0.00001);
|
||||
assertEquals(expectedLatDiff, bbox.getMaxY() - bbox.getMinY(), 0.00001);
|
||||
assertEquals(hash, Geohash.stringEncode(bbox.getMinX(), bbox.getMinY(), level));
|
||||
}
|
||||
|
||||
public void testGeohashExtremes() {
|
||||
@ -101,7 +101,7 @@ public class GeoHashTests extends ESTestCase {
|
||||
|
||||
public void testNorthPoleBoundingBox() {
|
||||
Rectangle bbox = Geohash.toBoundingBox("zzbxfpgzupbx"); // Bounding box with maximum precision touching north pole
|
||||
assertEquals(90.0, bbox.getMaxLat(), 0.0000001); // Should be 90 degrees
|
||||
assertEquals(90.0, bbox.getMaxY(), 0.0000001); // Should be 90 degrees
|
||||
}
|
||||
|
||||
public void testInvalidGeohashes() {
|
@ -31,20 +31,20 @@ import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentSubParser;
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Polygon;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geo.geometry.ShapeType;
|
||||
import org.elasticsearch.geo.utils.GeometryValidator;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.ShapeType;
|
||||
import org.elasticsearch.geometry.utils.GeometryValidator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -92,7 +92,7 @@ public final class GeoJson {
|
||||
public XContentBuilder visit(Circle circle) throws IOException {
|
||||
builder.field(FIELD_RADIUS.getPreferredName(), DistanceUnit.METERS.toString(circle.getRadiusMeters()));
|
||||
builder.field(ShapeParser.FIELD_COORDINATES.getPreferredName());
|
||||
return coordinatesToXContent(circle.getLat(), circle.getLon(), circle.getAlt());
|
||||
return coordinatesToXContent(circle.getY(), circle.getX(), circle.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -130,9 +130,9 @@ public final class GeoJson {
|
||||
builder.startArray(ShapeParser.FIELD_COORDINATES.getPreferredName());
|
||||
for (int i = 0; i < multiPoint.size(); i++) {
|
||||
Point p = multiPoint.get(i);
|
||||
builder.startArray().value(p.getLon()).value(p.getLat());
|
||||
if (p.hasAlt()) {
|
||||
builder.value(p.getAlt());
|
||||
builder.startArray().value(p.getX()).value(p.getY());
|
||||
if (p.hasZ()) {
|
||||
builder.value(p.getZ());
|
||||
}
|
||||
builder.endArray();
|
||||
}
|
||||
@ -153,7 +153,7 @@ public final class GeoJson {
|
||||
@Override
|
||||
public XContentBuilder visit(Point point) throws IOException {
|
||||
builder.field(ShapeParser.FIELD_COORDINATES.getPreferredName());
|
||||
return coordinatesToXContent(point.getLat(), point.getLon(), point.getAlt());
|
||||
return coordinatesToXContent(point.getY(), point.getX(), point.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -169,8 +169,8 @@ public final class GeoJson {
|
||||
@Override
|
||||
public XContentBuilder visit(Rectangle rectangle) throws IOException {
|
||||
builder.startArray(ShapeParser.FIELD_COORDINATES.getPreferredName());
|
||||
coordinatesToXContent(rectangle.getMaxLat(), rectangle.getMinLon(), rectangle.getMinAlt()); // top left
|
||||
coordinatesToXContent(rectangle.getMinLat(), rectangle.getMaxLon(), rectangle.getMaxAlt()); // bottom right
|
||||
coordinatesToXContent(rectangle.getMaxY(), rectangle.getMinX(), rectangle.getMinZ()); // top left
|
||||
coordinatesToXContent(rectangle.getMinY(), rectangle.getMaxX(), rectangle.getMaxZ()); // bottom right
|
||||
return builder.endArray();
|
||||
}
|
||||
|
||||
@ -185,9 +185,9 @@ public final class GeoJson {
|
||||
private XContentBuilder coordinatesToXContent(Line line) throws IOException {
|
||||
builder.startArray();
|
||||
for (int i = 0; i < line.length(); i++) {
|
||||
builder.startArray().value(line.getLon(i)).value(line.getLat(i));
|
||||
if (line.hasAlt()) {
|
||||
builder.value(line.getAlt(i));
|
||||
builder.startArray().value(line.getX(i)).value(line.getY(i));
|
||||
if (line.hasZ()) {
|
||||
builder.value(line.getZ(i));
|
||||
}
|
||||
builder.endArray();
|
||||
}
|
||||
@ -257,7 +257,7 @@ public final class GeoJson {
|
||||
}
|
||||
verifyNulls(type, geometries, orientation, null);
|
||||
Point point = coordinates.asPoint();
|
||||
return new Circle(point.getLat(), point.getLon(), point.getAlt(), radius.convert(DistanceUnit.METERS).value);
|
||||
return new Circle(point.getX(), point.getY(), point.getZ(), radius.convert(DistanceUnit.METERS).value);
|
||||
case POINT:
|
||||
verifyNulls(type, geometries, orientation, radius);
|
||||
return coordinates.asPoint();
|
||||
@ -353,7 +353,7 @@ public final class GeoJson {
|
||||
if (parser.currentToken() == XContentParser.Token.VALUE_NUMBER) {
|
||||
throw new ElasticsearchParseException("geo coordinates greater than 3 dimensions are not supported");
|
||||
}
|
||||
return new Point(lat, lon, alt);
|
||||
return new Point(lon, lat, alt);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -465,7 +465,7 @@ public final class GeoJson {
|
||||
throw new ElasticsearchException("attempting to get number of dimensions on an empty coordinate node");
|
||||
}
|
||||
if (coordinate != null) {
|
||||
return coordinate.hasAlt() ? 3 : 2;
|
||||
return coordinate.hasZ() ? 3 : 2;
|
||||
}
|
||||
return children.get(0).numDimensions();
|
||||
}
|
||||
@ -513,10 +513,10 @@ public final class GeoJson {
|
||||
int i = orientation ? 0 : lats.length - 1;
|
||||
for (CoordinateNode node : children) {
|
||||
Point point = node.asPoint();
|
||||
lats[i] = point.getLat();
|
||||
lons[i] = point.getLon();
|
||||
lats[i] = point.getY();
|
||||
lons[i] = point.getX();
|
||||
if (alts != null) {
|
||||
alts[i] = point.getAlt();
|
||||
alts[i] = point.getZ();
|
||||
}
|
||||
i = orientation ? i + 1 : i - 1;
|
||||
}
|
||||
@ -536,12 +536,12 @@ public final class GeoJson {
|
||||
|
||||
public Line asLineString(boolean coerce) {
|
||||
double[][] components = asLineComponents(true, coerce, false);
|
||||
return new Line(components[0], components[1], components[2]);
|
||||
return new Line(components[1], components[0], components[2]);
|
||||
}
|
||||
|
||||
public LinearRing asLinearRing(boolean orientation, boolean coerce) {
|
||||
double[][] components = asLineComponents(orientation, coerce, true);
|
||||
return new LinearRing(components[0], components[1], components[2]);
|
||||
return new LinearRing(components[1], components[0], components[2]);
|
||||
}
|
||||
|
||||
public MultiLine asMultiLineString(boolean coerce) {
|
||||
@ -592,13 +592,13 @@ public final class GeoJson {
|
||||
// verify coordinate bounds, correct if necessary
|
||||
Point uL = children.get(0).coordinate;
|
||||
Point lR = children.get(1).coordinate;
|
||||
return new Rectangle(lR.getLat(), uL.getLat(), uL.getLon(), lR.getLon());
|
||||
return new Rectangle(uL.getX(), lR.getX(), uL.getY(), lR.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
if (children == null) {
|
||||
builder.startArray().value(coordinate.getLon()).value(coordinate.getLat()).endArray();
|
||||
builder.startArray().value(coordinate.getX()).value(coordinate.getY()).endArray();
|
||||
} else {
|
||||
builder.startArray();
|
||||
for (CoordinateNode child : children) {
|
||||
|
@ -29,13 +29,13 @@ import org.elasticsearch.common.geo.GeoUtils.EffectivePoint;
|
||||
import org.elasticsearch.common.xcontent.ToXContentFragment;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geo.geometry.ShapeType;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.ShapeType;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
@ -137,7 +137,7 @@ public final class GeoPoint implements ToXContentFragment {
|
||||
"but found " + geometry.type());
|
||||
}
|
||||
Point point = (Point) geometry;
|
||||
return reset(point.getLat(), point.getLon());
|
||||
return reset(point.getY(), point.getX());
|
||||
}
|
||||
|
||||
GeoPoint parseGeoHash(String geohash, EffectivePoint effectivePoint) {
|
||||
@ -147,11 +147,11 @@ public final class GeoPoint implements ToXContentFragment {
|
||||
Rectangle rectangle = Geohash.toBoundingBox(geohash);
|
||||
switch (effectivePoint) {
|
||||
case TOP_LEFT:
|
||||
return reset(rectangle.getMaxLat(), rectangle.getMinLon());
|
||||
return reset(rectangle.getMaxY(), rectangle.getMinX());
|
||||
case TOP_RIGHT:
|
||||
return reset(rectangle.getMaxLat(), rectangle.getMaxLon());
|
||||
return reset(rectangle.getMaxY(), rectangle.getMaxX());
|
||||
case BOTTOM_RIGHT:
|
||||
return reset(rectangle.getMinLat(), rectangle.getMaxLon());
|
||||
return reset(rectangle.getMinY(), rectangle.getMaxX());
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported effective point " + effectivePoint);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ package org.elasticsearch.common.geo;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
|
@ -21,18 +21,18 @@ package org.elasticsearch.common.geo;
|
||||
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Polygon;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -86,7 +86,7 @@ public final class GeometryIO {
|
||||
out.writeVInt(multiPoint.size());
|
||||
for (int i = 0; i < multiPoint.size(); i++) {
|
||||
Point point = multiPoint.get(i);
|
||||
writeCoordinate(point.getLat(), point.getLon(), point.getAlt());
|
||||
writeCoordinate(point.getY(), point.getX(), point.getZ());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -104,7 +104,7 @@ public final class GeometryIO {
|
||||
@Override
|
||||
public Void visit(Point point) throws IOException {
|
||||
out.writeVInt(1); // Number of points For BWC with Shape Builder
|
||||
writeCoordinate(point.getLat(), point.getLon(), point.getAlt());
|
||||
writeCoordinate(point.getY(), point.getX(), point.getZ());
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -121,8 +121,8 @@ public final class GeometryIO {
|
||||
|
||||
@Override
|
||||
public Void visit(Rectangle rectangle) throws IOException {
|
||||
writeCoordinate(rectangle.getMaxLat(), rectangle.getMinLon(), rectangle.getMinAlt()); // top left
|
||||
writeCoordinate(rectangle.getMinLat(), rectangle.getMaxLon(), rectangle.getMaxAlt()); // bottom right
|
||||
writeCoordinate(rectangle.getMaxY(), rectangle.getMinX(), rectangle.getMinZ()); // top left
|
||||
writeCoordinate(rectangle.getMinY(), rectangle.getMaxX(), rectangle.getMaxZ()); // bottom right
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ public final class GeometryIO {
|
||||
private void writeCoordinates(Line line) throws IOException {
|
||||
out.writeVInt(line.length());
|
||||
for (int i = 0; i < line.length(); i++) {
|
||||
writeCoordinate(line.getLat(i), line.getLon(i), line.getAlt(i));
|
||||
writeCoordinate(line.getY(i), line.getX(i), line.getZ(i));
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,9 +224,9 @@ public final class GeometryIO {
|
||||
reverse(arr);
|
||||
}
|
||||
if (arr.length == 3) {
|
||||
return new LinearRing(arr[0], arr[1], arr[2]);
|
||||
return new LinearRing(arr[1], arr[0], arr[2]);
|
||||
} else {
|
||||
return new LinearRing(arr[0], arr[1]);
|
||||
return new LinearRing(arr[1], arr[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,15 +238,15 @@ public final class GeometryIO {
|
||||
double lon = in.readDouble();
|
||||
double lat = in.readDouble();
|
||||
double alt = readAlt(in);
|
||||
return new Point(lat, lon, alt);
|
||||
return new Point(lon, lat, alt);
|
||||
}
|
||||
|
||||
private static Line readLine(StreamInput in) throws IOException {
|
||||
double[][] coords = readLineComponents(in);
|
||||
if (coords.length == 3) {
|
||||
return new Line(coords[0], coords[1], coords[2]);
|
||||
return new Line(coords[1], coords[0], coords[2]);
|
||||
} else {
|
||||
return new Line(coords[0], coords[1]);
|
||||
return new Line(coords[1], coords[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,7 +266,7 @@ public final class GeometryIO {
|
||||
double lon = in.readDouble();
|
||||
double lat = in.readDouble();
|
||||
double alt = readAlt(in);
|
||||
points.add(new Point(lat, lon, alt));
|
||||
points.add(new Point(lon, lat, alt));
|
||||
}
|
||||
return new MultiPoint(points);
|
||||
}
|
||||
@ -293,7 +293,7 @@ public final class GeometryIO {
|
||||
double minLat = in.readDouble();
|
||||
double maxAlt = readAlt(in);
|
||||
|
||||
return new Rectangle(minLat, maxLat, minLon, maxLon, minAlt, maxAlt);
|
||||
return new Rectangle(minLon, maxLon, maxLat, minLat, minAlt, maxAlt);
|
||||
}
|
||||
|
||||
private static double readAlt(StreamInput in) throws IOException {
|
||||
|
@ -23,10 +23,10 @@ import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.GeometryValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.GeometryValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
|
@ -34,7 +34,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CircleBuilder extends ShapeBuilder<Circle, org.elasticsearch.geo.geometry.Circle, CircleBuilder> {
|
||||
public class CircleBuilder extends ShapeBuilder<Circle, org.elasticsearch.geometry.Circle, CircleBuilder> {
|
||||
|
||||
public static final ParseField FIELD_RADIUS = new ParseField("radius");
|
||||
public static final GeoShapeType TYPE = GeoShapeType.CIRCLE;
|
||||
@ -164,7 +164,7 @@ public class CircleBuilder extends ShapeBuilder<Circle, org.elasticsearch.geo.ge
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.elasticsearch.geo.geometry.Circle buildGeometry() {
|
||||
public org.elasticsearch.geometry.Circle buildGeometry() {
|
||||
throw new UnsupportedOperationException("CIRCLE geometry is not supported");
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class EnvelopeBuilder extends ShapeBuilder<Rectangle, org.elasticsearch.geo.geometry.Rectangle, EnvelopeBuilder> {
|
||||
public class EnvelopeBuilder extends ShapeBuilder<Rectangle, org.elasticsearch.geometry.Rectangle, EnvelopeBuilder> {
|
||||
|
||||
public static final GeoShapeType TYPE = GeoShapeType.ENVELOPE;
|
||||
|
||||
@ -113,8 +113,8 @@ public class EnvelopeBuilder extends ShapeBuilder<Rectangle, org.elasticsearch.g
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.elasticsearch.geo.geometry.Rectangle buildGeometry() {
|
||||
return new org.elasticsearch.geo.geometry.Rectangle(bottomRight.y, topLeft.y, topLeft.x, bottomRight.x);
|
||||
public org.elasticsearch.geometry.Rectangle buildGeometry() {
|
||||
return new org.elasticsearch.geometry.Rectangle(topLeft.x, bottomRight.x, topLeft.y, bottomRight.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,7 +27,8 @@ import org.elasticsearch.common.geo.parsers.ShapeParser;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.locationtech.spatial4j.shape.Shape;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -36,7 +37,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class GeometryCollectionBuilder extends ShapeBuilder<Shape,
|
||||
org.elasticsearch.geo.geometry.GeometryCollection<org.elasticsearch.geo.geometry.Geometry>, GeometryCollectionBuilder> {
|
||||
GeometryCollection<Geometry>, GeometryCollectionBuilder> {
|
||||
|
||||
public static final GeoShapeType TYPE = GeoShapeType.GEOMETRYCOLLECTION;
|
||||
|
||||
@ -186,17 +187,17 @@ public class GeometryCollectionBuilder extends ShapeBuilder<Shape,
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.elasticsearch.geo.geometry.GeometryCollection<org.elasticsearch.geo.geometry.Geometry> buildGeometry() {
|
||||
public GeometryCollection<Geometry> buildGeometry() {
|
||||
if (this.shapes.isEmpty()) {
|
||||
return GeometryCollection.EMPTY;
|
||||
}
|
||||
List<org.elasticsearch.geo.geometry.Geometry> shapes = new ArrayList<>(this.shapes.size());
|
||||
List<Geometry> shapes = new ArrayList<>(this.shapes.size());
|
||||
|
||||
for (ShapeBuilder shape : this.shapes) {
|
||||
shapes.add(shape.buildGeometry());
|
||||
}
|
||||
|
||||
return new org.elasticsearch.geo.geometry.GeometryCollection<>(shapes);
|
||||
return new GeometryCollection<>(shapes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,7 +23,7 @@ import org.elasticsearch.common.geo.GeoShapeType;
|
||||
import org.elasticsearch.common.geo.parsers.ShapeParser;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.GeometryFactory;
|
||||
@ -35,7 +35,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class LineStringBuilder extends ShapeBuilder<JtsGeometry, org.elasticsearch.geo.geometry.Geometry, LineStringBuilder> {
|
||||
public class LineStringBuilder extends ShapeBuilder<JtsGeometry, org.elasticsearch.geometry.Geometry, LineStringBuilder> {
|
||||
public static final GeoShapeType TYPE = GeoShapeType.LINESTRING;
|
||||
|
||||
/**
|
||||
@ -121,9 +121,9 @@ public class LineStringBuilder extends ShapeBuilder<JtsGeometry, org.elasticsear
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.elasticsearch.geo.geometry.Geometry buildGeometry() {
|
||||
return new Line(coordinates.stream().mapToDouble(i->i.y).toArray(),
|
||||
coordinates.stream().mapToDouble(i->i.x).toArray());
|
||||
public org.elasticsearch.geometry.Geometry buildGeometry() {
|
||||
return new Line(coordinates.stream().mapToDouble(i->i.x).toArray(), coordinates.stream().mapToDouble(i->i.y).toArray()
|
||||
);
|
||||
}
|
||||
|
||||
static ArrayList<LineString> decomposeS4J(GeometryFactory factory, Coordinate[] coordinates, ArrayList<LineString> strings) {
|
||||
|
@ -25,7 +25,8 @@ import org.elasticsearch.common.geo.parsers.ShapeParser;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.LineString;
|
||||
@ -37,7 +38,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MultiLineStringBuilder extends ShapeBuilder<JtsGeometry, org.elasticsearch.geo.geometry.Geometry, MultiLineStringBuilder> {
|
||||
public class MultiLineStringBuilder extends ShapeBuilder<JtsGeometry, org.elasticsearch.geometry.Geometry, MultiLineStringBuilder> {
|
||||
|
||||
public static final GeoShapeType TYPE = GeoShapeType.MULTILINESTRING;
|
||||
|
||||
@ -150,15 +151,16 @@ public class MultiLineStringBuilder extends ShapeBuilder<JtsGeometry, org.elasti
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.elasticsearch.geo.geometry.Geometry buildGeometry() {
|
||||
public org.elasticsearch.geometry.Geometry buildGeometry() {
|
||||
if (lines.isEmpty()) {
|
||||
return MultiLine.EMPTY;
|
||||
}
|
||||
List<org.elasticsearch.geo.geometry.Line> linestrings = new ArrayList<>(lines.size());
|
||||
List<Line> linestrings = new ArrayList<>(lines.size());
|
||||
for (int i = 0; i < lines.size(); ++i) {
|
||||
LineStringBuilder lsb = lines.get(i);
|
||||
linestrings.add(new org.elasticsearch.geo.geometry.Line(lsb.coordinates.stream().mapToDouble(c->c.y).toArray(),
|
||||
lsb.coordinates.stream().mapToDouble(c->c.x).toArray()));
|
||||
linestrings.add(new Line(lsb.coordinates.stream().mapToDouble(c->c.x).toArray(),
|
||||
lsb.coordinates.stream().mapToDouble(c->c.y).toArray()
|
||||
));
|
||||
}
|
||||
return new MultiLine(linestrings);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import org.elasticsearch.common.geo.XShapeCollection;
|
||||
import org.elasticsearch.common.geo.parsers.ShapeParser;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
import org.locationtech.spatial4j.shape.Point;
|
||||
|
||||
@ -87,7 +87,7 @@ public class MultiPointBuilder extends ShapeBuilder<XShapeCollection<Point>, Mul
|
||||
if (coordinates.isEmpty()) {
|
||||
return MultiPoint.EMPTY;
|
||||
}
|
||||
return new MultiPoint(coordinates.stream().map(coord -> new org.elasticsearch.geo.geometry.Point(coord.y, coord.x))
|
||||
return new MultiPoint(coordinates.stream().map(coord -> new org.elasticsearch.geometry.Point(coord.x, coord.y))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,8 @@ import org.elasticsearch.common.geo.parsers.ShapeParser;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
import org.locationtech.spatial4j.shape.Shape;
|
||||
|
||||
@ -188,14 +189,14 @@ public class MultiPolygonBuilder extends ShapeBuilder<Shape, MultiPolygon, Multi
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@Override
|
||||
public MultiPolygon buildGeometry() {
|
||||
List<org.elasticsearch.geo.geometry.Polygon> shapes = new ArrayList<>(this.polygons.size());
|
||||
List<Polygon> shapes = new ArrayList<>(this.polygons.size());
|
||||
Object poly;
|
||||
for (PolygonBuilder polygon : this.polygons) {
|
||||
poly = polygon.buildGeometry();
|
||||
if (poly instanceof List) {
|
||||
shapes.addAll((List<org.elasticsearch.geo.geometry.Polygon>) poly);
|
||||
shapes.addAll((List<Polygon>) poly);
|
||||
} else {
|
||||
shapes.add((org.elasticsearch.geo.geometry.Polygon)poly);
|
||||
shapes.add((Polygon)poly);
|
||||
}
|
||||
}
|
||||
if (shapes.isEmpty()) {
|
||||
|
@ -28,7 +28,7 @@ import org.locationtech.spatial4j.shape.Point;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PointBuilder extends ShapeBuilder<Point, org.elasticsearch.geo.geometry.Point, PointBuilder> {
|
||||
public class PointBuilder extends ShapeBuilder<Point, org.elasticsearch.geometry.Point, PointBuilder> {
|
||||
public static final GeoShapeType TYPE = GeoShapeType.POINT;
|
||||
|
||||
/**
|
||||
@ -88,8 +88,8 @@ public class PointBuilder extends ShapeBuilder<Point, org.elasticsearch.geo.geom
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.elasticsearch.geo.geometry.Point buildGeometry() {
|
||||
return new org.elasticsearch.geo.geometry.Point(coordinates.get(0).y, coordinates.get(0).x);
|
||||
public org.elasticsearch.geometry.Point buildGeometry() {
|
||||
return new org.elasticsearch.geometry.Point(coordinates.get(0).x, coordinates.get(0).y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,7 +53,7 @@ import static org.apache.lucene.geo.GeoUtils.orient;
|
||||
* Methods to wrap polygons at the dateline and building shapes from the data held by the
|
||||
* builder.
|
||||
*/
|
||||
public class PolygonBuilder extends ShapeBuilder<JtsGeometry, org.elasticsearch.geo.geometry.Geometry, PolygonBuilder> {
|
||||
public class PolygonBuilder extends ShapeBuilder<JtsGeometry, org.elasticsearch.geometry.Geometry, PolygonBuilder> {
|
||||
|
||||
public static final GeoShapeType TYPE = GeoShapeType.POLYGON;
|
||||
|
||||
@ -231,7 +231,7 @@ public class PolygonBuilder extends ShapeBuilder<JtsGeometry, org.elasticsearch.
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.elasticsearch.geo.geometry.Geometry buildGeometry() {
|
||||
public org.elasticsearch.geometry.Geometry buildGeometry() {
|
||||
return toPolygonGeometry();
|
||||
}
|
||||
|
||||
@ -280,17 +280,18 @@ public class PolygonBuilder extends ShapeBuilder<JtsGeometry, org.elasticsearch.
|
||||
return factory.createPolygon(shell, holes);
|
||||
}
|
||||
|
||||
public org.elasticsearch.geo.geometry.Polygon toPolygonGeometry() {
|
||||
final List<org.elasticsearch.geo.geometry.LinearRing> holes = new ArrayList<>(this.holes.size());
|
||||
public org.elasticsearch.geometry.Polygon toPolygonGeometry() {
|
||||
final List<org.elasticsearch.geometry.LinearRing> holes = new ArrayList<>(this.holes.size());
|
||||
for (int i = 0; i < this.holes.size(); ++i) {
|
||||
holes.add(linearRing(this.holes.get(i).coordinates));
|
||||
}
|
||||
return new org.elasticsearch.geo.geometry.Polygon(linearRing(this.shell.coordinates), holes);
|
||||
return new org.elasticsearch.geometry.Polygon(linearRing(this.shell.coordinates), holes);
|
||||
}
|
||||
|
||||
protected static org.elasticsearch.geo.geometry.LinearRing linearRing(List<Coordinate> coordinates) {
|
||||
return new org.elasticsearch.geo.geometry.LinearRing(coordinates.stream().mapToDouble(i -> i.y).toArray(),
|
||||
coordinates.stream().mapToDouble(i -> i.x).toArray());
|
||||
protected static org.elasticsearch.geometry.LinearRing linearRing(List<Coordinate> coordinates) {
|
||||
return new org.elasticsearch.geometry.LinearRing(coordinates.stream().mapToDouble(i -> i.x).toArray(),
|
||||
coordinates.stream().mapToDouble(i -> i.y).toArray()
|
||||
);
|
||||
}
|
||||
|
||||
protected static LinearRing linearRingS4J(GeometryFactory factory, List<Coordinate> coordinates) {
|
||||
|
@ -52,7 +52,7 @@ import java.util.Objects;
|
||||
/**
|
||||
* Basic class for building GeoJSON shapes like Polygons, Linestrings, etc
|
||||
*/
|
||||
public abstract class ShapeBuilder<T extends Shape, G extends org.elasticsearch.geo.geometry.Geometry,
|
||||
public abstract class ShapeBuilder<T extends Shape, G extends org.elasticsearch.geometry.Geometry,
|
||||
E extends ShapeBuilder<T, G, E>> implements NamedWriteable, ToXContentObject {
|
||||
|
||||
protected static final Logger LOGGER = LogManager.getLogger(ShapeBuilder.class);
|
||||
|
@ -26,7 +26,7 @@ import org.apache.lucene.util.BytesRefBuilder;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.geo.GeoUtils;
|
||||
import org.elasticsearch.common.time.DateUtils;
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.script.JodaCompatibleZonedDateTime;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -35,7 +35,7 @@ import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper.DeprecatedParameters;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.index.query.QueryShardException;
|
||||
|
@ -23,7 +23,7 @@ import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.geo.GeometryParser;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.index.query.VectorGeoShapeQueryProcessor;
|
||||
|
||||
/**
|
||||
|
@ -23,18 +23,18 @@ package org.elasticsearch.index.mapper;
|
||||
import org.apache.lucene.document.LatLonShape;
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Polygon;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.locationtech.spatial4j.exception.InvalidShapeException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -58,7 +58,7 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
|
||||
private static final double DATELINE = 180;
|
||||
|
||||
protected static final Comparator<Edge> INTERSECTION_ORDER = Comparator.comparingDouble(o -> o.intersect.getLat());
|
||||
protected static final Comparator<Edge> INTERSECTION_ORDER = Comparator.comparingDouble(o -> o.intersect.getY());
|
||||
|
||||
private final boolean orientation;
|
||||
|
||||
@ -161,7 +161,7 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
@Override
|
||||
public Geometry visit(Point point) {
|
||||
//TODO: Just remove altitude for now. We need to add normalization later
|
||||
return new Point(point.getLat(), point.getLon());
|
||||
return new Point(point.getX(), point.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -228,10 +228,10 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
double[] lats = new double[partMinus.length()];
|
||||
double[] lons = new double[partMinus.length()];
|
||||
for (int i = 0; i < partMinus.length(); i++) {
|
||||
lats[i] = normalizeLat(partMinus.getLat(i));
|
||||
lons[i] = normalizeLon(partMinus.getLon(i));
|
||||
lats[i] = normalizeLat(partMinus.getY(i));
|
||||
lons[i] = normalizeLon(partMinus.getX(i));
|
||||
}
|
||||
lines.add(new Line(lats, lons));
|
||||
lines.add(new Line(lons, lats));
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
@ -245,8 +245,8 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
* @return array of linestrings given as coordinate arrays
|
||||
*/
|
||||
private List<Line> decompose(double dateline, Line line) {
|
||||
double[] lons = line.getLons();
|
||||
double[] lats = line.getLats();
|
||||
double[] lons = line.getX();
|
||||
double[] lats = line.getY();
|
||||
return decompose(dateline, lons, lats);
|
||||
}
|
||||
|
||||
@ -267,12 +267,12 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
double[] partLons = Arrays.copyOfRange(lons, offset, i + 1);
|
||||
double[] partLats = Arrays.copyOfRange(lats, offset, i + 1);
|
||||
if (t < 1) {
|
||||
Point intersection = position(new Point(lats[i - 1], lons[i - 1]), new Point(lats[i], lons[i]), t);
|
||||
partLons[partLons.length - 1] = intersection.getLon();
|
||||
partLats[partLats.length - 1] = intersection.getLat();
|
||||
Point intersection = position(new Point(lons[i - 1], lats[i - 1]), new Point(lons[i], lats[i]), t);
|
||||
partLons[partLons.length - 1] = intersection.getX();
|
||||
partLats[partLats.length - 1] = intersection.getY();
|
||||
|
||||
lons[offset + i - 1] = intersection.getLon();
|
||||
lats[offset + i - 1] = intersection.getLat();
|
||||
lons[offset + i - 1] = intersection.getX();
|
||||
lats[offset + i - 1] = intersection.getY();
|
||||
|
||||
shift(shift, lons);
|
||||
offset = i - 1;
|
||||
@ -281,18 +281,18 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
shift(shift, partLons);
|
||||
offset = i;
|
||||
}
|
||||
parts.add(new Line(partLats, partLons));
|
||||
parts.add(new Line(partLons, partLats));
|
||||
}
|
||||
}
|
||||
|
||||
if (offset == 0) {
|
||||
shift(shift, lons);
|
||||
parts.add(new Line(lats, lons));
|
||||
parts.add(new Line(lons, lats));
|
||||
} else if (offset < lons.length - 1) {
|
||||
double[] partLons = Arrays.copyOfRange(lons, offset, lons.length);
|
||||
double[] partLats = Arrays.copyOfRange(lats, offset, lats.length);
|
||||
shift(shift, partLons);
|
||||
parts.add(new Line(partLats, partLons));
|
||||
parts.add(new Line(partLons, partLats));
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
@ -312,7 +312,7 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
if (dateline == 0) {
|
||||
return coordinate;
|
||||
} else {
|
||||
return new Point(coordinate.getLat(), -2 * dateline + coordinate.getLon());
|
||||
return new Point(-2 * dateline + coordinate.getX(), coordinate.getY());
|
||||
}
|
||||
}
|
||||
|
||||
@ -345,10 +345,10 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
Set<Point> exterior = new HashSet<>();
|
||||
Set<Point> interior = new HashSet<>();
|
||||
for (int i = 0; i < shell.length(); i++) {
|
||||
exterior.add(new Point(shell.getLat(i), shell.getLon(i)));
|
||||
exterior.add(new Point(shell.getX(i), shell.getY(i)));
|
||||
}
|
||||
for (int i = 0; i < hole.length(); i++) {
|
||||
interior.add(new Point(hole.getLat(i), hole.getLon(i)));
|
||||
interior.add(new Point(hole.getX(i), hole.getY(i)));
|
||||
}
|
||||
exterior.retainAll(interior);
|
||||
if (exterior.size() >= 2) {
|
||||
@ -414,9 +414,9 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
} else if (position == 1) {
|
||||
return p2;
|
||||
} else {
|
||||
final double x = p1.getLon() + position * (p2.getLon() - p1.getLon());
|
||||
final double y = p1.getLat() + position * (p2.getLat() - p1.getLat());
|
||||
return new Point(y, x);
|
||||
final double x = p1.getX() + position * (p2.getX() - p1.getX());
|
||||
final double y = p1.getY() + position * (p2.getY() - p1.getY());
|
||||
return new Point(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@ -434,7 +434,7 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
private Point[] points(LinearRing linearRing) {
|
||||
Point[] points = new Point[linearRing.length()];
|
||||
for (int i = 0; i < linearRing.length(); i++) {
|
||||
points[i] = new Point(linearRing.getLat(i), linearRing.getLon(i));
|
||||
points[i] = new Point(linearRing.getX(i), linearRing.getY(i));
|
||||
}
|
||||
return points;
|
||||
}
|
||||
@ -484,8 +484,8 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
*/
|
||||
private static void translate(Point[] points) {
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
if (points[i].getLon() < 0) {
|
||||
points[i] = new Point(points[i].getLat(), points[i].getLon() + 2 * DATELINE);
|
||||
if (points[i].getX() < 0) {
|
||||
points[i] = new Point(points[i].getX() + 2 * DATELINE, points[i].getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -502,14 +502,14 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
final int next = (top + 1) % length;
|
||||
|
||||
final int determinantSign = orient(
|
||||
points[offset + prev].getLon(), points[offset + prev].getLat(),
|
||||
points[offset + top].getLon(), points[offset + top].getLat(),
|
||||
points[offset + next].getLon(), points[offset + next].getLat());
|
||||
points[offset + prev].getX(), points[offset + prev].getY(),
|
||||
points[offset + top].getX(), points[offset + top].getY(),
|
||||
points[offset + next].getX(), points[offset + next].getY());
|
||||
|
||||
if (determinantSign == 0) {
|
||||
// Points are collinear, but `top` is not in the middle if so, so the edges either side of `top` are intersecting.
|
||||
throw new InvalidShapeException("Cannot determine orientation: edges adjacent to ("
|
||||
+ points[offset + top].getLon() + "," + points[offset + top].getLat() + ") coincide");
|
||||
+ points[offset + top].getX() + "," + points[offset + top].getY() + ") coincide");
|
||||
}
|
||||
|
||||
return determinantSign < 0;
|
||||
@ -522,10 +522,10 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
private static int top(Point[] points, int offset, int length) {
|
||||
int top = 0; // we start at 1 here since top points to 0
|
||||
for (int i = 1; i < length; i++) {
|
||||
if (points[offset + i].getLat() < points[offset + top].getLat()) {
|
||||
if (points[offset + i].getY() < points[offset + top].getY()) {
|
||||
top = i;
|
||||
} else if (points[offset + i].getLat() == points[offset + top].getLat()) {
|
||||
if (points[offset + i].getLon() < points[offset + top].getLon()) {
|
||||
} else if (points[offset + i].getY() == points[offset + top].getY()) {
|
||||
if (points[offset + i].getX() < points[offset + top].getX()) {
|
||||
top = i;
|
||||
}
|
||||
}
|
||||
@ -535,24 +535,24 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
|
||||
|
||||
private static double[] range(Point[] points, int offset, int length) {
|
||||
double minX = points[0].getLon();
|
||||
double minX = points[0].getX();
|
||||
double maxX = minX;
|
||||
double minY = points[0].getLat();
|
||||
double minY = points[0].getY();
|
||||
double maxY = minY;
|
||||
// compute the bounding coordinates (@todo: cleanup brute force)
|
||||
for (int i = 1; i < length; ++i) {
|
||||
Point point = points[offset + i];
|
||||
if (point.getLon() < minX) {
|
||||
minX = point.getLon();
|
||||
if (point.getX() < minX) {
|
||||
minX = point.getX();
|
||||
}
|
||||
if (point.getLon() > maxX) {
|
||||
maxX = point.getLon();
|
||||
if (point.getX() > maxX) {
|
||||
maxX = point.getX();
|
||||
}
|
||||
if (point.getLat() < minY) {
|
||||
minY = point.getLat();
|
||||
if (point.getY() < minY) {
|
||||
minY = point.getY();
|
||||
}
|
||||
if (point.getLat() > maxY) {
|
||||
maxY = point.getLat();
|
||||
if (point.getY() > maxY) {
|
||||
maxY = point.getY();
|
||||
}
|
||||
}
|
||||
return new double[]{minX, maxX, minY, maxY};
|
||||
@ -592,8 +592,8 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
// ShapeBuilder.intersection that computes dateline edges as valid intersect points
|
||||
// in support of OGC standards
|
||||
if (e1.intersect != Edge.MAX_COORDINATE && e2.intersect != Edge.MAX_COORDINATE
|
||||
&& !(e1.next.next.coordinate.equals(e2.coordinate) && Math.abs(e1.next.coordinate.getLon()) == DATELINE
|
||||
&& Math.abs(e2.coordinate.getLon()) == DATELINE)) {
|
||||
&& !(e1.next.next.coordinate.equals(e2.coordinate) && Math.abs(e1.next.coordinate.getX()) == DATELINE
|
||||
&& Math.abs(e2.coordinate.getX()) == DATELINE)) {
|
||||
connect(e1, e2);
|
||||
}
|
||||
}
|
||||
@ -653,9 +653,9 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
final int edgeOffset, int length) {
|
||||
assert edges.length >= length + edgeOffset;
|
||||
assert points.length >= length + pointOffset;
|
||||
edges[edgeOffset] = new Edge(new Point(points[pointOffset].getLat(), points[pointOffset].getLon()), null);
|
||||
edges[edgeOffset] = new Edge(new Point(points[pointOffset].getX(), points[pointOffset].getY()), null);
|
||||
for (int i = 1; i < length; i++) {
|
||||
Point nextPoint = new Point(points[pointOffset + i].getLat(), points[pointOffset + i].getLon());
|
||||
Point nextPoint = new Point(points[pointOffset + i].getX(), points[pointOffset + i].getY());
|
||||
if (direction) {
|
||||
edges[edgeOffset + i] = new Edge(nextPoint, edges[edgeOffset + i - 1]);
|
||||
edges[edgeOffset + i].component = component;
|
||||
@ -693,10 +693,10 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
for (int i = 0; i < edges.length; i++) {
|
||||
Point p1 = edges[i].coordinate;
|
||||
Point p2 = edges[i].next.coordinate;
|
||||
assert !Double.isNaN(p2.getLon()) && !Double.isNaN(p1.getLon());
|
||||
assert !Double.isNaN(p2.getX()) && !Double.isNaN(p1.getX());
|
||||
edges[i].intersect = Edge.MAX_COORDINATE;
|
||||
|
||||
double position = intersection(p1.getLon(), p2.getLon(), dateline);
|
||||
double position = intersection(p1.getX(), p2.getX(), dateline);
|
||||
if (!Double.isNaN(position)) {
|
||||
edges[i].intersection(position);
|
||||
numIntersections++;
|
||||
@ -747,7 +747,7 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
// here.
|
||||
final Edge current = new Edge(holes[i].coordinate, holes[i].next);
|
||||
current.intersect = current.coordinate;
|
||||
final int intersections = intersections(current.coordinate.getLon(), edges);
|
||||
final int intersections = intersections(current.coordinate.getX(), edges);
|
||||
|
||||
if (intersections == 0) {
|
||||
// There were no edges that intersect the line of longitude through
|
||||
@ -804,13 +804,13 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
private static int component(final Edge edge, final int id, final ArrayList<Edge> edges, double[] partitionPoint) {
|
||||
// find a coordinate that is not part of the dateline
|
||||
Edge any = edge;
|
||||
while (any.coordinate.getLon() == +DATELINE || any.coordinate.getLon() == -DATELINE) {
|
||||
while (any.coordinate.getX() == +DATELINE || any.coordinate.getX() == -DATELINE) {
|
||||
if ((any = any.next) == edge) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
double shiftOffset = any.coordinate.getLon() > DATELINE ? DATELINE : (any.coordinate.getLon() < -DATELINE ? -DATELINE : 0);
|
||||
double shiftOffset = any.coordinate.getX() > DATELINE ? DATELINE : (any.coordinate.getX() < -DATELINE ? -DATELINE : 0);
|
||||
|
||||
// run along the border of the component, collect the
|
||||
// edges, shift them according to the dateline and
|
||||
@ -830,8 +830,8 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
if (edges != null) {
|
||||
// found a closed loop - we have two connected components so we need to slice into two distinct components
|
||||
if (visitedEdge.containsKey(current.coordinate)) {
|
||||
partitionPoint[0] = current.coordinate.getLon();
|
||||
partitionPoint[1] = current.coordinate.getLat();
|
||||
partitionPoint[0] = current.coordinate.getX();
|
||||
partitionPoint[1] = current.coordinate.getY();
|
||||
if (connectedComponents > 0 && current.next != edge) {
|
||||
throw new InvalidShapeException("Shape contains more than one shared point");
|
||||
}
|
||||
@ -912,10 +912,10 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
double[] x = new double[coords.length];
|
||||
double[] y = new double[coords.length];
|
||||
for (int c = 0; c < coords.length; ++c) {
|
||||
x[c] = normalizeLon(coords[c].getLon());
|
||||
y[c] = normalizeLat(coords[c].getLat());
|
||||
x[c] = normalizeLon(coords[c].getX());
|
||||
y[c] = normalizeLat(coords[c].getY());
|
||||
}
|
||||
holes.add(new LinearRing(y, x));
|
||||
holes.add(new LinearRing(x, y));
|
||||
}
|
||||
} else {
|
||||
holes = Collections.emptyList();
|
||||
@ -926,11 +926,11 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
for (int i = 0; i < shell.length; ++i) {
|
||||
//Lucene Tessellator treats different +180 and -180 and we should keep the sign.
|
||||
//normalizeLon method excludes -180.
|
||||
x[i] = Math.abs(shell[i].getLon()) > 180 ? normalizeLon(shell[i].getLon()) : shell[i].getLon();
|
||||
y[i] = normalizeLat(shell[i].getLat());
|
||||
x[i] = Math.abs(shell[i].getX()) > 180 ? normalizeLon(shell[i].getX()) : shell[i].getX();
|
||||
y[i] = normalizeLat(shell[i].getY());
|
||||
}
|
||||
|
||||
return new Polygon(new LinearRing(y, x), holes);
|
||||
return new Polygon(new LinearRing(x, y), holes);
|
||||
}
|
||||
|
||||
private static Point[][] holes(Edge[] holes, int numHoles) {
|
||||
@ -975,8 +975,8 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(org.elasticsearch.geo.geometry.Line line) {
|
||||
addFields(LatLonShape.createIndexableFields(name, new org.apache.lucene.geo.Line(line.getLats(), line.getLons())));
|
||||
public Void visit(Line line) {
|
||||
addFields(LatLonShape.createIndexableFields(name, new org.apache.lucene.geo.Line(line.getY(), line.getX())));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -987,7 +987,7 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
|
||||
@Override
|
||||
public Void visit(MultiLine multiLine) {
|
||||
for (org.elasticsearch.geo.geometry.Line line : multiLine) {
|
||||
for (Line line : multiLine) {
|
||||
visit(line);
|
||||
}
|
||||
return null;
|
||||
@ -1003,7 +1003,7 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
|
||||
@Override
|
||||
public Void visit(MultiPolygon multiPolygon) {
|
||||
for(org.elasticsearch.geo.geometry.Polygon polygon : multiPolygon) {
|
||||
for(Polygon polygon : multiPolygon) {
|
||||
visit(polygon);
|
||||
}
|
||||
return null;
|
||||
@ -1011,21 +1011,21 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
|
||||
@Override
|
||||
public Void visit(Point point) {
|
||||
addFields(LatLonShape.createIndexableFields(name, point.getLat(), point.getLon()));
|
||||
addFields(LatLonShape.createIndexableFields(name, point.getY(), point.getX()));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(org.elasticsearch.geo.geometry.Polygon polygon) {
|
||||
public Void visit(Polygon polygon) {
|
||||
addFields(LatLonShape.createIndexableFields(name, toLucenePolygon(polygon)));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(org.elasticsearch.geo.geometry.Rectangle r) {
|
||||
public Void visit(Rectangle r) {
|
||||
org.apache.lucene.geo.Polygon p = new org.apache.lucene.geo.Polygon(
|
||||
new double[]{r.getMinLat(), r.getMinLat(), r.getMaxLat(), r.getMaxLat(), r.getMinLat()},
|
||||
new double[]{r.getMinLon(), r.getMaxLon(), r.getMaxLon(), r.getMinLon(), r.getMinLon()});
|
||||
new double[]{r.getMinY(), r.getMinY(), r.getMaxY(), r.getMaxY(), r.getMinY()},
|
||||
new double[]{r.getMinX(), r.getMaxX(), r.getMaxX(), r.getMinX(), r.getMinX()});
|
||||
addFields(LatLonShape.createIndexableFields(name, p));
|
||||
return null;
|
||||
}
|
||||
@ -1036,11 +1036,11 @@ public final class GeoShapeIndexer implements AbstractGeometryFieldMapper.Indexe
|
||||
}
|
||||
|
||||
|
||||
public static org.apache.lucene.geo.Polygon toLucenePolygon(org.elasticsearch.geo.geometry.Polygon polygon) {
|
||||
public static org.apache.lucene.geo.Polygon toLucenePolygon(Polygon polygon) {
|
||||
org.apache.lucene.geo.Polygon[] holes = new org.apache.lucene.geo.Polygon[polygon.getNumberOfHoles()];
|
||||
for(int i = 0; i<holes.length; i++) {
|
||||
holes[i] = new org.apache.lucene.geo.Polygon(polygon.getHole(i).getLats(), polygon.getHole(i).getLons());
|
||||
holes[i] = new org.apache.lucene.geo.Polygon(polygon.getHole(i).getY(), polygon.getHole(i).getX());
|
||||
}
|
||||
return new org.apache.lucene.geo.Polygon(polygon.getPolygon().getLats(), polygon.getPolygon().getLons(), holes);
|
||||
return new org.apache.lucene.geo.Polygon(polygon.getPolygon().getY(), polygon.getPolygon().getX(), holes);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -38,8 +38,8 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
|
||||
@ -183,7 +183,7 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
||||
public GeoBoundingBoxQueryBuilder setCorners(final String geohash) {
|
||||
// get the bounding box of the geohash and set topLeft and bottomRight
|
||||
Rectangle ghBBox = Geohash.toBoundingBox(geohash);
|
||||
return setCorners(new GeoPoint(ghBBox.getMaxLat(), ghBBox.getMinLon()), new GeoPoint(ghBBox.getMinLat(), ghBBox.getMaxLon()));
|
||||
return setCorners(new GeoPoint(ghBBox.getMaxY(), ghBBox.getMinX()), new GeoPoint(ghBBox.getMinY(), ghBBox.getMaxX()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
|
||||
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
|
@ -37,16 +37,18 @@ import org.elasticsearch.common.geo.builders.MultiPolygonBuilder;
|
||||
import org.elasticsearch.common.geo.builders.PointBuilder;
|
||||
import org.elasticsearch.common.geo.builders.PolygonBuilder;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
|
||||
import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
@ -134,10 +136,10 @@ public class LegacyGeoShapeQueryProcessor implements AbstractGeometryFieldMapper
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShapeBuilder<?, ?, ?> visit(org.elasticsearch.geo.geometry.Line line) {
|
||||
public ShapeBuilder<?, ?, ?> visit(Line line) {
|
||||
List<Coordinate> coordinates = new ArrayList<>();
|
||||
for (int i = 0; i < line.length(); i++) {
|
||||
coordinates.add(new Coordinate(line.getLon(i), line.getLat(i), line.getAlt(i)));
|
||||
coordinates.add(new Coordinate(line.getX(i), line.getY(i), line.getZ(i)));
|
||||
}
|
||||
return new LineStringBuilder(coordinates);
|
||||
}
|
||||
@ -161,7 +163,7 @@ public class LegacyGeoShapeQueryProcessor implements AbstractGeometryFieldMapper
|
||||
List<Coordinate> coordinates = new ArrayList<>();
|
||||
for (int i = 0; i < multiPoint.size(); i++) {
|
||||
Point p = multiPoint.get(i);
|
||||
coordinates.add(new Coordinate(p.getLon(), p.getLat(), p.getAlt()));
|
||||
coordinates.add(new Coordinate(p.getX(), p.getY(), p.getZ()));
|
||||
}
|
||||
return new MultiPointBuilder(coordinates);
|
||||
}
|
||||
@ -177,24 +179,24 @@ public class LegacyGeoShapeQueryProcessor implements AbstractGeometryFieldMapper
|
||||
|
||||
@Override
|
||||
public ShapeBuilder<?, ?, ?> visit(Point point) {
|
||||
return new PointBuilder(point.getLon(), point.getLat());
|
||||
return new PointBuilder(point.getX(), point.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShapeBuilder<?, ?, ?> visit(org.elasticsearch.geo.geometry.Polygon polygon) {
|
||||
public ShapeBuilder<?, ?, ?> visit(Polygon polygon) {
|
||||
PolygonBuilder polygonBuilder =
|
||||
new PolygonBuilder((LineStringBuilder) visit((org.elasticsearch.geo.geometry.Line) polygon.getPolygon()),
|
||||
new PolygonBuilder((LineStringBuilder) visit((Line) polygon.getPolygon()),
|
||||
ShapeBuilder.Orientation.RIGHT, false);
|
||||
for (int i = 0; i < polygon.getNumberOfHoles(); i++) {
|
||||
polygonBuilder.hole((LineStringBuilder) visit((org.elasticsearch.geo.geometry.Line) polygon.getHole(i)));
|
||||
polygonBuilder.hole((LineStringBuilder) visit((Line) polygon.getHole(i)));
|
||||
}
|
||||
return polygonBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShapeBuilder<?, ?, ?> visit(Rectangle rectangle) {
|
||||
return new EnvelopeBuilder(new Coordinate(rectangle.getMinLon(), rectangle.getMaxLat()),
|
||||
new Coordinate(rectangle.getMaxLon(), rectangle.getMinLat()));
|
||||
return new EnvelopeBuilder(new Coordinate(rectangle.getMinX(), rectangle.getMaxY()),
|
||||
new Coordinate(rectangle.getMaxX(), rectangle.getMinY()));
|
||||
}
|
||||
});
|
||||
return shapeBuilder;
|
||||
|
@ -24,7 +24,7 @@ import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.geo.ShapeRelation;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item;
|
||||
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
||||
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder;
|
||||
|
@ -28,15 +28,16 @@ import org.apache.lucene.search.MatchNoDocsQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.common.geo.GeoShapeType;
|
||||
import org.elasticsearch.common.geo.ShapeRelation;
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
|
||||
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
|
||||
import org.elasticsearch.index.mapper.GeoShapeIndexer;
|
||||
@ -105,9 +106,9 @@ public class VectorGeoShapeQueryProcessor implements AbstractGeometryFieldMapper
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query visit(org.elasticsearch.geo.geometry.Line line) {
|
||||
public Query visit(org.elasticsearch.geometry.Line line) {
|
||||
validateIsGeoShapeFieldType();
|
||||
return LatLonShape.newLineQuery(fieldName, relation.getLuceneRelation(), new Line(line.getLats(), line.getLons()));
|
||||
return LatLonShape.newLineQuery(fieldName, relation.getLuceneRelation(), new Line(line.getY(), line.getX()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -120,7 +121,7 @@ public class VectorGeoShapeQueryProcessor implements AbstractGeometryFieldMapper
|
||||
validateIsGeoShapeFieldType();
|
||||
Line[] lines = new Line[multiLine.size()];
|
||||
for (int i = 0; i < multiLine.size(); i++) {
|
||||
lines[i] = new Line(multiLine.get(i).getLats(), multiLine.get(i).getLons());
|
||||
lines[i] = new Line(multiLine.get(i).getY(), multiLine.get(i).getX());
|
||||
}
|
||||
return LatLonShape.newLineQuery(fieldName, relation.getLuceneRelation(), lines);
|
||||
}
|
||||
@ -144,18 +145,18 @@ public class VectorGeoShapeQueryProcessor implements AbstractGeometryFieldMapper
|
||||
public Query visit(Point point) {
|
||||
validateIsGeoShapeFieldType();
|
||||
return LatLonShape.newBoxQuery(fieldName, relation.getLuceneRelation(),
|
||||
point.getLat(), point.getLat(), point.getLon(), point.getLon());
|
||||
point.getY(), point.getY(), point.getX(), point.getX());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query visit(org.elasticsearch.geo.geometry.Polygon polygon) {
|
||||
public Query visit(org.elasticsearch.geometry.Polygon polygon) {
|
||||
return LatLonShape.newPolygonQuery(fieldName, relation.getLuceneRelation(), toLucenePolygon(polygon));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query visit(org.elasticsearch.geo.geometry.Rectangle r) {
|
||||
public Query visit(Rectangle r) {
|
||||
return LatLonShape.newBoxQuery(fieldName, relation.getLuceneRelation(),
|
||||
r.getMinLat(), r.getMaxLat(), r.getMinLon(), r.getMaxLon());
|
||||
r.getMinY(), r.getMaxY(), r.getMinX(), r.getMaxX());
|
||||
}
|
||||
|
||||
private void validateIsGeoShapeFieldType() {
|
||||
|
@ -30,7 +30,7 @@ import org.elasticsearch.common.network.NetworkAddress;
|
||||
import org.elasticsearch.common.time.DateFormatter;
|
||||
import org.elasticsearch.common.time.DateMathParser;
|
||||
import org.elasticsearch.common.time.DateUtils;
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.index.mapper.DateFieldMapper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.elasticsearch.search.aggregations.bucket.geogrid;
|
||||
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.search.aggregations.Aggregator;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
|
@ -20,7 +20,7 @@ package org.elasticsearch.search.aggregations.bucket.geogrid;
|
||||
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.search.aggregations.InternalAggregations;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -50,8 +50,8 @@ import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.elasticsearch.geo.utils.Geohash.addNeighbors;
|
||||
import static org.elasticsearch.geo.utils.Geohash.stringEncode;
|
||||
import static org.elasticsearch.geometry.utils.Geohash.addNeighbors;
|
||||
import static org.elasticsearch.geometry.utils.Geohash.stringEncode;
|
||||
|
||||
/**
|
||||
* A {@link ContextMapping} that uses a geo location/area as a
|
||||
|
@ -21,7 +21,7 @@ package org.elasticsearch.common.geo;
|
||||
import org.elasticsearch.common.geo.parsers.ShapeParser;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.index.mapper.GeoShapeIndexer;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions;
|
||||
@ -66,14 +66,14 @@ abstract class BaseGeoParsingTestCase extends ESTestCase {
|
||||
ElasticsearchGeoAssertions.assertEquals(expected, ShapeParser.parse(parser).buildS4J());
|
||||
} else {
|
||||
GeometryParser geometryParser = new GeometryParser(true, true, true);
|
||||
org.elasticsearch.geo.geometry.Geometry shape = geometryParser.parse(parser);
|
||||
org.elasticsearch.geometry.Geometry shape = geometryParser.parse(parser);
|
||||
shape = new GeoShapeIndexer(true, "name").prepareForIndexing(shape);
|
||||
ElasticsearchGeoAssertions.assertEquals(expected, shape);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertGeometryEquals(org.elasticsearch.geo.geometry.Geometry expected, XContentBuilder geoJson) throws IOException {
|
||||
protected void assertGeometryEquals(org.elasticsearch.geometry.Geometry expected, XContentBuilder geoJson) throws IOException {
|
||||
try (XContentParser parser = createParser(geoJson)) {
|
||||
parser.nextToken();
|
||||
assertEquals(expected, new GeoJson(true, false, new GeographyValidator(false)).fromXContent(parser));
|
||||
|
@ -25,18 +25,18 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParseException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Polygon;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
@ -56,7 +56,7 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.field("type", "Point")
|
||||
.startArray("coordinates").value(100.0).value(0.0).endArray()
|
||||
.endObject();
|
||||
Point expected = new Point(0.0, 100.0);
|
||||
Point expected = new Point(100.0, 0.0);
|
||||
assertGeometryEquals(expected, pointGeoJson);
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.endArray()
|
||||
.endObject();
|
||||
|
||||
Line expected = new Line(new double[] {0.0, 1.0}, new double[] { 100.0, 101.0});
|
||||
Line expected = new Line(new double[] { 100.0, 101.0}, new double[] {0.0, 1.0});
|
||||
try (XContentParser parser = createParser(lineGeoJson)) {
|
||||
parser.nextToken();
|
||||
assertEquals(expected, new GeoJson(false, false, new GeographyValidator(true)).fromXContent(parser));
|
||||
@ -96,8 +96,8 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.endObject();
|
||||
|
||||
MultiLine expected = new MultiLine(Arrays.asList(
|
||||
new Line(new double[] {0.0, 1.0}, new double[] { 100.0, 101.0}),
|
||||
new Line(new double[] {2.0, 3.0}, new double[] { 102.0, 103.0})
|
||||
new Line(new double[] { 100.0, 101.0}, new double[] {0.0, 1.0}),
|
||||
new Line(new double[] { 102.0, 103.0}, new double[] {2.0, 3.0})
|
||||
|
||||
));
|
||||
|
||||
@ -112,7 +112,7 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.field("radius", "200m")
|
||||
.endObject();
|
||||
|
||||
Circle expected = new Circle(0.0, 100.0, 200);
|
||||
Circle expected = new Circle(100.0, 0.0, 200);
|
||||
assertGeometryEquals(expected, multilinesGeoJson);
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.startArray().value(50).value(-30).endArray()
|
||||
.endArray()
|
||||
.endObject();
|
||||
Rectangle expected = new Rectangle(-30, 30, -50, 50);
|
||||
Rectangle expected = new Rectangle(-50, 50, 30, -30);
|
||||
assertGeometryEquals(expected, multilinesGeoJson);
|
||||
|
||||
// test #2: envelope that spans dateline
|
||||
@ -167,7 +167,7 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.endArray()
|
||||
.endObject();
|
||||
|
||||
expected = new Rectangle(-30, 30, 50, -50);
|
||||
expected = new Rectangle(50, -50, 30, -30);
|
||||
assertGeometryEquals(expected, multilinesGeoJson);
|
||||
|
||||
// test #3: "envelope" (actually a triangle) with invalid number of coordinates (TopRight, BottomLeft, BottomRight)
|
||||
@ -214,8 +214,8 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
|
||||
Polygon p = new Polygon(
|
||||
new LinearRing(
|
||||
new double[] {1d, 1d, 0d, 0d, 1d},
|
||||
new double[] {100d, 101d, 101d, 100d, 100d}));
|
||||
new double[] {100d, 101d, 101d, 100d, 100d}, new double[] {1d, 1d, 0d, 0d, 1d}
|
||||
));
|
||||
assertGeometryEquals(p, polygonGeoJson);
|
||||
}
|
||||
|
||||
@ -235,8 +235,7 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.endObject();
|
||||
|
||||
Polygon expected = new Polygon(new LinearRing(
|
||||
new double[]{1.0, 1.0, 0.0, 0.0, 1.0},
|
||||
new double[]{100.0, 101.0, 101.0, 100.0, 100.0},
|
||||
new double[]{100.0, 101.0, 101.0, 100.0, 100.0}, new double[]{1.0, 1.0, 0.0, 0.0, 1.0},
|
||||
new double[]{10.0, 10.0, 10.0, 10.0, 10.0}
|
||||
));
|
||||
try (XContentParser parser = createParser(polygonGeoJson)) {
|
||||
@ -504,10 +503,10 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
|
||||
LinearRing hole =
|
||||
new LinearRing(
|
||||
new double[] {0.8d, 0.2d, 0.2d, 0.8d, 0.8d}, new double[] {100.2d, 100.2d, 100.8d, 100.8d, 100.2d});
|
||||
new double[] {100.2d, 100.2d, 100.8d, 100.8d, 100.2d}, new double[] {0.8d, 0.2d, 0.2d, 0.8d, 0.8d});
|
||||
Polygon p =
|
||||
new Polygon(new LinearRing(
|
||||
new double[] {1d, 1d, 0d, 0d, 1d}, new double[] {100d, 101d, 101d, 100d, 100d}), Collections.singletonList(hole));
|
||||
new double[] {100d, 101d, 101d, 100d, 100d}, new double[] {1d, 1d, 0d, 0d, 1d}), Collections.singletonList(hole));
|
||||
assertGeometryEquals(p, polygonGeoJson);
|
||||
}
|
||||
|
||||
@ -523,8 +522,8 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.endObject();
|
||||
|
||||
assertGeometryEquals(new MultiPoint(Arrays.asList(
|
||||
new Point(0, 100),
|
||||
new Point(1, 101))), multiPointGeoJson);
|
||||
new Point(100, 0),
|
||||
new Point(101, 1))), multiPointGeoJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -563,13 +562,13 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.endObject();
|
||||
|
||||
LinearRing hole = new LinearRing(
|
||||
new double[] {0.8d, 0.2d, 0.2d, 0.8d, 0.8d}, new double[] {100.2d, 100.2d, 100.8d, 100.8d, 100.2d});
|
||||
new double[] {100.2d, 100.2d, 100.8d, 100.8d, 100.2d}, new double[] {0.8d, 0.2d, 0.2d, 0.8d, 0.8d});
|
||||
|
||||
MultiPolygon polygons = new MultiPolygon(Arrays.asList(
|
||||
new Polygon(new LinearRing(
|
||||
new double[] {2d, 2d, 3d, 3d, 2d}, new double[] {102d, 103d, 103d, 102d, 102d})),
|
||||
new double[] {102d, 103d, 103d, 102d, 102d}, new double[] {2d, 2d, 3d, 3d, 2d})),
|
||||
new Polygon(new LinearRing(
|
||||
new double[] {0d, 0d, 1d, 1d, 0d}, new double[] {100d, 101d, 101d, 100d, 100d}),
|
||||
new double[] {100d, 101d, 101d, 100d, 100d}, new double[] {0d, 0d, 1d, 1d, 0d}),
|
||||
Collections.singletonList(hole))));
|
||||
|
||||
assertGeometryEquals(polygons, multiPolygonGeoJson);
|
||||
@ -609,11 +608,10 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.endObject();
|
||||
|
||||
GeometryCollection<Geometry> geometryExpected = new GeometryCollection<> (Arrays.asList(
|
||||
new Line(new double[] {0d, 1d}, new double[] {100d, 101d}),
|
||||
new Point(2d, 102d),
|
||||
new Line(new double[] {100d, 101d}, new double[] {0d, 1d}),
|
||||
new Point(102d, 2d),
|
||||
new Polygon(new LinearRing(
|
||||
new double[] {10, 15, 0, -15, -10, 10},
|
||||
new double[] {-177, 176, 172, 176, -177, -177}
|
||||
new double[] {-177, 176, 172, 176, -177, -177}, new double[] {10, 15, 0, -15, -10, 10}
|
||||
))
|
||||
));
|
||||
assertGeometryEquals(geometryExpected, geometryCollectionGeoJson);
|
||||
@ -636,7 +634,7 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.startObject("lala").field("type", "NotAPoint").endObject()
|
||||
.endObject();
|
||||
|
||||
Point expectedPt = new Point(0, 100);
|
||||
Point expectedPt = new Point(100, 0);
|
||||
assertGeometryEquals(expectedPt, pointGeoJson, false);
|
||||
}
|
||||
|
||||
@ -665,9 +663,9 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.endObject();
|
||||
|
||||
Polygon expected = new Polygon(
|
||||
new LinearRing(new double[]{15.0, 10.0, -10.0, -15.0, 0.0, 15.0}, new double[]{176.0, -177.0, -177.0, 176.0, 172.0, 176.0}),
|
||||
new LinearRing(new double[]{176.0, -177.0, -177.0, 176.0, 172.0, 176.0}, new double[]{15.0, 10.0, -10.0, -15.0, 0.0, 15.0}),
|
||||
Collections.singletonList(
|
||||
new LinearRing(new double[]{8.0, 10.0, -8.0, 8.0}, new double[]{-172.0, 174.0, -172.0, -172.0})
|
||||
new LinearRing(new double[]{-172.0, 174.0, -172.0, -172.0}, new double[]{8.0, 10.0, -8.0, 8.0})
|
||||
));
|
||||
assertGeometryEquals(expected, polygonGeoJson);
|
||||
|
||||
@ -695,9 +693,9 @@ public class GeoJsonParserTests extends BaseGeoParsingTestCase {
|
||||
.endObject();
|
||||
|
||||
expected = new Polygon(
|
||||
new LinearRing(new double[]{15.0, 0.0, -15.0, -10.0, 10.0, 15.0}, new double[]{176.0, 172.0, 176.0, -177.0, -177.0, 176.0}),
|
||||
new LinearRing(new double[]{176.0, 172.0, 176.0, -177.0, -177.0, 176.0}, new double[]{15.0, 0.0, -15.0, -10.0, 10.0, 15.0}),
|
||||
Collections.singletonList(
|
||||
new LinearRing(new double[]{8.0, -8.0, 10.0, 8.0}, new double[]{-172.0, -172.0, 174.0, -172.0})
|
||||
new LinearRing(new double[]{-172.0, -172.0, 174.0, -172.0}, new double[]{8.0, -8.0, 10.0, 8.0})
|
||||
));
|
||||
assertGeometryEquals(expected, polygonGeoJson);
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.GeometryTestUtils;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.utils.GeographyValidator;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.utils.GeographyValidator;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
|
@ -30,10 +30,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.index.mapper.ContentPath;
|
||||
import org.elasticsearch.index.mapper.GeoShapeIndexer;
|
||||
import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper;
|
||||
@ -78,7 +79,7 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
.endObject();
|
||||
Point expected = GEOMETRY_FACTORY.createPoint(new Coordinate(100.0, 0.0));
|
||||
assertGeometryEquals(new JtsPoint(expected, SPATIAL_CONTEXT), pointGeoJson, true);
|
||||
assertGeometryEquals(new org.elasticsearch.geo.geometry.Point(0d, 100d), pointGeoJson, false);
|
||||
assertGeometryEquals(new org.elasticsearch.geometry.Point(100d, 0d), pointGeoJson, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -137,8 +138,8 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
});
|
||||
assertGeometryEquals(jtsGeom(expected), multilinesGeoJson, true);
|
||||
assertGeometryEquals(new MultiLine(Arrays.asList(
|
||||
new org.elasticsearch.geo.geometry.Line(new double[] {0d, 1d}, new double[] {100d, 101d}),
|
||||
new org.elasticsearch.geo.geometry.Line(new double[] {2d, 3d}, new double[] {102d, 103d}))),
|
||||
new Line(new double[] {100d, 101d}, new double[] {0d, 1d}),
|
||||
new Line(new double[] {102d, 103d}, new double[] {2d, 3d}))),
|
||||
multilinesGeoJson, false);
|
||||
}
|
||||
|
||||
@ -194,7 +195,7 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
.endObject();
|
||||
Rectangle expected = SPATIAL_CONTEXT.makeRectangle(-50, 50, -30, 30);
|
||||
assertGeometryEquals(expected, multilinesGeoJson, true);
|
||||
assertGeometryEquals(new org.elasticsearch.geo.geometry.Rectangle(-30, 30, -50, 50),
|
||||
assertGeometryEquals(new org.elasticsearch.geometry.Rectangle(-50, 50, 30, -30),
|
||||
multilinesGeoJson, false);
|
||||
|
||||
// test #2: envelope that spans dateline
|
||||
@ -207,7 +208,7 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
|
||||
expected = SPATIAL_CONTEXT.makeRectangle(50, -50, -30, 30);
|
||||
assertGeometryEquals(expected, multilinesGeoJson, true);
|
||||
assertGeometryEquals(new org.elasticsearch.geo.geometry.Rectangle(-30, 30, 50, -50),
|
||||
assertGeometryEquals(new org.elasticsearch.geometry.Rectangle(50, -50, 30, -30),
|
||||
multilinesGeoJson, false);
|
||||
|
||||
// test #3: "envelope" (actually a triangle) with invalid number of coordinates (TopRight, BottomLeft, BottomRight)
|
||||
@ -263,10 +264,10 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
Polygon expected = GEOMETRY_FACTORY.createPolygon(shell, null);
|
||||
assertGeometryEquals(jtsGeom(expected), polygonGeoJson, true);
|
||||
|
||||
org.elasticsearch.geo.geometry.Polygon p = new org.elasticsearch.geo.geometry.Polygon(
|
||||
new org.elasticsearch.geo.geometry.LinearRing(
|
||||
new double[] {0d, 0d, 1d, 1d, 0d},
|
||||
new double[] {100d, 101d, 101d, 100d, 100d}));
|
||||
org.elasticsearch.geometry.Polygon p = new org.elasticsearch.geometry.Polygon(
|
||||
new org.elasticsearch.geometry.LinearRing(
|
||||
new double[] {100d, 101d, 101d, 100d, 100d}, new double[] {0d, 0d, 1d, 1d, 0d}
|
||||
));
|
||||
assertGeometryEquals(p, polygonGeoJson, false);
|
||||
}
|
||||
|
||||
@ -310,9 +311,8 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
ElasticsearchGeoAssertions.assertEquals(jtsGeom(expected), ShapeParser.parse(parser, mapperBuilder).buildS4J());
|
||||
}
|
||||
|
||||
org.elasticsearch.geo.geometry.Polygon p = new org.elasticsearch.geo.geometry.Polygon(new org.elasticsearch.geo.geometry.LinearRing(
|
||||
Arrays.stream(coordinates).mapToDouble(i->i.y).toArray(),
|
||||
Arrays.stream(coordinates).mapToDouble(i->i.x).toArray()
|
||||
org.elasticsearch.geometry.Polygon p = new org.elasticsearch.geometry.Polygon(new org.elasticsearch.geometry.LinearRing(
|
||||
Arrays.stream(coordinates).mapToDouble(i->i.x).toArray(), Arrays.stream(coordinates).mapToDouble(i->i.y).toArray()
|
||||
));
|
||||
assertGeometryEquals(p, polygonGeoJson, false);
|
||||
}
|
||||
@ -863,12 +863,12 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
Polygon expected = GEOMETRY_FACTORY.createPolygon(shell, holes);
|
||||
assertGeometryEquals(jtsGeom(expected), polygonGeoJson, true);
|
||||
|
||||
org.elasticsearch.geo.geometry.LinearRing hole =
|
||||
new org.elasticsearch.geo.geometry.LinearRing(
|
||||
new double[] {0.8d, 0.2d, 0.2d, 0.8d, 0.8d}, new double[] {100.8d, 100.8d, 100.2d, 100.2d, 100.8d});
|
||||
org.elasticsearch.geo.geometry.Polygon p =
|
||||
new org.elasticsearch.geo.geometry.Polygon(new org.elasticsearch.geo.geometry.LinearRing(
|
||||
new double[] {0d, 0d, 1d, 1d, 0d}, new double[] {100d, 101d, 101d, 100d, 100d}), Collections.singletonList(hole));
|
||||
org.elasticsearch.geometry.LinearRing hole =
|
||||
new org.elasticsearch.geometry.LinearRing(
|
||||
new double[] {100.8d, 100.8d, 100.2d, 100.2d, 100.8d}, new double[] {0.8d, 0.2d, 0.2d, 0.8d, 0.8d});
|
||||
org.elasticsearch.geometry.Polygon p =
|
||||
new org.elasticsearch.geometry.Polygon(new org.elasticsearch.geometry.LinearRing(
|
||||
new double[] {100d, 101d, 101d, 100d, 100d}, new double[] {0d, 0d, 1d, 1d, 0d}), Collections.singletonList(hole));
|
||||
assertGeometryEquals(p, polygonGeoJson, false);
|
||||
}
|
||||
|
||||
@ -911,8 +911,8 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
assertGeometryEquals(expected, multiPointGeoJson, true);
|
||||
|
||||
assertGeometryEquals(new MultiPoint(Arrays.asList(
|
||||
new org.elasticsearch.geo.geometry.Point(0, 100),
|
||||
new org.elasticsearch.geo.geometry.Point(1, 101))), multiPointGeoJson, false);
|
||||
new org.elasticsearch.geometry.Point(100, 0),
|
||||
new org.elasticsearch.geometry.Point(101, 1))), multiPointGeoJson, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -983,14 +983,14 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
|
||||
assertGeometryEquals(expected, multiPolygonGeoJson, true);
|
||||
|
||||
org.elasticsearch.geo.geometry.LinearRing hole = new org.elasticsearch.geo.geometry.LinearRing(
|
||||
new double[] {0.8d, 0.2d, 0.2d, 0.8d, 0.8d}, new double[] {100.8d, 100.8d, 100.2d, 100.2d, 100.8d});
|
||||
org.elasticsearch.geometry.LinearRing hole = new org.elasticsearch.geometry.LinearRing(
|
||||
new double[] {100.8d, 100.8d, 100.2d, 100.2d, 100.8d}, new double[] {0.8d, 0.2d, 0.2d, 0.8d, 0.8d});
|
||||
|
||||
org.elasticsearch.geo.geometry.MultiPolygon polygons = new org.elasticsearch.geo.geometry.MultiPolygon(Arrays.asList(
|
||||
new org.elasticsearch.geo.geometry.Polygon(new org.elasticsearch.geo.geometry.LinearRing(
|
||||
new double[] {2d, 3d, 3d, 2d, 2d}, new double[] {103d, 103d, 102d, 102d, 103d})),
|
||||
new org.elasticsearch.geo.geometry.Polygon(new org.elasticsearch.geo.geometry.LinearRing(
|
||||
new double[] {0d, 1d, 1d, 0d, 0d}, new double[] {101d, 101d, 100d, 100d, 101d}), Collections.singletonList(hole))));
|
||||
org.elasticsearch.geometry.MultiPolygon polygons = new org.elasticsearch.geometry.MultiPolygon(Arrays.asList(
|
||||
new org.elasticsearch.geometry.Polygon(new org.elasticsearch.geometry.LinearRing(
|
||||
new double[] {103d, 103d, 102d, 102d, 103d}, new double[] {2d, 3d, 3d, 2d, 2d})),
|
||||
new org.elasticsearch.geometry.Polygon(new org.elasticsearch.geometry.LinearRing(
|
||||
new double[] {101d, 101d, 100d, 100d, 101d}, new double[] {0d, 1d, 1d, 0d, 0d}), Collections.singletonList(hole))));
|
||||
|
||||
assertGeometryEquals(polygons, multiPolygonGeoJson, false);
|
||||
|
||||
@ -1041,13 +1041,13 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
|
||||
assertGeometryEquals(jtsGeom(withHoles), multiPolygonGeoJson, true);
|
||||
|
||||
org.elasticsearch.geo.geometry.LinearRing luceneHole =
|
||||
new org.elasticsearch.geo.geometry.LinearRing(
|
||||
new double[] {0.8d, 0.2d, 0.2d, 0.8d, 0.8d}, new double[] {100.8d, 100.8d, 100.2d, 100.2d, 100.8d});
|
||||
org.elasticsearch.geometry.LinearRing luceneHole =
|
||||
new org.elasticsearch.geometry.LinearRing(
|
||||
new double[] {100.8d, 100.8d, 100.2d, 100.2d, 100.8d}, new double[] {0.8d, 0.2d, 0.2d, 0.8d, 0.8d});
|
||||
|
||||
org.elasticsearch.geo.geometry.Polygon lucenePolygons = (new org.elasticsearch.geo.geometry.Polygon(
|
||||
new org.elasticsearch.geo.geometry.LinearRing(
|
||||
new double[] {0d, 0d, 1d, 1d, 0d}, new double[] {100d, 101d, 101d, 100d, 100d}), Collections.singletonList(luceneHole)));
|
||||
org.elasticsearch.geometry.Polygon lucenePolygons = (new org.elasticsearch.geometry.Polygon(
|
||||
new org.elasticsearch.geometry.LinearRing(
|
||||
new double[] {100d, 101d, 101d, 100d, 100d}, new double[] {0d, 0d, 1d, 1d, 0d}), Collections.singletonList(luceneHole)));
|
||||
assertGeometryEquals(lucenePolygons, multiPolygonGeoJson, false);
|
||||
}
|
||||
|
||||
@ -1124,16 +1124,16 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
assertGeometryEquals(shapeCollection(expected), geometryCollectionGeoJson, true);
|
||||
|
||||
GeometryCollection<Geometry> geometryExpected = new GeometryCollection<> (Arrays.asList(
|
||||
new org.elasticsearch.geo.geometry.Line(new double[] {0d, 1d}, new double[] {100d, 101d}),
|
||||
new org.elasticsearch.geo.geometry.Point(2d, 102d),
|
||||
new org.elasticsearch.geo.geometry.MultiPolygon(Arrays.asList(
|
||||
new org.elasticsearch.geo.geometry.Polygon(new org.elasticsearch.geo.geometry.LinearRing(
|
||||
new double[] {-12.142857142857142d, 12.142857142857142d, 15d, 0d, -15d, -12.142857142857142d},
|
||||
new double[] {180d, 180d, 176d, 172d, 176d, 180d}
|
||||
new Line(new double[] {100d, 101d}, new double[] {0d, 1d}),
|
||||
new org.elasticsearch.geometry.Point(102d, 2d),
|
||||
new org.elasticsearch.geometry.MultiPolygon(Arrays.asList(
|
||||
new org.elasticsearch.geometry.Polygon(new org.elasticsearch.geometry.LinearRing(
|
||||
new double[] {180d, 180d, 176d, 172d, 176d, 180d},
|
||||
new double[] {-12.142857142857142d, 12.142857142857142d, 15d, 0d, -15d, -12.142857142857142d}
|
||||
)),
|
||||
new org.elasticsearch.geo.geometry.Polygon(new org.elasticsearch.geo.geometry.LinearRing(
|
||||
new double[] {12.142857142857142d, -12.142857142857142d, -10d, 10d, 12.142857142857142d},
|
||||
new double[] {-180d, -180d, -177d, -177d, -180d}
|
||||
new org.elasticsearch.geometry.Polygon(new org.elasticsearch.geometry.LinearRing(
|
||||
new double[] {-180d, -180d, -177d, -177d, -180d},
|
||||
new double[] {12.142857142857142d, -12.142857142857142d, -10d, 10d, 12.142857142857142d}
|
||||
))
|
||||
))
|
||||
));
|
||||
@ -1159,7 +1159,7 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
Point expected = GEOMETRY_FACTORY.createPoint(new Coordinate(100.0, 0.0));
|
||||
assertGeometryEquals(new JtsPoint(expected, SPATIAL_CONTEXT), pointGeoJson, true);
|
||||
|
||||
org.elasticsearch.geo.geometry.Point expectedPt = new org.elasticsearch.geo.geometry.Point(0, 100);
|
||||
org.elasticsearch.geometry.Point expectedPt = new org.elasticsearch.geometry.Point(100, 0);
|
||||
assertGeometryEquals(expectedPt, pointGeoJson, false);
|
||||
}
|
||||
|
||||
@ -1423,7 +1423,7 @@ public class GeoJsonShapeParserTests extends BaseGeoParsingTestCase {
|
||||
assertNull(parser.nextToken()); // no more elements afterwards
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Geometry parse(XContentParser parser) throws IOException, ParseException {
|
||||
GeometryParser geometryParser = new GeometryParser(true, true, true);
|
||||
GeoShapeIndexer indexer = new GeoShapeIndexer(true, "name");
|
||||
|
@ -40,11 +40,11 @@ import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.index.mapper.ContentPath;
|
||||
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
|
||||
import org.elasticsearch.index.mapper.GeoShapeIndexer;
|
||||
@ -110,7 +110,7 @@ public class GeoWKTShapeParserTests extends BaseGeoParsingTestCase {
|
||||
Coordinate c = new Coordinate(p.lon(), p.lat());
|
||||
Point expected = GEOMETRY_FACTORY.createPoint(c);
|
||||
assertExpected(new JtsPoint(expected, SPATIAL_CONTEXT), new PointBuilder().coordinate(c), true);
|
||||
assertExpected(new org.elasticsearch.geo.geometry.Point(p.lat(), p.lon()), new PointBuilder().coordinate(c), false);
|
||||
assertExpected(new org.elasticsearch.geometry.Point(p.lon(), p.lat()), new PointBuilder().coordinate(c), false);
|
||||
assertMalformed(new PointBuilder().coordinate(c));
|
||||
}
|
||||
|
||||
@ -122,10 +122,10 @@ public class GeoWKTShapeParserTests extends BaseGeoParsingTestCase {
|
||||
coordinates.add(new Coordinate(GeoTestUtil.nextLongitude(), GeoTestUtil.nextLatitude()));
|
||||
}
|
||||
|
||||
List<org.elasticsearch.geo.geometry.Point> points = new ArrayList<>(numPoints);
|
||||
List<org.elasticsearch.geometry.Point> points = new ArrayList<>(numPoints);
|
||||
for (int i = 0; i < numPoints; ++i) {
|
||||
Coordinate c = coordinates.get(i);
|
||||
points.add(new org.elasticsearch.geo.geometry.Point(c.y, c.x));
|
||||
points.add(new org.elasticsearch.geometry.Point(c.x, c.y));
|
||||
}
|
||||
|
||||
Geometry expectedGeom;
|
||||
@ -177,7 +177,7 @@ public class GeoWKTShapeParserTests extends BaseGeoParsingTestCase {
|
||||
lats[i] = coordinates.get(i).y;
|
||||
lons[i] = coordinates.get(i).x;
|
||||
}
|
||||
assertExpected(new Line(lats, lons), new LineStringBuilder(coordinates), false);
|
||||
assertExpected(new Line(lons, lats), new LineStringBuilder(coordinates), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -195,14 +195,14 @@ public class GeoWKTShapeParserTests extends BaseGeoParsingTestCase {
|
||||
List<Line> lines = new ArrayList<>(lineStrings.size());
|
||||
for (int j = 0; j < lineStrings.size(); ++j) {
|
||||
Coordinate[] c = lineStrings.get(j).getCoordinates();
|
||||
lines.add(new Line(Arrays.stream(c).mapToDouble(i->i.y).toArray(),
|
||||
Arrays.stream(c).mapToDouble(i->i.x).toArray()));
|
||||
lines.add(new Line(Arrays.stream(c).mapToDouble(i->i.x).toArray(), Arrays.stream(c).mapToDouble(i->i.y).toArray()
|
||||
));
|
||||
}
|
||||
Geometry expectedGeom;
|
||||
if (lines.isEmpty()) {
|
||||
expectedGeom = GeometryCollection.EMPTY;
|
||||
} else if (lines.size() == 1) {
|
||||
expectedGeom = new Line(lines.get(0).getLats(), lines.get(0).getLons());
|
||||
expectedGeom = new Line(lines.get(0).getX(), lines.get(0).getY());
|
||||
} else {
|
||||
expectedGeom = new MultiLine(lines);
|
||||
}
|
||||
@ -275,12 +275,12 @@ public class GeoWKTShapeParserTests extends BaseGeoParsingTestCase {
|
||||
Polygon expected = GEOMETRY_FACTORY.createPolygon(shell, holes);
|
||||
assertExpected(jtsGeom(expected), polygonWithHole, true);
|
||||
|
||||
org.elasticsearch.geo.geometry.LinearRing hole =
|
||||
new org.elasticsearch.geo.geometry.LinearRing(
|
||||
new double[] {0.8d, 0.8d, 0.2d, 0.2d, 0.8d}, new double[] {100.2d, 100.8d, 100.8d, 100.2d, 100.2d});
|
||||
org.elasticsearch.geo.geometry.Polygon p =
|
||||
new org.elasticsearch.geo.geometry.Polygon(new org.elasticsearch.geo.geometry.LinearRing(
|
||||
new double[] {0d, 1d, 1d, 0d, 0d}, new double[] {101d, 101d, 100d, 100d, 101d}), Collections.singletonList(hole));
|
||||
org.elasticsearch.geometry.LinearRing hole =
|
||||
new org.elasticsearch.geometry.LinearRing(
|
||||
new double[] {100.2d, 100.8d, 100.8d, 100.2d, 100.2d}, new double[] {0.8d, 0.8d, 0.2d, 0.2d, 0.8d});
|
||||
org.elasticsearch.geometry.Polygon p =
|
||||
new org.elasticsearch.geometry.Polygon(new org.elasticsearch.geometry.LinearRing(
|
||||
new double[] {101d, 101d, 100d, 100d, 101d}, new double[] {0d, 1d, 1d, 0d, 0d}), Collections.singletonList(hole));
|
||||
assertExpected(p, polygonWithHole, false);
|
||||
assertMalformed(polygonWithHole);
|
||||
}
|
||||
@ -448,7 +448,7 @@ public class GeoWKTShapeParserTests extends BaseGeoParsingTestCase {
|
||||
|
||||
Rectangle expected = SPATIAL_CONTEXT.makeRectangle(r.minLon, r.maxLon, r.minLat, r.maxLat);
|
||||
assertExpected(expected, builder, true);
|
||||
assertExpected(new org.elasticsearch.geo.geometry.Rectangle(r.minLat, r.maxLat, r.minLon, r.maxLon), builder, false);
|
||||
assertExpected(new org.elasticsearch.geometry.Rectangle(r.minLon, r.maxLon, r.maxLat, r.minLat), builder, false);
|
||||
assertMalformed(builder);
|
||||
}
|
||||
|
||||
|
@ -24,9 +24,9 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.ShapeType;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.ShapeType;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import static org.elasticsearch.geo.GeometryTestUtils.randomGeometry;
|
||||
@ -84,7 +84,7 @@ public class GeometryIOTests extends ESTestCase {
|
||||
}
|
||||
|
||||
private boolean shapeSupported(Geometry geometry) {
|
||||
if (geometry.hasAlt()) {
|
||||
if (geometry.hasZ()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -22,17 +22,17 @@ package org.elasticsearch.common.geo;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Polygon;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
import org.elasticsearch.index.mapper.GeoShapeIndexer;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
@ -50,7 +50,7 @@ public class GeometryIndexerTests extends ESTestCase {
|
||||
|
||||
public void testCircle() {
|
||||
UnsupportedOperationException ex =
|
||||
expectThrows(UnsupportedOperationException.class, () -> indexer.prepareForIndexing(new Circle(1, 2, 3)));
|
||||
expectThrows(UnsupportedOperationException.class, () -> indexer.prepareForIndexing(new Circle(2, 1, 3)));
|
||||
assertEquals("CIRCLE geometry is not supported", ex.getMessage());
|
||||
}
|
||||
|
||||
@ -58,21 +58,21 @@ public class GeometryIndexerTests extends ESTestCase {
|
||||
assertEquals(GeometryCollection.EMPTY, indexer.prepareForIndexing(GeometryCollection.EMPTY));
|
||||
|
||||
GeometryCollection<Geometry> collection = new GeometryCollection<>(Collections.singletonList(
|
||||
new Point(1, 2)
|
||||
new Point(2, 1)
|
||||
));
|
||||
|
||||
Geometry indexed = new Point(1, 2);
|
||||
Geometry indexed = new Point(2, 1);
|
||||
assertEquals(indexed, indexer.prepareForIndexing(collection));
|
||||
|
||||
collection = new GeometryCollection<>(Arrays.asList(
|
||||
new Point(1, 2), new Point(3, 4), new Line(new double[]{10, 20}, new double[]{160, 200})
|
||||
new Point(2, 1), new Point(4, 3), new Line(new double[]{160, 200}, new double[]{10, 20})
|
||||
));
|
||||
|
||||
indexed = new GeometryCollection<>(Arrays.asList(
|
||||
new Point(1, 2), new Point(3, 4),
|
||||
new Point(2, 1), new Point(4, 3),
|
||||
new MultiLine(Arrays.asList(
|
||||
new Line(new double[]{10, 15}, new double[]{160, 180}),
|
||||
new Line(new double[]{15, 20}, new double[]{180, -160}))
|
||||
new Line(new double[]{160, 180}, new double[]{10, 15}),
|
||||
new Line(new double[]{180, -160}, new double[]{15, 20}))
|
||||
))
|
||||
);
|
||||
assertEquals(indexed, indexer.prepareForIndexing(collection));
|
||||
@ -80,44 +80,44 @@ public class GeometryIndexerTests extends ESTestCase {
|
||||
}
|
||||
|
||||
public void testLine() {
|
||||
Line line = new Line(new double[]{1, 2}, new double[]{3, 4});
|
||||
Line line = new Line(new double[]{3, 4}, new double[]{1, 2});
|
||||
Geometry indexed = line;
|
||||
assertEquals(indexed, indexer.prepareForIndexing(line));
|
||||
|
||||
line = new Line(new double[]{10, 20}, new double[]{160, 200});
|
||||
line = new Line(new double[]{160, 200}, new double[]{10, 20});
|
||||
indexed = new MultiLine(Arrays.asList(
|
||||
new Line(new double[]{10, 15}, new double[]{160, 180}),
|
||||
new Line(new double[]{15, 20}, new double[]{180, -160}))
|
||||
new Line(new double[]{160, 180}, new double[]{10, 15}),
|
||||
new Line(new double[]{180, -160}, new double[]{15, 20}))
|
||||
);
|
||||
|
||||
assertEquals(indexed, indexer.prepareForIndexing(line));
|
||||
}
|
||||
|
||||
public void testMultiLine() {
|
||||
Line line = new Line(new double[]{1, 2}, new double[]{3, 4});
|
||||
Line line = new Line(new double[]{3, 4}, new double[]{1, 2});
|
||||
MultiLine multiLine = new MultiLine(Collections.singletonList(line));
|
||||
Geometry indexed = line;
|
||||
assertEquals(indexed, indexer.prepareForIndexing(multiLine));
|
||||
|
||||
multiLine = new MultiLine(Arrays.asList(
|
||||
line, new Line(new double[]{10, 20}, new double[]{160, 200})
|
||||
line, new Line(new double[]{160, 200}, new double[]{10, 20})
|
||||
));
|
||||
|
||||
indexed = new MultiLine(Arrays.asList(
|
||||
line,
|
||||
new Line(new double[]{10, 15}, new double[]{160, 180}),
|
||||
new Line(new double[]{15, 20}, new double[]{180, -160}))
|
||||
new Line(new double[]{160, 180}, new double[]{10, 15}),
|
||||
new Line(new double[]{180, -160}, new double[]{15, 20}))
|
||||
);
|
||||
|
||||
assertEquals(indexed, indexer.prepareForIndexing(multiLine));
|
||||
}
|
||||
|
||||
public void testPoint() {
|
||||
Point point = new Point(1, 2);
|
||||
Point point = new Point(2, 1);
|
||||
Geometry indexed = point;
|
||||
assertEquals(indexed, indexer.prepareForIndexing(point));
|
||||
|
||||
point = new Point(1, 2, 3);
|
||||
point = new Point(2, 1, 3);
|
||||
assertEquals(indexed, indexer.prepareForIndexing(point));
|
||||
}
|
||||
|
||||
@ -126,38 +126,38 @@ public class GeometryIndexerTests extends ESTestCase {
|
||||
Geometry indexed = multiPoint;
|
||||
assertEquals(indexed, indexer.prepareForIndexing(multiPoint));
|
||||
|
||||
multiPoint = new MultiPoint(Collections.singletonList(new Point(1, 2)));
|
||||
indexed = new Point(1, 2);
|
||||
multiPoint = new MultiPoint(Collections.singletonList(new Point(2, 1)));
|
||||
indexed = new Point(2, 1);
|
||||
assertEquals(indexed, indexer.prepareForIndexing(multiPoint));
|
||||
|
||||
multiPoint = new MultiPoint(Arrays.asList(new Point(1, 2), new Point(3, 4)));
|
||||
multiPoint = new MultiPoint(Arrays.asList(new Point(2, 1), new Point(4, 3)));
|
||||
indexed = multiPoint;
|
||||
assertEquals(indexed, indexer.prepareForIndexing(multiPoint));
|
||||
|
||||
multiPoint = new MultiPoint(Arrays.asList(new Point(1, 2, 10), new Point(3, 4, 10)));
|
||||
multiPoint = new MultiPoint(Arrays.asList(new Point(2, 1, 10), new Point(4, 3, 10)));
|
||||
assertEquals(indexed, indexer.prepareForIndexing(multiPoint));
|
||||
}
|
||||
|
||||
public void testPolygon() {
|
||||
Polygon polygon = new Polygon(new LinearRing(new double[]{10, 10, 20, 20, 10}, new double[]{160, 200, 200, 160, 160}));
|
||||
Polygon polygon = new Polygon(new LinearRing(new double[]{160, 200, 200, 160, 160}, new double[]{10, 10, 20, 20, 10}));
|
||||
Geometry indexed = new MultiPolygon(Arrays.asList(
|
||||
new Polygon(new LinearRing(new double[]{10, 20, 20, 10, 10}, new double[]{180, 180, 160, 160, 180})),
|
||||
new Polygon(new LinearRing(new double[]{20, 10, 10, 20, 20}, new double[]{-180, -180, -160, -160, -180}))
|
||||
new Polygon(new LinearRing(new double[]{180, 180, 160, 160, 180}, new double[]{10, 20, 20, 10, 10})),
|
||||
new Polygon(new LinearRing(new double[]{-180, -180, -160, -160, -180}, new double[]{20, 10, 10, 20, 20}))
|
||||
));
|
||||
|
||||
assertEquals(indexed, indexer.prepareForIndexing(polygon));
|
||||
|
||||
polygon = new Polygon(new LinearRing(new double[]{10, 10, 20, 20, 10}, new double[]{160, 200, 200, 160, 160}),
|
||||
polygon = new Polygon(new LinearRing(new double[]{160, 200, 200, 160, 160}, new double[]{10, 10, 20, 20, 10}),
|
||||
Collections.singletonList(
|
||||
new LinearRing(new double[]{12, 18, 18, 12, 12}, new double[]{165, 165, 195, 195, 165})));
|
||||
new LinearRing(new double[]{165, 165, 195, 195, 165}, new double[]{12, 18, 18, 12, 12})));
|
||||
|
||||
indexed = new MultiPolygon(Arrays.asList(
|
||||
new Polygon(new LinearRing(
|
||||
new double[]{10, 12, 12, 18, 18, 20, 20, 10, 10},
|
||||
new double[]{180, 180, 165, 165, 180, 180, 160, 160, 180})),
|
||||
new double[]{180, 180, 165, 165, 180, 180, 160, 160, 180}, new double[]{10, 12, 12, 18, 18, 20, 20, 10, 10}
|
||||
)),
|
||||
new Polygon(new LinearRing(
|
||||
new double[]{12, 10, 10, 20, 20, 18, 18, 12, 12},
|
||||
new double[]{-180, -180, -160, -160, -180, -180, -165, -165, -180}))
|
||||
new double[]{-180, -180, -160, -160, -180, -180, -165, -165, -180}, new double[]{12, 10, 10, 20, 20, 18, 18, 12, 12}
|
||||
))
|
||||
));
|
||||
|
||||
assertEquals(indexed, indexer.prepareForIndexing(polygon));
|
||||
|
@ -26,10 +26,10 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParseException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
/**
|
||||
@ -48,9 +48,9 @@ public class GeometryParserTests extends ESTestCase {
|
||||
try (XContentParser parser = createParser(pointGeoJson)) {
|
||||
parser.nextToken();
|
||||
GeometryFormat format = new GeometryParser(true, randomBoolean(), randomBoolean()).geometryFormat(parser);
|
||||
assertEquals(new Point(0, 100), format.fromXContent(parser));
|
||||
assertEquals(new Point(100, 0), format.fromXContent(parser));
|
||||
XContentBuilder newGeoJson = XContentFactory.jsonBuilder();
|
||||
format.toXContent(new Point(10, 100), newGeoJson, ToXContent.EMPTY_PARAMS);
|
||||
format.toXContent(new Point(100, 10), newGeoJson, ToXContent.EMPTY_PARAMS);
|
||||
assertEquals("{\"type\":\"point\",\"coordinates\":[100.0,10.0]}", Strings.toString(newGeoJson));
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ public class GeometryParserTests extends ESTestCase {
|
||||
|
||||
try (XContentParser parser = createParser(pointGeoJsonWithZ)) {
|
||||
parser.nextToken();
|
||||
assertEquals(new Point(0, 100, 10.0), new GeometryParser(true, randomBoolean(), true).parse(parser));
|
||||
assertEquals(new Point(100, 0, 10.0), new GeometryParser(true, randomBoolean(), true).parse(parser));
|
||||
}
|
||||
|
||||
|
||||
@ -84,7 +84,7 @@ public class GeometryParserTests extends ESTestCase {
|
||||
.endArray()
|
||||
.endObject();
|
||||
|
||||
Polygon p = new Polygon(new LinearRing(new double[]{1d, 1d, 0d, 0d, 1d}, new double[]{100d, 101d, 101d, 100d, 100d}));
|
||||
Polygon p = new Polygon(new LinearRing(new double[]{100d, 101d, 101d, 100d, 100d}, new double[]{1d, 1d, 0d, 0d, 1d}));
|
||||
try (XContentParser parser = createParser(polygonGeoJson)) {
|
||||
parser.nextToken();
|
||||
// Coerce should automatically close the polygon
|
||||
@ -109,9 +109,9 @@ public class GeometryParserTests extends ESTestCase {
|
||||
parser.nextToken(); // Field Name
|
||||
parser.nextToken(); // Field Value
|
||||
GeometryFormat format = new GeometryParser(true, randomBoolean(), randomBoolean()).geometryFormat(parser);
|
||||
assertEquals(new Point(0, 100), format.fromXContent(parser));
|
||||
assertEquals(new Point(100, 0), format.fromXContent(parser));
|
||||
XContentBuilder newGeoJson = XContentFactory.jsonBuilder().startObject().field("val");
|
||||
format.toXContent(new Point(10, 100), newGeoJson, ToXContent.EMPTY_PARAMS);
|
||||
format.toXContent(new Point(100, 10), newGeoJson, ToXContent.EMPTY_PARAMS);
|
||||
newGeoJson.endObject();
|
||||
assertEquals("{\"val\":\"point (100.0 10.0)\"}", Strings.toString(newGeoJson));
|
||||
}
|
||||
@ -126,7 +126,7 @@ public class GeometryParserTests extends ESTestCase {
|
||||
parser.nextToken(); // Start object
|
||||
parser.nextToken(); // Field Name
|
||||
parser.nextToken(); // Field Value
|
||||
assertEquals(new Line(new double[]{0, 10}, new double[]{100, 200} ),
|
||||
assertEquals(new Line(new double[]{100, 200}, new double[]{0, 10}),
|
||||
new GeometryParser(true, randomBoolean(), randomBoolean()).parse(parser));
|
||||
}
|
||||
}
|
||||
@ -146,7 +146,7 @@ public class GeometryParserTests extends ESTestCase {
|
||||
|
||||
XContentBuilder newGeoJson = XContentFactory.jsonBuilder().startObject().field("val");
|
||||
// if we serialize non-null value - it should be serialized as geojson
|
||||
format.toXContent(new Point(10, 100), newGeoJson, ToXContent.EMPTY_PARAMS);
|
||||
format.toXContent(new Point(100, 10), newGeoJson, ToXContent.EMPTY_PARAMS);
|
||||
newGeoJson.endObject();
|
||||
assertEquals("{\"val\":{\"type\":\"point\",\"coordinates\":[100.0,10.0]}}", Strings.toString(newGeoJson));
|
||||
|
||||
|
@ -27,6 +27,7 @@ import org.elasticsearch.common.geo.builders.MultiLineStringBuilder;
|
||||
import org.elasticsearch.common.geo.builders.PointBuilder;
|
||||
import org.elasticsearch.common.geo.builders.PolygonBuilder;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.index.mapper.GeoShapeIndexer;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
@ -52,9 +53,9 @@ public class ShapeBuilderTests extends ESTestCase {
|
||||
Point point = pb.buildS4J();
|
||||
assertEquals(-100D, point.getX(), 0.0d);
|
||||
assertEquals(45D, point.getY(), 0.0d);
|
||||
org.elasticsearch.geo.geometry.Point geoPoint = pb.buildGeometry();
|
||||
assertEquals(-100D, geoPoint.getLon(), 0.0d);
|
||||
assertEquals(45D, geoPoint.getLat(), 0.0d);
|
||||
org.elasticsearch.geometry.Point geoPoint = pb.buildGeometry();
|
||||
assertEquals(-100D, geoPoint.getX(), 0.0d);
|
||||
assertEquals(45D, geoPoint.getY(), 0.0d);
|
||||
}
|
||||
|
||||
public void testNewRectangle() {
|
||||
@ -65,11 +66,11 @@ public class ShapeBuilderTests extends ESTestCase {
|
||||
assertEquals(45D, rectangle.getMaxX(), 0.0d);
|
||||
assertEquals(30D, rectangle.getMaxY(), 0.0d);
|
||||
|
||||
org.elasticsearch.geo.geometry.Rectangle luceneRectangle = eb.buildGeometry();
|
||||
assertEquals(-45D, luceneRectangle.getMinLon(), 0.0d);
|
||||
assertEquals(-30D, luceneRectangle.getMinLat(), 0.0d);
|
||||
assertEquals(45D, luceneRectangle.getMaxLon(), 0.0d);
|
||||
assertEquals(30D, luceneRectangle.getMaxLat(), 0.0d);
|
||||
org.elasticsearch.geometry.Rectangle luceneRectangle = eb.buildGeometry();
|
||||
assertEquals(-45D, luceneRectangle.getMinX(), 0.0d);
|
||||
assertEquals(-30D, luceneRectangle.getMinY(), 0.0d);
|
||||
assertEquals(45D, luceneRectangle.getMaxX(), 0.0d);
|
||||
assertEquals(30D, luceneRectangle.getMaxY(), 0.0d);
|
||||
}
|
||||
|
||||
public void testNewPolygon() {
|
||||
@ -87,15 +88,15 @@ public class ShapeBuilderTests extends ESTestCase {
|
||||
assertEquals(exterior.getCoordinateN(2), new Coordinate(45, -30));
|
||||
assertEquals(exterior.getCoordinateN(3), new Coordinate(-45, -30));
|
||||
|
||||
org.elasticsearch.geo.geometry.LinearRing polygon = pb.toPolygonGeometry().getPolygon();
|
||||
assertEquals(polygon.getLat(0), 30, 0d);
|
||||
assertEquals(polygon.getLon(0), -45, 0d);
|
||||
assertEquals(polygon.getLat(1), 30, 0d);
|
||||
assertEquals(polygon.getLon(1), 45, 0d);
|
||||
assertEquals(polygon.getLat(2), -30, 0d);
|
||||
assertEquals(polygon.getLon(2), 45, 0d);
|
||||
assertEquals(polygon.getLat(3), -30, 0d);
|
||||
assertEquals(polygon.getLon(3), -45, 0d);
|
||||
LinearRing polygon = pb.toPolygonGeometry().getPolygon();
|
||||
assertEquals(polygon.getY(0), 30, 0d);
|
||||
assertEquals(polygon.getX(0), -45, 0d);
|
||||
assertEquals(polygon.getY(1), 30, 0d);
|
||||
assertEquals(polygon.getX(1), 45, 0d);
|
||||
assertEquals(polygon.getY(2), -30, 0d);
|
||||
assertEquals(polygon.getX(2), 45, 0d);
|
||||
assertEquals(polygon.getY(3), -30, 0d);
|
||||
assertEquals(polygon.getX(3), -45, 0d);
|
||||
}
|
||||
|
||||
public void testNewPolygon_coordinate() {
|
||||
@ -113,15 +114,15 @@ public class ShapeBuilderTests extends ESTestCase {
|
||||
assertEquals(exterior.getCoordinateN(2), new Coordinate(45, -30));
|
||||
assertEquals(exterior.getCoordinateN(3), new Coordinate(-45, -30));
|
||||
|
||||
org.elasticsearch.geo.geometry.LinearRing polygon = pb.toPolygonGeometry().getPolygon();
|
||||
assertEquals(polygon.getLat(0), 30, 0d);
|
||||
assertEquals(polygon.getLon(0), -45, 0d);
|
||||
assertEquals(polygon.getLat(1), 30, 0d);
|
||||
assertEquals(polygon.getLon(1), 45, 0d);
|
||||
assertEquals(polygon.getLat(2), -30, 0d);
|
||||
assertEquals(polygon.getLon(2), 45, 0d);
|
||||
assertEquals(polygon.getLat(3), -30, 0d);
|
||||
assertEquals(polygon.getLon(3), -45, 0d);
|
||||
LinearRing polygon = pb.toPolygonGeometry().getPolygon();
|
||||
assertEquals(polygon.getY(0), 30, 0d);
|
||||
assertEquals(polygon.getX(0), -45, 0d);
|
||||
assertEquals(polygon.getY(1), 30, 0d);
|
||||
assertEquals(polygon.getX(1), 45, 0d);
|
||||
assertEquals(polygon.getY(2), -30, 0d);
|
||||
assertEquals(polygon.getX(2), 45, 0d);
|
||||
assertEquals(polygon.getY(3), -30, 0d);
|
||||
assertEquals(polygon.getX(3), -45, 0d);
|
||||
}
|
||||
|
||||
public void testNewPolygon_coordinates() {
|
||||
@ -137,15 +138,15 @@ public class ShapeBuilderTests extends ESTestCase {
|
||||
assertEquals(exterior.getCoordinateN(2), new Coordinate(45, -30));
|
||||
assertEquals(exterior.getCoordinateN(3), new Coordinate(-45, -30));
|
||||
|
||||
org.elasticsearch.geo.geometry.LinearRing polygon = pb.toPolygonGeometry().getPolygon();
|
||||
assertEquals(polygon.getLat(0), 30, 0d);
|
||||
assertEquals(polygon.getLon(0), -45, 0d);
|
||||
assertEquals(polygon.getLat(1), 30, 0d);
|
||||
assertEquals(polygon.getLon(1), 45, 0d);
|
||||
assertEquals(polygon.getLat(2), -30, 0d);
|
||||
assertEquals(polygon.getLon(2), 45, 0d);
|
||||
assertEquals(polygon.getLat(3), -30, 0d);
|
||||
assertEquals(polygon.getLon(3), -45, 0d);
|
||||
LinearRing polygon = pb.toPolygonGeometry().getPolygon();
|
||||
assertEquals(polygon.getY(0), 30, 0d);
|
||||
assertEquals(polygon.getX(0), -45, 0d);
|
||||
assertEquals(polygon.getY(1), 30, 0d);
|
||||
assertEquals(polygon.getX(1), 45, 0d);
|
||||
assertEquals(polygon.getY(2), -30, 0d);
|
||||
assertEquals(polygon.getX(2), 45, 0d);
|
||||
assertEquals(polygon.getY(3), -30, 0d);
|
||||
assertEquals(polygon.getX(3), -45, 0d);
|
||||
}
|
||||
|
||||
public void testLineStringBuilder() {
|
||||
|
@ -30,7 +30,7 @@ import org.elasticsearch.common.collect.Iterators;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -187,7 +187,7 @@ public class ExternalMapper extends FieldMapper {
|
||||
|
||||
// Let's add a Dummy Shape
|
||||
if (shapeMapper instanceof GeoShapeFieldMapper) {
|
||||
shapeMapper.parse(context.createExternalValueContext(new Point(45, -100)));
|
||||
shapeMapper.parse(context.createExternalValueContext(new Point(-100, 45)));
|
||||
} else {
|
||||
PointBuilder pb = new PointBuilder(-100, 45);
|
||||
shapeMapper.parse(context.createExternalValueContext(pb.buildS4J()));
|
||||
|
@ -39,7 +39,7 @@ import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||
import static org.elasticsearch.geo.utils.Geohash.stringEncode;
|
||||
import static org.elasticsearch.geometry.utils.Geohash.stringEncode;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.IGNORE_Z_VALUE;
|
||||
import static org.elasticsearch.index.mapper.GeoPointFieldMapper.Names.NULL_VALUE;
|
||||
|
@ -32,7 +32,7 @@ import org.elasticsearch.test.geo.RandomGeoGenerator;
|
||||
import java.io.IOException;
|
||||
import java.util.function.DoubleSupplier;
|
||||
|
||||
import static org.elasticsearch.geo.utils.Geohash.stringEncode;
|
||||
import static org.elasticsearch.geometry.utils.Geohash.stringEncode;
|
||||
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
|
@ -28,7 +28,7 @@ import org.elasticsearch.common.geo.GeoUtils;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentParser.Token;
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.locationtech.spatial4j.context.SpatialContext;
|
||||
import org.locationtech.spatial4j.distance.DistanceUtils;
|
||||
|
@ -44,8 +44,8 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.geo.utils.Geohash.PRECISION;
|
||||
import static org.elasticsearch.geo.utils.Geohash.stringEncode;
|
||||
import static org.elasticsearch.geometry.utils.Geohash.PRECISION;
|
||||
import static org.elasticsearch.geometry.utils.Geohash.stringEncode;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.search.aggregations.AggregationBuilders.geohashGrid;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
|
@ -20,7 +20,7 @@ package org.elasticsearch.search.aggregations.bucket;
|
||||
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode;
|
||||
import org.elasticsearch.search.aggregations.bucket.filter.Filter;
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.elasticsearch.search.aggregations.bucket.geogrid;
|
||||
|
||||
import static org.elasticsearch.geo.utils.Geohash.stringEncode;
|
||||
import static org.elasticsearch.geometry.utils.Geohash.stringEncode;
|
||||
|
||||
public class GeoHashGridAggregatorTests extends GeoGridAggregatorTestCase<InternalGeoHashGridBucket> {
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.elasticsearch.search.aggregations.bucket.geogrid;
|
||||
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.search.aggregations.InternalAggregations;
|
||||
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
||||
|
||||
|
@ -33,7 +33,7 @@ import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
|
@ -29,7 +29,7 @@ import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.DistanceUnit;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.index.fielddata.ScriptDocValues;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
|
@ -66,7 +66,7 @@ import java.util.Random;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.geo.utils.Geohash.addNeighbors;
|
||||
import static org.elasticsearch.geometry.utils.Geohash.addNeighbors;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.geoBoundingBoxQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.geoDistanceQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
|
@ -27,7 +27,7 @@ import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.geometry.utils.Geohash;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
|
@ -40,7 +40,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.geo.utils.Geohash.addNeighborsAtLevel;
|
||||
import static org.elasticsearch.geometry.utils.Geohash.addNeighborsAtLevel;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.search.suggest.completion.CategoryContextMappingTests.assertContextSuggestFields;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -24,7 +24,8 @@ import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.geo.parsers.ShapeParser;
|
||||
import org.elasticsearch.common.unit.DistanceUnit;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Assert;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
@ -223,7 +224,7 @@ public class ElasticsearchGeoAssertions {
|
||||
Assert.assertEquals(s1, s2);
|
||||
} else if (s1 instanceof Object[] && s2 instanceof Object[]) {
|
||||
Assert.assertArrayEquals((Object[]) s1, (Object[]) s2);
|
||||
} else if (s1 instanceof org.elasticsearch.geo.geometry.Geometry && s2 instanceof org.elasticsearch.geo.geometry.Geometry) {
|
||||
} else if (s1 instanceof org.elasticsearch.geometry.Geometry && s2 instanceof org.elasticsearch.geometry.Geometry) {
|
||||
Assert.assertEquals(s1, s2);
|
||||
} else {
|
||||
//We want to know the type of the shape because we test shape equality in a special way...
|
||||
@ -245,7 +246,7 @@ public class ElasticsearchGeoAssertions {
|
||||
unwrapJTS(shape) instanceof MultiPolygon);
|
||||
} else {
|
||||
assertTrue("expected Polygon[] but found " + shape.getClass().getName(),
|
||||
shape instanceof org.elasticsearch.geo.geometry.MultiPolygon);
|
||||
shape instanceof org.elasticsearch.geometry.MultiPolygon);
|
||||
}
|
||||
}
|
||||
|
||||
@ -255,7 +256,7 @@ public class ElasticsearchGeoAssertions {
|
||||
+ unwrapJTS(shape).getClass().getName(), unwrapJTS(shape) instanceof Polygon);
|
||||
} else {
|
||||
assertTrue("expected Polygon but found " + shape.getClass().getName(),
|
||||
shape instanceof org.elasticsearch.geo.geometry.Polygon);
|
||||
shape instanceof org.elasticsearch.geometry.Polygon);
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,7 +266,7 @@ public class ElasticsearchGeoAssertions {
|
||||
+ unwrapJTS(shape).getClass().getName(), unwrapJTS(shape) instanceof LineString);
|
||||
} else {
|
||||
assertTrue("expected Line but found " + shape.getClass().getName(),
|
||||
shape instanceof org.elasticsearch.geo.geometry.Line);
|
||||
shape instanceof Line);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,17 +20,17 @@
|
||||
package org.elasticsearch.geo;
|
||||
|
||||
import org.apache.lucene.geo.GeoTestUtil;
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Polygon;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -53,10 +53,10 @@ public class GeometryTestUtils {
|
||||
|
||||
public static Circle randomCircle(boolean hasAlt) {
|
||||
if (hasAlt) {
|
||||
return new Circle(randomLat(), randomLon(), ESTestCase.randomDouble(),
|
||||
return new Circle(randomLon(), randomLat(), ESTestCase.randomDouble(),
|
||||
ESTestCase.randomDoubleBetween(0, 100, false));
|
||||
} else {
|
||||
return new Circle(randomLat(), randomLon(), ESTestCase.randomDoubleBetween(0, 100, false));
|
||||
return new Circle(randomLon(), randomLat(), ESTestCase.randomDoubleBetween(0, 100, false));
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,9 +75,9 @@ public class GeometryTestUtils {
|
||||
}
|
||||
}
|
||||
if (hasAlts) {
|
||||
return new Line(lats, lons, alts);
|
||||
return new Line(lons, lats, alts);
|
||||
}
|
||||
return new Line(lats, lons);
|
||||
return new Line(lons, lats);
|
||||
}
|
||||
|
||||
public static Point randomPoint() {
|
||||
@ -86,9 +86,9 @@ public class GeometryTestUtils {
|
||||
|
||||
public static Point randomPoint(boolean hasAlt) {
|
||||
if (hasAlt) {
|
||||
return new Point(randomLat(), randomLon(), randomAlt());
|
||||
return new Point(randomLon(), randomLat(), randomAlt());
|
||||
} else {
|
||||
return new Point(randomLat(), randomLon());
|
||||
return new Point(randomLon(), randomLat());
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,11 +99,11 @@ public class GeometryTestUtils {
|
||||
List<LinearRing> holes = new ArrayList<>();
|
||||
for (int i = 0; i < lucenePolygon.numHoles(); i++) {
|
||||
org.apache.lucene.geo.Polygon poly = luceneHoles[i];
|
||||
holes.add(linearRing(poly.getPolyLats(), poly.getPolyLons(), hasAlt));
|
||||
holes.add(linearRing(poly.getPolyLons(), poly.getPolyLats(), hasAlt));
|
||||
}
|
||||
return new Polygon(linearRing(lucenePolygon.getPolyLats(), lucenePolygon.getPolyLons(), hasAlt), holes);
|
||||
return new Polygon(linearRing(lucenePolygon.getPolyLons(), lucenePolygon.getPolyLats(), hasAlt), holes);
|
||||
}
|
||||
return new Polygon(linearRing(lucenePolygon.getPolyLats(), lucenePolygon.getPolyLons(), hasAlt));
|
||||
return new Polygon(linearRing(lucenePolygon.getPolyLons(), lucenePolygon.getPolyLats(), hasAlt));
|
||||
}
|
||||
|
||||
|
||||
@ -116,16 +116,16 @@ public class GeometryTestUtils {
|
||||
return alts;
|
||||
}
|
||||
|
||||
public static LinearRing linearRing(double[] lats, double[] lons, boolean generateAlts) {
|
||||
public static LinearRing linearRing(double[] lons, double[] lats,boolean generateAlts) {
|
||||
if (generateAlts) {
|
||||
return new LinearRing(lats, lons, randomAltRing(lats.length));
|
||||
return new LinearRing(lons, lats, randomAltRing(lats.length));
|
||||
}
|
||||
return new LinearRing(lats, lons);
|
||||
return new LinearRing(lons, lats);
|
||||
}
|
||||
|
||||
public static Rectangle randomRectangle() {
|
||||
org.apache.lucene.geo.Rectangle rectangle = GeoTestUtil.nextBox();
|
||||
return new Rectangle(rectangle.minLat, rectangle.maxLat, rectangle.minLon, rectangle.maxLon);
|
||||
return new Rectangle(rectangle.minLon, rectangle.maxLon, rectangle.maxLat, rectangle.minLat);
|
||||
}
|
||||
|
||||
public static MultiPoint randomMultiPoint(boolean hasAlt) {
|
||||
|
@ -6,11 +6,11 @@
|
||||
package org.elasticsearch.xpack.ml.datafeed.extractor.fields;
|
||||
|
||||
import org.elasticsearch.common.document.DocumentField;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.ShapeType;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.ShapeType;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -168,7 +168,7 @@ public abstract class ExtractedField {
|
||||
throw new IllegalArgumentException("Unexpected non-point geo_shape type: " + geometry.type().name());
|
||||
}
|
||||
Point pt = ((Point)geometry);
|
||||
return pt.getLat() + "," + pt.getLon();
|
||||
return pt.getY() + "," + pt.getX();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected value for a geo_shape field: " + geoString);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import org.elasticsearch.common.Explicit;
|
||||
import org.elasticsearch.common.geo.GeometryParser;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
|
@ -9,15 +9,18 @@ import org.apache.lucene.document.XYShape;
|
||||
import org.apache.lucene.geo.XYLine;
|
||||
import org.apache.lucene.geo.XYPolygon;
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
|
||||
import org.elasticsearch.index.mapper.ParseContext;
|
||||
|
||||
@ -71,8 +74,8 @@ public class ShapeIndexer implements AbstractGeometryFieldMapper.Indexer<Geometr
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(org.elasticsearch.geo.geometry.Line line) {
|
||||
float[][] vertices = lineToFloatArray(line.getLons(), line.getLats());
|
||||
public Void visit(Line line) {
|
||||
float[][] vertices = lineToFloatArray(line.getX(), line.getY());
|
||||
addFields(XYShape.createIndexableFields(name, new XYLine(vertices[0], vertices[1])));
|
||||
return null;
|
||||
}
|
||||
@ -84,7 +87,7 @@ public class ShapeIndexer implements AbstractGeometryFieldMapper.Indexer<Geometr
|
||||
|
||||
@Override
|
||||
public Void visit(MultiLine multiLine) {
|
||||
for (org.elasticsearch.geo.geometry.Line line : multiLine) {
|
||||
for (Line line : multiLine) {
|
||||
visit(line);
|
||||
}
|
||||
return null;
|
||||
@ -100,7 +103,7 @@ public class ShapeIndexer implements AbstractGeometryFieldMapper.Indexer<Geometr
|
||||
|
||||
@Override
|
||||
public Void visit(MultiPolygon multiPolygon) {
|
||||
for(org.elasticsearch.geo.geometry.Polygon polygon : multiPolygon) {
|
||||
for(Polygon polygon : multiPolygon) {
|
||||
visit(polygon);
|
||||
}
|
||||
return null;
|
||||
@ -108,21 +111,21 @@ public class ShapeIndexer implements AbstractGeometryFieldMapper.Indexer<Geometr
|
||||
|
||||
@Override
|
||||
public Void visit(Point point) {
|
||||
addFields(XYShape.createIndexableFields(name, (float)point.getLon(), (float)point.getLat()));
|
||||
addFields(XYShape.createIndexableFields(name, (float)point.getX(), (float)point.getY()));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(org.elasticsearch.geo.geometry.Polygon polygon) {
|
||||
public Void visit(Polygon polygon) {
|
||||
addFields(XYShape.createIndexableFields(name, toLucenePolygon(polygon)));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(org.elasticsearch.geo.geometry.Rectangle r) {
|
||||
public Void visit(Rectangle r) {
|
||||
XYPolygon p = new XYPolygon(
|
||||
new float[]{(float)r.getMinLon(), (float)r.getMaxLon(), (float)r.getMaxLon(), (float)r.getMinLon(), (float)r.getMinLon()},
|
||||
new float[]{(float)r.getMinLat(), (float)r.getMinLat(), (float)r.getMaxLat(), (float)r.getMaxLat(), (float)r.getMinLat()});
|
||||
new float[]{(float)r.getMinX(), (float)r.getMaxX(), (float)r.getMaxX(), (float)r.getMinX(), (float)r.getMinX()},
|
||||
new float[]{(float)r.getMinY(), (float)r.getMinY(), (float)r.getMaxY(), (float)r.getMaxY(), (float)r.getMinY()});
|
||||
addFields(XYShape.createIndexableFields(name, p));
|
||||
return null;
|
||||
}
|
||||
@ -132,17 +135,17 @@ public class ShapeIndexer implements AbstractGeometryFieldMapper.Indexer<Geometr
|
||||
}
|
||||
}
|
||||
|
||||
public static XYPolygon toLucenePolygon(org.elasticsearch.geo.geometry.Polygon polygon) {
|
||||
public static XYPolygon toLucenePolygon(Polygon polygon) {
|
||||
XYPolygon[] holes = new XYPolygon[polygon.getNumberOfHoles()];
|
||||
LinearRing ring;
|
||||
float[][] vertices;
|
||||
for(int i = 0; i<holes.length; i++) {
|
||||
ring = polygon.getHole(i);
|
||||
vertices = lineToFloatArray(ring.getLons(), ring.getLats());
|
||||
vertices = lineToFloatArray(ring.getX(), ring.getY());
|
||||
holes[i] = new XYPolygon(vertices[0], vertices[1]);
|
||||
}
|
||||
ring = polygon.getPolygon();
|
||||
vertices = lineToFloatArray(ring.getLons(), ring.getLats());
|
||||
vertices = lineToFloatArray(ring.getX(), ring.getY());
|
||||
return new XYPolygon(vertices[0], vertices[1], holes);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.index.query.AbstractGeometryQueryBuilder;
|
||||
|
@ -15,15 +15,18 @@ import org.apache.lucene.search.MatchNoDocsQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.common.geo.GeoShapeType;
|
||||
import org.elasticsearch.common.geo.ShapeRelation;
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
@ -84,9 +87,9 @@ public class ShapeQueryProcessor implements AbstractGeometryFieldMapper.QueryPro
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query visit(org.elasticsearch.geo.geometry.Line line) {
|
||||
public Query visit(Line line) {
|
||||
return XYShape.newLineQuery(fieldName, relation.getLuceneRelation(),
|
||||
new XYLine(doubleArrayToFloatArray(line.getLons()), doubleArrayToFloatArray(line.getLats())));
|
||||
new XYLine(doubleArrayToFloatArray(line.getX()), doubleArrayToFloatArray(line.getY())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,8 +101,8 @@ public class ShapeQueryProcessor implements AbstractGeometryFieldMapper.QueryPro
|
||||
public Query visit(MultiLine multiLine) {
|
||||
XYLine[] lines = new XYLine[multiLine.size()];
|
||||
for (int i=0; i<multiLine.size(); i++) {
|
||||
lines[i] = new XYLine(doubleArrayToFloatArray(multiLine.get(i).getLons()),
|
||||
doubleArrayToFloatArray(multiLine.get(i).getLats()));
|
||||
lines[i] = new XYLine(doubleArrayToFloatArray(multiLine.get(i).getX()),
|
||||
doubleArrayToFloatArray(multiLine.get(i).getY()));
|
||||
}
|
||||
return XYShape.newLineQuery(fieldName, relation.getLuceneRelation(), lines);
|
||||
}
|
||||
@ -126,18 +129,18 @@ public class ShapeQueryProcessor implements AbstractGeometryFieldMapper.QueryPro
|
||||
@Override
|
||||
public Query visit(Point point) {
|
||||
return XYShape.newBoxQuery(fieldName, relation.getLuceneRelation(),
|
||||
(float)point.getLon(), (float)point.getLon(), (float)point.getLat(), (float)point.getLat());
|
||||
(float)point.getX(), (float)point.getX(), (float)point.getY(), (float)point.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query visit(org.elasticsearch.geo.geometry.Polygon polygon) {
|
||||
public Query visit(Polygon polygon) {
|
||||
return XYShape.newPolygonQuery(fieldName, relation.getLuceneRelation(), toLucenePolygon(polygon));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query visit(org.elasticsearch.geo.geometry.Rectangle r) {
|
||||
public Query visit(Rectangle r) {
|
||||
return XYShape.newBoxQuery(fieldName, relation.getLuceneRelation(),
|
||||
(float)r.getMinLon(), (float)r.getMaxLon(), (float)r.getMinLat(), (float)r.getMaxLat());
|
||||
(float)r.getMinX(), (float)r.getMaxX(), (float)r.getMinY(), (float)r.getMaxY());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,8 @@ import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.ShapeType;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.ShapeType;
|
||||
import org.elasticsearch.index.get.GetResult;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
|
@ -13,8 +13,8 @@ import org.elasticsearch.common.geo.builders.EnvelopeBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.ShapeType;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.ShapeType;
|
||||
import org.elasticsearch.index.query.ExistsQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
|
@ -8,16 +8,16 @@ package org.elasticsearch.xpack.spatial.util;
|
||||
import org.apache.lucene.geo.XShapeTestUtil;
|
||||
import org.apache.lucene.geo.XYPolygon;
|
||||
import org.elasticsearch.geo.GeometryTestUtils;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Polygon;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -72,16 +72,16 @@ public class ShapeTestUtils {
|
||||
List<LinearRing> holes = new ArrayList<>();
|
||||
for (int i = 0; i < lucenePolygon.numHoles(); i++) {
|
||||
XYPolygon poly = luceneHoles[i];
|
||||
holes.add(linearRing(poly.getPolyY(), poly.getPolyX(), hasAlt));
|
||||
holes.add(linearRing(poly.getPolyX(), poly.getPolyY(), hasAlt));
|
||||
}
|
||||
return new Polygon(linearRing(lucenePolygon.getPolyY(), lucenePolygon.getPolyX(), hasAlt), holes);
|
||||
return new Polygon(linearRing(lucenePolygon.getPolyX(), lucenePolygon.getPolyY(), hasAlt), holes);
|
||||
}
|
||||
return new Polygon(linearRing(lucenePolygon.getPolyY(), lucenePolygon.getPolyX(), hasAlt));
|
||||
return new Polygon(linearRing(lucenePolygon.getPolyX(), lucenePolygon.getPolyY(), hasAlt));
|
||||
}
|
||||
|
||||
public static Rectangle randomRectangle() {
|
||||
org.apache.lucene.geo.XYRectangle rectangle = XShapeTestUtil.nextBox();
|
||||
return new Rectangle(rectangle.minY, rectangle.maxY, rectangle.minX, rectangle.maxX);
|
||||
return new Rectangle(rectangle.minX, rectangle.maxX, rectangle.maxY, rectangle.minY);
|
||||
}
|
||||
|
||||
public static MultiPoint randomMultiPoint(boolean hasAlt) {
|
||||
|
@ -5,8 +5,8 @@
|
||||
*/
|
||||
package org.elasticsearch.xpack.sql.jdbc;
|
||||
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
import org.elasticsearch.xpack.sql.proto.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -8,10 +8,10 @@ package org.elasticsearch.xpack.sql.qa.jdbc;
|
||||
|
||||
import com.carrotsearch.hppc.IntObjectHashMap;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
import org.elasticsearch.xpack.sql.jdbc.EsType;
|
||||
import org.elasticsearch.xpack.sql.proto.StringUtils;
|
||||
import org.relique.jdbc.csv.CsvResultSet;
|
||||
@ -78,7 +78,7 @@ public class JdbcAssert {
|
||||
public static void assertResultSets(ResultSet expected, ResultSet actual, Logger logger, boolean lenientDataType) throws SQLException {
|
||||
assertResultSets(expected, actual, logger, lenientDataType, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Assert the given result sets, potentially in a lenient way.
|
||||
* When lenientDataType is specified, the type comparison of a column is widden to reach a common, compatible ground.
|
||||
@ -165,7 +165,7 @@ public class JdbcAssert {
|
||||
if ((expectedType == Types.VARCHAR && expected instanceof CsvResultSet) && nameOf(actualType).startsWith("INTERVAL_")) {
|
||||
expectedType = actualType;
|
||||
}
|
||||
|
||||
|
||||
// csv doesn't support NULL type so skip type checking
|
||||
if (actualType == Types.NULL && expected instanceof CsvResultSet) {
|
||||
expectedType = Types.NULL;
|
||||
@ -177,7 +177,7 @@ public class JdbcAssert {
|
||||
expectedType, actualType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String nameOf(int sqlType) {
|
||||
return SQL_TO_TYPE.get(sqlType).getName();
|
||||
}
|
||||
@ -191,7 +191,7 @@ public class JdbcAssert {
|
||||
throws SQLException {
|
||||
assertResultSetData(expected, actual, logger, lenientDataType, true);
|
||||
}
|
||||
|
||||
|
||||
public static void assertResultSetData(ResultSet expected, ResultSet actual, Logger logger, boolean lenientDataType,
|
||||
boolean lenientFloatingNumbers) throws SQLException {
|
||||
try (ResultSet ex = expected; ResultSet ac = actual) {
|
||||
@ -282,8 +282,8 @@ public class JdbcAssert {
|
||||
// geo points are loaded form doc values where they are stored as long-encoded values leading
|
||||
// to lose in precision
|
||||
assertThat(expectedObject, instanceOf(Point.class));
|
||||
assertEquals(((Point) expectedObject).getLat(), ((Point) actualObject).getLat(), 0.000001d);
|
||||
assertEquals(((Point) expectedObject).getLon(), ((Point) actualObject).getLon(), 0.000001d);
|
||||
assertEquals(((Point) expectedObject).getY(), ((Point) actualObject).getY(), 0.000001d);
|
||||
assertEquals(((Point) expectedObject).getX(), ((Point) actualObject).getX(), 0.000001d);
|
||||
} else {
|
||||
assertEquals(msg, expectedObject, actualObject);
|
||||
}
|
||||
|
@ -17,21 +17,21 @@ import org.elasticsearch.common.xcontent.ToXContentFragment;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.geo.geometry.Circle;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geo.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geo.geometry.Line;
|
||||
import org.elasticsearch.geo.geometry.LinearRing;
|
||||
import org.elasticsearch.geo.geometry.MultiLine;
|
||||
import org.elasticsearch.geo.geometry.MultiPoint;
|
||||
import org.elasticsearch.geo.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geo.geometry.Polygon;
|
||||
import org.elasticsearch.geo.geometry.Rectangle;
|
||||
import org.elasticsearch.geo.utils.StandardValidator;
|
||||
import org.elasticsearch.geo.utils.GeometryValidator;
|
||||
import org.elasticsearch.geo.utils.WellKnownText;
|
||||
import org.elasticsearch.geometry.Circle;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.GeometryCollection;
|
||||
import org.elasticsearch.geometry.GeometryVisitor;
|
||||
import org.elasticsearch.geometry.Line;
|
||||
import org.elasticsearch.geometry.LinearRing;
|
||||
import org.elasticsearch.geometry.MultiLine;
|
||||
import org.elasticsearch.geometry.MultiPoint;
|
||||
import org.elasticsearch.geometry.MultiPolygon;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.geometry.Polygon;
|
||||
import org.elasticsearch.geometry.Rectangle;
|
||||
import org.elasticsearch.geometry.utils.StandardValidator;
|
||||
import org.elasticsearch.geometry.utils.GeometryValidator;
|
||||
import org.elasticsearch.geometry.utils.WellKnownText;
|
||||
import org.elasticsearch.xpack.sql.SqlIllegalArgumentException;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -58,7 +58,7 @@ public class GeoShape implements ToXContentFragment, NamedWriteable {
|
||||
private static final WellKnownText WKT_PARSER = new WellKnownText(true, validator);
|
||||
|
||||
public GeoShape(double lon, double lat) {
|
||||
shape = new Point(lat, lon);
|
||||
shape = new Point(lon, lat);
|
||||
}
|
||||
|
||||
public GeoShape(Object value) throws IOException {
|
||||
@ -101,7 +101,7 @@ public class GeoShape implements ToXContentFragment, NamedWriteable {
|
||||
return shape.visit(new GeometryVisitor<Point, RuntimeException>() {
|
||||
@Override
|
||||
public Point visit(Circle circle) {
|
||||
return new Point(circle.getLat(), circle.getLon(), circle.hasAlt() ? circle.getAlt() : Double.NaN);
|
||||
return new Point(circle.getX(), circle.getY(), circle.hasZ() ? circle.getZ() : Double.NaN);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -115,7 +115,7 @@ public class GeoShape implements ToXContentFragment, NamedWriteable {
|
||||
@Override
|
||||
public Point visit(Line line) {
|
||||
if (line.length() > 0) {
|
||||
return new Point(line.getLat(0), line.getLon(0), line.hasAlt() ? line.getAlt(0) : Double.NaN);
|
||||
return new Point(line.getX(0), line.getY(0), line.hasZ() ? line.getZ(0) : Double.NaN);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -152,24 +152,24 @@ public class GeoShape implements ToXContentFragment, NamedWriteable {
|
||||
|
||||
@Override
|
||||
public Point visit(Rectangle rectangle) {
|
||||
return new Point(rectangle.getMinLat(), rectangle.getMinLon(), rectangle.getMinAlt());
|
||||
return new Point(rectangle.getMinX(), rectangle.getMinY(), rectangle.getMinZ());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Double getX() {
|
||||
Point firstPoint = firstPoint();
|
||||
return firstPoint != null ? firstPoint.getLon() : null;
|
||||
return firstPoint != null ? firstPoint.getX() : null;
|
||||
}
|
||||
|
||||
public Double getY() {
|
||||
Point firstPoint = firstPoint();
|
||||
return firstPoint != null ? firstPoint.getLat() : null;
|
||||
return firstPoint != null ? firstPoint.getY() : null;
|
||||
}
|
||||
|
||||
public Double getZ() {
|
||||
Point firstPoint = firstPoint();
|
||||
return firstPoint != null && firstPoint.hasAlt() ? firstPoint.getAlt() : null;
|
||||
return firstPoint != null && firstPoint.hasZ() ? firstPoint.getZ() : null;
|
||||
}
|
||||
|
||||
public String getGeometryType() {
|
||||
@ -183,10 +183,10 @@ public class GeoShape implements ToXContentFragment, NamedWriteable {
|
||||
if (shape2.shape instanceof Point == false) {
|
||||
throw new SqlIllegalArgumentException("distance calculation is only supported for points; received [{}]", shape2);
|
||||
}
|
||||
double srcLat = ((Point) shape1.shape).getLat();
|
||||
double srcLon = ((Point) shape1.shape).getLon();
|
||||
double dstLat = ((Point) shape2.shape).getLat();
|
||||
double dstLon = ((Point) shape2.shape).getLon();
|
||||
double srcLat = ((Point) shape1.shape).getY();
|
||||
double srcLon = ((Point) shape1.shape).getX();
|
||||
double dstLat = ((Point) shape2.shape).getY();
|
||||
double dstLon = ((Point) shape2.shape).getX();
|
||||
return GeoUtils.arcDistance(srcLat, srcLon, dstLat, dstLon);
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
package org.elasticsearch.xpack.sql.planner;
|
||||
|
||||
import org.elasticsearch.common.time.DateFormatter;
|
||||
import org.elasticsearch.geo.geometry.Geometry;
|
||||
import org.elasticsearch.geo.geometry.Point;
|
||||
import org.elasticsearch.geometry.Geometry;
|
||||
import org.elasticsearch.geometry.Point;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.xpack.sql.SqlIllegalArgumentException;
|
||||
import org.elasticsearch.xpack.sql.expression.Attribute;
|
||||
@ -157,7 +157,7 @@ final class QueryTranslator {
|
||||
new CountAggs(),
|
||||
new DateTimes(),
|
||||
new Firsts(),
|
||||
new Lasts(),
|
||||
new Lasts(),
|
||||
new MADs()
|
||||
);
|
||||
|
||||
@ -679,7 +679,7 @@ final class QueryTranslator {
|
||||
// Since RangeQueryBuilder can handle date as String as well, we'll format it as String and provide the format as well.
|
||||
value = formatter.format((ZonedDateTime) value);
|
||||
} else {
|
||||
formatter = DateFormatter.forPattern(TIME_FORMAT);
|
||||
formatter = DateFormatter.forPattern(TIME_FORMAT);
|
||||
value = formatter.format((OffsetTime) value);
|
||||
}
|
||||
format = formatter.pattern();
|
||||
@ -698,7 +698,7 @@ final class QueryTranslator {
|
||||
if (geometry instanceof Point) {
|
||||
String field = nameOf(stDistance.left());
|
||||
return new GeoDistanceQuery(source, field, ((Number) value).doubleValue(),
|
||||
((Point) geometry).getLat(), ((Point) geometry).getLon());
|
||||
((Point) geometry).getY(), ((Point) geometry).getX());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -787,7 +787,7 @@ final class QueryTranslator {
|
||||
@Override
|
||||
protected QueryTranslation asQuery(Range r, boolean onAggs) {
|
||||
Expression e = r.value();
|
||||
|
||||
|
||||
if (e instanceof NamedExpression) {
|
||||
Query query = null;
|
||||
AggFilter aggFilter = null;
|
||||
@ -810,7 +810,7 @@ final class QueryTranslator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class Scalars extends ExpressionTranslator<ScalarFunction> {
|
||||
|
||||
@Override
|
||||
@ -834,7 +834,7 @@ final class QueryTranslator {
|
||||
//
|
||||
// Agg translators
|
||||
//
|
||||
|
||||
|
||||
static class CountAggs extends SingleValueAggTranslator<Count> {
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user