Skip to content

Commit

Permalink
Geo: implement proper handling of out of bounds geo points (#47734)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
imotov committed Oct 9, 2019
1 parent f8b8afd commit 12e4e7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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
Expand Down Expand Up @@ -161,8 +162,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,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() {
Expand Down

0 comments on commit 12e4e7e

Please sign in to comment.