|
@@ -19,6 +19,17 @@
|
|
|
|
|
|
package org.elasticsearch.common.geo;
|
|
|
|
|
|
+import static org.hamcrest.Matchers.containsString;
|
|
|
+import static org.hamcrest.Matchers.instanceOf;
|
|
|
+import static org.hamcrest.Matchers.not;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
import org.apache.lucene.index.IndexableField;
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
@@ -37,14 +48,7 @@ import org.elasticsearch.geometry.Polygon;
|
|
|
import org.elasticsearch.geometry.Rectangle;
|
|
|
import org.elasticsearch.index.mapper.GeoShapeIndexer;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
-import java.io.IOException;
|
|
|
-import java.text.ParseException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import static org.hamcrest.Matchers.instanceOf;
|
|
|
+import org.locationtech.spatial4j.exception.InvalidShapeException;
|
|
|
|
|
|
public class GeometryIndexerTests extends ESTestCase {
|
|
|
|
|
@@ -357,6 +361,15 @@ public class GeometryIndexerTests extends ESTestCase {
|
|
|
actual(polygon(randomBoolean() ? null : randomBoolean(), 20, 0, 20, 10, -20, 10, -20, 0, 20, 0), randomBoolean()));
|
|
|
}
|
|
|
|
|
|
+ public void testInvalidSelfCrossingPolygon() {
|
|
|
+ Polygon polygon = new Polygon(new LinearRing(
|
|
|
+ new double[]{0, 0, 1, 0.5, 1.5, 1, 2, 2, 0}, new double[]{0, 2, 1.9, 1.8, 1.8, 1.9, 2, 0, 0}
|
|
|
+ ));
|
|
|
+ Exception e = expectThrows(InvalidShapeException.class, () -> indexer.prepareForIndexing(polygon));
|
|
|
+ assertThat(e.getMessage(), containsString("Self-intersection at or near point ["));
|
|
|
+ assertThat(e.getMessage(), not(containsString("NaN")));
|
|
|
+ }
|
|
|
+
|
|
|
private XContentBuilder polygon(Boolean orientation, double... val) throws IOException {
|
|
|
XContentBuilder pointGeoJson = XContentFactory.jsonBuilder().startObject();
|
|
|
{
|