Skip to content

Commit

Permalink
Geo: implement proper handling of out of bounds geo points
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 elastic#43916
  • Loading branch information
imotov committed Oct 8, 2019
1 parent 71fab46 commit 02a158c
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 @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 02a158c

Please sign in to comment.