From 02a158cd7d9ad70de2541b828ca062bb02c1f1c7 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Tue, 8 Oct 2019 19:21:10 +0400 Subject: [PATCH] Geo: implement proper handling of out of bounds geo points 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 54fb9a97a8658..364694dd0a276 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeIndexer.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/GeoShapeIndexer.java @@ -50,6 +50,7 @@ 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 @@ -160,8 +161,9 @@ public Geometry visit(MultiPolygon multiPolygon) { @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 47b02ea698112..ba3f55afea987 100644 --- a/server/src/test/java/org/elasticsearch/common/geo/GeometryIndexerTests.java +++ b/server/src/test/java/org/elasticsearch/common/geo/GeometryIndexerTests.java @@ -137,6 +137,15 @@ public void testPoint() { 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() {