Skip to content

Commit 12e4e7e

Browse files
committed
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
1 parent f8b8afd commit 12e4e7e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

server/src/main/java/org/elasticsearch/index/mapper/GeoShapeIndexer.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import static org.apache.lucene.geo.GeoUtils.orient;
5252
import static org.elasticsearch.common.geo.GeoUtils.normalizeLat;
5353
import static org.elasticsearch.common.geo.GeoUtils.normalizeLon;
54+
import static org.elasticsearch.common.geo.GeoUtils.normalizePoint;
5455

5556
/**
5657
* Utility class that converts geometries into Lucene-compatible form
@@ -161,8 +162,9 @@ public Geometry visit(MultiPolygon multiPolygon) {
161162

162163
@Override
163164
public Geometry visit(Point point) {
164-
//TODO: Just remove altitude for now. We need to add normalization later
165-
return new Point(point.getX(), point.getY());
165+
double[] latlon = new double[]{point.getX(), point.getY()};
166+
normalizePoint(latlon);
167+
return new Point(latlon[0], latlon[1]);
166168
}
167169

168170
@Override

server/src/test/java/org/elasticsearch/common/geo/GeometryIndexerTests.java

+9
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ public void testPoint() {
222222

223223
point = new Point(2, 1, 3);
224224
assertEquals(indexed, indexer.prepareForIndexing(point));
225+
226+
point = new Point(362, 1);
227+
assertEquals(indexed, indexer.prepareForIndexing(point));
228+
229+
point = new Point(-178, 179);
230+
assertEquals(indexed, indexer.prepareForIndexing(point));
231+
232+
point = new Point(180, 180);
233+
assertEquals(new Point(0, 0), indexer.prepareForIndexing(point));
225234
}
226235

227236
public void testMultiPoint() {

0 commit comments

Comments
 (0)