-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Add support for distance queries on shape queries #53468
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/ShapeUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.spatial.index.mapper; | ||
|
||
import org.elasticsearch.geometry.Circle; | ||
import org.elasticsearch.geometry.Line; | ||
import org.elasticsearch.geometry.Point; | ||
import org.elasticsearch.geometry.Polygon; | ||
import org.elasticsearch.geometry.Rectangle; | ||
|
||
|
||
/** | ||
* Utility class that transforms Elasticsearch geometry objects to the Lucene representation | ||
*/ | ||
public class ShapeUtils { | ||
|
||
public static org.apache.lucene.geo.XYPolygon toLuceneXYPolygon(Polygon polygon) { | ||
org.apache.lucene.geo.XYPolygon[] holes = new org.apache.lucene.geo.XYPolygon[polygon.getNumberOfHoles()]; | ||
for(int i = 0; i<holes.length; i++) { | ||
holes[i] = new org.apache.lucene.geo.XYPolygon( | ||
doubleArrayToFloatArray(polygon.getHole(i).getX()), | ||
doubleArrayToFloatArray(polygon.getHole(i).getY())); | ||
} | ||
return new org.apache.lucene.geo.XYPolygon( | ||
doubleArrayToFloatArray(polygon.getPolygon().getX()), | ||
doubleArrayToFloatArray(polygon.getPolygon().getY()), holes); | ||
} | ||
|
||
public static org.apache.lucene.geo.XYPolygon toLuceneXYPolygon(Rectangle r) { | ||
return new org.apache.lucene.geo.XYPolygon( | ||
new float[]{(float) r.getMinX(), (float) r.getMaxX(), (float) r.getMaxX(), (float) r.getMinX(), (float) r.getMinX()}, | ||
new float[]{(float) r.getMinY(), (float) r.getMinY(), (float) r.getMaxY(), (float) r.getMaxY(), (float) r.getMinY()}); | ||
} | ||
|
||
public static org.apache.lucene.geo.XYRectangle toLuceneXYRectangle(Rectangle r) { | ||
return new org.apache.lucene.geo.XYRectangle((float) r.getMinX(), (float) r.getMaxX(), | ||
(float) r.getMinY(), (float) r.getMaxY()); | ||
} | ||
|
||
public static org.apache.lucene.geo.XYPoint toLuceneXYPoint(Point point) { | ||
return new org.apache.lucene.geo.XYPoint((float) point.getX(), (float) point.getY()); | ||
} | ||
|
||
public static org.apache.lucene.geo.XYLine toLuceneXYLine(Line line) { | ||
return new org.apache.lucene.geo.XYLine( | ||
doubleArrayToFloatArray(line.getX()), | ||
doubleArrayToFloatArray(line.getY())); | ||
} | ||
|
||
public static org.apache.lucene.geo.XYCircle toLuceneXYCircle(Circle circle) { | ||
return new org.apache.lucene.geo.XYCircle((float) circle.getX(), (float) circle.getY(), (float) circle.getRadiusMeters()); | ||
} | ||
|
||
private ShapeUtils() { | ||
} | ||
|
||
private static float[] doubleArrayToFloatArray(double[] array) { | ||
float[] result = new float[array.length]; | ||
for (int i = 0; i < array.length; ++i) { | ||
result[i] = (float) array[i]; | ||
} | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems our circle interface does not really support cartesian circles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it is a bit misleading to have the Geometry API specify the circle radius as
getRadiusMeters
. Probably worth a clean up in another PR. /cc @imotovThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I am not particularly happy with my decision to go with meters here. I think it was a mistake. I agree we need to clean this up, but it probably deserves some brainstorming and definitely a separate PR since it affects SQL as well.