From 12e4e7ef545fa1a567fcaf423ab80d9a0936753a Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Wed, 9 Oct 2019 14:35:54 +0400 Subject: [PATCH] Geo: implement proper handling of out of bounds geo points (#47734) This is the first iteration in improving of handling of out of bounds geopoints with a latitude outside of the -90 - +90 range and a longitude outside of the -180 - +180 range. Relates to #43916 --- .../org/elasticsearch/index/mapper/GeoShapeIndexer.java | 6 ++++-- .../elasticsearch/common/geo/GeometryIndexerTests.java | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeIndexer.java b/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeIndexer.java index 317784baefa..efa490a2357 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeIndexer.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeIndexer.java @@ -51,6 +51,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import static org.apache.lucene.geo.GeoUtils.orient; import static org.elasticsearch.common.geo.GeoUtils.normalizeLat; import static org.elasticsearch.common.geo.GeoUtils.normalizeLon; +import static org.elasticsearch.common.geo.GeoUtils.normalizePoint; /** * Utility class that converts geometries into Lucene-compatible form @@ -161,8 +162,9 @@ 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.getX(), point.getY()); + double[] latlon = new double[]{point.getX(), point.getY()}; + normalizePoint(latlon); + return new Point(latlon[0], latlon[1]); } @Override diff --git a/server/src/test/java/org/elasticsearch/common/geo/GeometryIndexerTests.java b/server/src/test/java/org/elasticsearch/common/geo/GeometryIndexerTests.java index 0b2f2945aba..24b135be5c6 100644 --- a/server/src/test/java/org/elasticsearch/common/geo/GeometryIndexerTests.java +++ b/server/src/test/java/org/elasticsearch/common/geo/GeometryIndexerTests.java @@ -222,6 +222,15 @@ public class GeometryIndexerTests extends ESTestCase { point = new Point(2, 1, 3); assertEquals(indexed, indexer.prepareForIndexing(point)); + + point = new Point(362, 1); + assertEquals(indexed, indexer.prepareForIndexing(point)); + + point = new Point(-178, 179); + assertEquals(indexed, indexer.prepareForIndexing(point)); + + point = new Point(180, 180); + assertEquals(new Point(0, 0), indexer.prepareForIndexing(point)); } public void testMultiPoint() {