-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add bounds support for geogrid agg on shapes #51973
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
Merged
talevy
merged 15 commits into
elastic:geoshape-doc-values
from
talevy:gdv-shape-grid-bounds
Mar 2, 2020
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d537b33
Add bounds support for geogrid agg on shapes
talevy 6d7d8d6
fix behavior of tree relate
talevy d4d99f4
Merge branch 'geoshape-doc-values' into gdv-shape-grid-bounds
talevy b0de38e
small cleanup
talevy 38c508d
Fix checkstyle
talevy 4ae9e67
in silico
talevy ef26c35
Merge remote-tracking branch 'elastic/geoshape-doc-values' into gdv-s…
talevy fcc52f7
fix tests
talevy 805eb5a
remove unused test code
talevy 1741d0e
fix checkstyle
talevy 0d60301
Merge remote-tracking branch 'elastic/geoshape-doc-values' into gdv-s…
talevy 80d1a25
Merge remote-tracking branch 'elastic/geoshape-doc-values' into gdv-s…
talevy 25d694e
Merge remote-tracking branch 'elastic/geoshape-doc-values' into gdv-s…
talevy a62474e
Refactor to make Bounded Tilers
talevy cedc60d
fix geohash and other edge case tests
talevy 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -316,6 +316,5 @@ public double minX() { | |
public double maxX() { | ||
return Math.max(negRight, posRight); | ||
} | ||
|
||
} | ||
} |
This file contains hidden or 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
108 changes: 108 additions & 0 deletions
108
...in/java/org/elasticsearch/search/aggregations/bucket/geogrid/BoundedGeoHashGridTiler.java
This file contains hidden or 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,108 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.search.aggregations.bucket.geogrid; | ||
|
||
import org.elasticsearch.common.geo.GeoBoundingBox; | ||
import org.elasticsearch.common.geo.GeoRelation; | ||
import org.elasticsearch.geometry.Rectangle; | ||
import org.elasticsearch.geometry.utils.Geohash; | ||
import org.elasticsearch.index.fielddata.MultiGeoValues; | ||
|
||
public class BoundedGeoHashGridTiler extends GeoHashGridTiler { | ||
private final double boundsTop; | ||
private final double boundsBottom; | ||
private final double boundsWestLeft; | ||
private final double boundsWestRight; | ||
private final double boundsEastLeft; | ||
private final double boundsEastRight; | ||
private final boolean crossesDateline; | ||
|
||
BoundedGeoHashGridTiler(GeoBoundingBox geoBoundingBox) { | ||
// split geoBoundingBox into west and east boxes | ||
boundsTop = geoBoundingBox.top(); | ||
boundsBottom = geoBoundingBox.bottom(); | ||
if (geoBoundingBox.right() < geoBoundingBox.left()) { | ||
boundsWestLeft = -180; | ||
boundsWestRight = geoBoundingBox.right(); | ||
boundsEastLeft = geoBoundingBox.left(); | ||
boundsEastRight = 180; | ||
crossesDateline = true; | ||
} else { // only set east bounds | ||
boundsEastLeft = geoBoundingBox.left(); | ||
boundsEastRight = geoBoundingBox.right(); | ||
boundsWestLeft = 0; | ||
boundsWestRight = 0; | ||
crossesDateline = false; | ||
} | ||
} | ||
|
||
@Override | ||
public int advancePointValue(long[] values, double x, double y, int precision, int valuesIdx) { | ||
long hash = encode(x, y, precision); | ||
if (cellIntersectsGeoBoundingBox(Geohash.toBoundingBox(Geohash.stringEncode(hash)))) { | ||
values[valuesIdx] = hash; | ||
return valuesIdx + 1; | ||
} | ||
return valuesIdx; | ||
} | ||
|
||
boolean cellIntersectsGeoBoundingBox(Rectangle rectangle) { | ||
return (boundsTop >= rectangle.getMinY() && boundsBottom <= rectangle.getMaxY() | ||
&& (boundsEastLeft <= rectangle.getMaxX() && boundsEastRight >= rectangle.getMinX() | ||
|| (crossesDateline && boundsWestLeft <= rectangle.getMaxX() && boundsWestRight >= rectangle.getMinX()))); | ||
} | ||
|
||
@Override | ||
protected int setValue(CellValues docValues, MultiGeoValues.GeoValue geoValue, MultiGeoValues.BoundingBox bounds, int precision) { | ||
String hash = Geohash.stringEncode(bounds.minX(), bounds.minY(), precision); | ||
GeoRelation relation = relateTile(geoValue, hash); | ||
if (relation != GeoRelation.QUERY_DISJOINT) { | ||
docValues.resizeCell(1); | ||
docValues.add(0, Geohash.longEncode(hash)); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
@Override | ||
protected GeoRelation relateTile(MultiGeoValues.GeoValue geoValue, String hash) { | ||
Rectangle rectangle = Geohash.toBoundingBox(hash); | ||
if (cellIntersectsGeoBoundingBox(rectangle)) { | ||
return geoValue.relate(rectangle); | ||
} else { | ||
return GeoRelation.QUERY_DISJOINT; | ||
} | ||
} | ||
|
||
@Override | ||
protected int setValuesForFullyContainedTile(String hash, CellValues values, | ||
int valuesIndex, int targetPrecision) { | ||
String[] hashes = Geohash.getSubGeohashes(hash); | ||
for (int i = 0; i < hashes.length; i++) { | ||
if (hashes[i].length() == targetPrecision ) { | ||
if (cellIntersectsGeoBoundingBox(Geohash.toBoundingBox(hashes[i]))) { | ||
values.add(valuesIndex++, Geohash.longEncode(hashes[i])); | ||
} | ||
} else { | ||
valuesIndex = setValuesForFullyContainedTile(hashes[i], values, valuesIndex, targetPrecision); | ||
} | ||
} | ||
return valuesIndex; | ||
} | ||
} |
48 changes: 0 additions & 48 deletions
48
.../java/org/elasticsearch/search/aggregations/bucket/geogrid/BoundedGeoPointCellValues.java
This file was deleted.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
...in/java/org/elasticsearch/search/aggregations/bucket/geogrid/BoundedGeoTileGridTiler.java
This file contains hidden or 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,107 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.search.aggregations.bucket.geogrid; | ||
|
||
import org.elasticsearch.common.geo.GeoBoundingBox; | ||
import org.elasticsearch.common.geo.GeoRelation; | ||
import org.elasticsearch.geometry.Rectangle; | ||
import org.elasticsearch.index.fielddata.MultiGeoValues; | ||
|
||
public class BoundedGeoTileGridTiler extends GeoTileGridTiler { | ||
private final double boundsTop; | ||
private final double boundsBottom; | ||
private final double boundsWestLeft; | ||
private final double boundsWestRight; | ||
private final double boundsEastLeft; | ||
private final double boundsEastRight; | ||
private final boolean crossesDateline; | ||
|
||
public BoundedGeoTileGridTiler(GeoBoundingBox geoBoundingBox) { | ||
// split geoBoundingBox into west and east boxes | ||
boundsTop = geoBoundingBox.top(); | ||
boundsBottom = geoBoundingBox.bottom(); | ||
if (geoBoundingBox.right() < geoBoundingBox.left()) { | ||
boundsWestLeft = -180; | ||
boundsWestRight = geoBoundingBox.right(); | ||
boundsEastLeft = geoBoundingBox.left(); | ||
boundsEastRight = 180; | ||
crossesDateline = true; | ||
} else { // only set east bounds | ||
boundsEastLeft = geoBoundingBox.left(); | ||
boundsEastRight = geoBoundingBox.right(); | ||
boundsWestLeft = 0; | ||
boundsWestRight = 0; | ||
crossesDateline = false; | ||
} | ||
} | ||
|
||
public int advancePointValue(long[] values, double x, double y, int precision, int valuesIdx) { | ||
long hash = encode(x, y, precision); | ||
if (cellIntersectsGeoBoundingBox(GeoTileUtils.toBoundingBox(hash))) { | ||
values[valuesIdx] = hash; | ||
return valuesIdx + 1; | ||
} | ||
return valuesIdx; | ||
} | ||
|
||
boolean cellIntersectsGeoBoundingBox(Rectangle rectangle) { | ||
return (boundsTop >= rectangle.getMinY() && boundsBottom <= rectangle.getMaxY() | ||
&& (boundsEastLeft <= rectangle.getMaxX() && boundsEastRight >= rectangle.getMinX() | ||
|| (crossesDateline && boundsWestLeft <= rectangle.getMaxX() && boundsWestRight >= rectangle.getMinX()))); | ||
} | ||
|
||
@Override | ||
public GeoRelation relateTile(MultiGeoValues.GeoValue geoValue, int xTile, int yTile, int precision) { | ||
Rectangle rectangle = GeoTileUtils.toBoundingBox(xTile, yTile, precision); | ||
if (cellIntersectsGeoBoundingBox(rectangle)) { | ||
talevy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return geoValue.relate(rectangle); | ||
} | ||
return GeoRelation.QUERY_DISJOINT; | ||
} | ||
|
||
@Override | ||
protected int setValue(CellValues docValues, MultiGeoValues.GeoValue geoValue, int xTile, int yTile, int precision) { | ||
if (cellIntersectsGeoBoundingBox(GeoTileUtils.toBoundingBox(xTile, yTile, precision))) { | ||
docValues.resizeCell(1); | ||
docValues.add(0, GeoTileUtils.longEncodeTiles(precision, xTile, yTile)); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
@Override | ||
protected int setValuesForFullyContainedTile(int xTile, int yTile, int zTile, CellValues values, int valuesIndex, | ||
int targetPrecision) { | ||
zTile++; | ||
for (int i = 0; i < 2; i++) { | ||
for (int j = 0; j < 2; j++) { | ||
int nextX = 2 * xTile + i; | ||
int nextY = 2 * yTile + j; | ||
if (zTile == targetPrecision) { | ||
if (cellIntersectsGeoBoundingBox(GeoTileUtils.toBoundingBox(nextX, nextY, zTile))) { | ||
values.add(valuesIndex++, GeoTileUtils.longEncodeTiles(zTile, nextX, nextY)); | ||
} | ||
} else { | ||
valuesIndex = setValuesForFullyContainedTile(nextX, nextY, zTile, values, valuesIndex, targetPrecision); | ||
} | ||
} | ||
} | ||
return valuesIndex; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.