Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geo: Don't flip longitude of envelopes crossing dateline #34535

Merged

Conversation

imotov
Copy link
Contributor

@imotov imotov commented Oct 16, 2018

When a envelope that crosses the dateline is specified as a part of
geo_shape query is parsed it shouldn't have its left and right points
flipped.

Fixes #34418

When a envelope that crosses the dateline is specified as a part of
geo_shape query is parsed it shouldn't have its left and right points
flipped.

Fixes elastic#34418
@imotov imotov added >bug :Analytics/Geo Indexing, search aggregations of geo points and shapes v7.0.0 v6.5.0 labels Oct 16, 2018
@imotov imotov requested review from nknize and iverase October 16, 2018 19:28
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@iverase
Copy link
Contributor

iverase commented Oct 17, 2018

It is interesting to see that there was a test to actually check this coercing. I think I would like @nknize to comment here in case this coerce has been added for some use case I am not aware of. Still it seems wrong because it does not allow to build envelopes that crosses the dateline.

In the meanwhile I had a look into the documentation:

https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html#_envelope

The definition is a bit open:

Elasticsearch supports an envelope type, which consists of coordinates for upper left and lower right points of the shape to represent a bounding rectangle:

If we go for this change we should updated it and define that oder of the coordinates is important:

Elasticsearch supports an envelope type, which consists of coordinates for upper left and lower right points of the shape to represent a bounding rectangle in the format [[minLon, maxLat],[maxLon, minLat]]:

WDYT?

@iverase
Copy link
Contributor

iverase commented Oct 17, 2018

And thinking about WKT, It would be interesting to test that providing the envelope in Elasticsearch format gives the same result than when it is given in WKT.

@nknize
Copy link
Contributor

nknize commented Oct 17, 2018

Its been a while, but IIRC the coercion test was for the case where a user provides TopRight, BottomLeft instead of TopLeft, BottomRight. I think for this case the bug is: if (((lR.x < uL.x) || (uL.y < lR.y))) should instead be a logical AND: if (((lR.x < uL.x) && (uL.y < lR.y))) ? Otherwise the envelope is implied to cross the dateline?

+1 for making the doc change.

@iverase
Copy link
Contributor

iverase commented Oct 17, 2018

I don't think coerce can never work because when crossing the dateline then the envelope will be ilegal . We should remove it and change docs to make the order more explicit.

@nknize
Copy link
Contributor

nknize commented Oct 18, 2018

It should work if the logic is changed to &&? In that case the envelope crosses the dateline since upperLeft.y > lowerRight.y but upperLeft.x < lowerRight.x. Either way, I'm also fine with removing the leniency and requiring explicit order. Though I think we should note it in breaking changes in case users have relied on coerce to correct the order for them.

@iverase
Copy link
Contributor

iverase commented Oct 18, 2018

Sorry I didn't explained myself properly. It works when providing the right coordinates.
But if a user provides the bottomLeft and the upperRight coordinates, then they will be corrected except when crossing the dateline where they will get an error. That is what I would like to avoid.

@nknize
Copy link
Contributor

nknize commented Oct 18, 2018

👍 We would need to correct for that but I agree that the code starts getting far too hairy to support the leniency. +1 for requiring explicit order and documenting in breaking changes. In this case coerce should only be used for normalizing coordinates to -180 : 180 and -90 : 90.

@imotov imotov merged commit 94bde37 into elastic:master Oct 19, 2018
imotov added a commit that referenced this pull request Oct 19, 2018
When a envelope that crosses the dateline is specified as a part of
geo_shape query is parsed it shouldn't have its left and right points
flipped.

Fixes #34418
kcm pushed a commit that referenced this pull request Oct 30, 2018
When a envelope that crosses the dateline is specified as a part of
geo_shape query is parsed it shouldn't have its left and right points
flipped.

Fixes #34418
@imotov imotov deleted the issue-34418-geo-shape-query-dateline-rest branch May 1, 2020 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes >breaking >bug v6.5.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants