-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alternative algorithm for inflated bounds
The BoundedGeoHexGridTiler inflates the bounding box for parent cell searches since the parent cells bounds do not match the descendents. This algorithm does a slightly more refined calculation of the inflation factor by considering all four corners and inflating in the four directions independently.
- Loading branch information
1 parent
c0e702c
commit 4d98839
Showing
4 changed files
with
509 additions
and
15 deletions.
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
47 changes: 47 additions & 0 deletions
47
...ack/spatial/search/aggregations/bucket/geogrid/BoundedGeoHexGridTilerAllCornersTests.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,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.spatial.search.aggregations.bucket.geogrid; | ||
|
||
import org.elasticsearch.common.geo.GeoBoundingBox; | ||
import org.elasticsearch.geometry.Rectangle; | ||
|
||
import static org.elasticsearch.xpack.spatial.search.aggregations.bucket.geogrid.GeoHexGridTiler.BoundedGeoHexGridTiler.wAvg; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
/** | ||
* The new algorithm calculates the inflation as a weighted average of the original bounds | ||
* and the bounds of the cells at all four corners of the bbox. | ||
*/ | ||
public class BoundedGeoHexGridTilerAllCornersTests extends BoundedGeoHexGridTilerTests { | ||
|
||
@Override | ||
protected GeoBoundingBox inflateBbox(int precision, GeoBoundingBox bbox, double factor) { | ||
return GeoHexGridTiler.BoundedGeoHexGridTiler.inflateBbox2(precision, bbox, factor); | ||
} | ||
|
||
@Override | ||
/* Calculate the bounds of the h3 cell assuming the test bbox is entirely within the cell */ | ||
protected Rectangle getFullBounds(Rectangle bounds, GeoBoundingBox bbox) { | ||
return bounds; | ||
} | ||
|
||
public void testBoundedTilerInflation_WeightedAverages() { | ||
assertThat("Weighted average 0.5 (pos)", wAvg(10, 20, 0.5), equalTo(15.0)); | ||
assertThat("Weighted average 0.5 (neg)", wAvg(-10, -20, 0.5), equalTo(-15.0)); | ||
assertThat("Weighted average 0.5", wAvg(-10, 10, 0.5), equalTo(0.0)); | ||
assertThat("Weighted average 0.0 (pos)", wAvg(10, 20, 0.0), equalTo(10.0)); | ||
assertThat("Weighted average 0.0 (neg)", wAvg(-10, -20, 0.0), equalTo(-10.0)); | ||
assertThat("Weighted average 0.0", wAvg(-10, 10, 0.0), equalTo(-10.0)); | ||
assertThat("Weighted average 1.0 (pos)", wAvg(10, 20, 1.0), equalTo(20.0)); | ||
assertThat("Weighted average 1.0 (neg)", wAvg(-10, -20, 1.0), equalTo(-20.0)); | ||
assertThat("Weighted average 1.0", wAvg(-10, 10, 1.0), equalTo(10.0)); | ||
assertThat("Weighted average 2.0 (pos)", wAvg(10, 20, 2.0), equalTo(30.0)); | ||
assertThat("Weighted average 2.0 (neg)", wAvg(-10, -20, 2.0), equalTo(-30.0)); | ||
assertThat("Weighted average 2.0", wAvg(-10, 10, 2.0), equalTo(30.0)); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...xpack/spatial/search/aggregations/bucket/geogrid/BoundedGeoHexGridTilerMaxWidthTests.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,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.spatial.search.aggregations.bucket.geogrid; | ||
|
||
import org.elasticsearch.common.geo.GeoBoundingBox; | ||
import org.elasticsearch.common.geo.GeoUtils; | ||
import org.elasticsearch.geometry.Rectangle; | ||
|
||
import static org.elasticsearch.xpack.spatial.search.aggregations.bucket.geogrid.GeoHexGridTiler.BoundedGeoHexGridTiler.height; | ||
import static org.elasticsearch.xpack.spatial.search.aggregations.bucket.geogrid.GeoHexGridTiler.BoundedGeoHexGridTiler.width; | ||
|
||
/** | ||
* The original algorithm inflates using the max size of cells at two corners of the bbox. | ||
*/ | ||
public class BoundedGeoHexGridTilerMaxWidthTests extends BoundedGeoHexGridTilerTests { | ||
|
||
@Override | ||
protected GeoBoundingBox inflateBbox(int precision, GeoBoundingBox bbox, double factor) { | ||
return GeoHexGridTiler.BoundedGeoHexGridTiler.inflateBbox(precision, bbox, factor); | ||
} | ||
|
||
@Override | ||
/* Calculate the bounds of the h3 cell assuming the test bbox is entirely within the cell */ | ||
protected Rectangle getFullBounds(Rectangle bounds, GeoBoundingBox bbox) { | ||
final double height = height(bounds); | ||
final double width = width(bounds); | ||
// inflate the coordinates by the full width and height | ||
final double minY = Math.max(bbox.bottom() - height, -90d); | ||
final double maxY = Math.min(bbox.top() + height, 90d); | ||
final double left = GeoUtils.normalizeLon(bbox.left() - width); | ||
final double right = GeoUtils.normalizeLon(bbox.right() + width); | ||
if (2 * width + width(bbox) >= 360d) { | ||
// if the total width is bigger than the world, then it covers all longitude range. | ||
return new Rectangle(-180, 180, maxY, minY); | ||
} else { | ||
return new Rectangle(left, right, maxY, minY); | ||
} | ||
} | ||
} |
Oops, something went wrong.