|
@@ -5,7 +5,7 @@
|
|
|
* 2.0.
|
|
|
*/
|
|
|
|
|
|
-package org.elasticsearch.xpack.spatial.index.query;
|
|
|
+package org.elasticsearch.xpack.spatial.common;
|
|
|
|
|
|
import org.apache.lucene.geo.Component2D;
|
|
|
import org.apache.lucene.geo.GeoUtils;
|
|
@@ -13,46 +13,38 @@ import org.apache.lucene.geo.LatLonGeometry;
|
|
|
import org.apache.lucene.index.PointValues;
|
|
|
import org.apache.lucene.spatial3d.geom.GeoArea;
|
|
|
import org.apache.lucene.spatial3d.geom.GeoAreaFactory;
|
|
|
-import org.apache.lucene.spatial3d.geom.GeoPoint;
|
|
|
import org.apache.lucene.spatial3d.geom.GeoPolygon;
|
|
|
-import org.apache.lucene.spatial3d.geom.GeoPolygonFactory;
|
|
|
import org.apache.lucene.spatial3d.geom.LatLonBounds;
|
|
|
import org.apache.lucene.spatial3d.geom.PlanetModel;
|
|
|
-import org.elasticsearch.h3.CellBoundary;
|
|
|
import org.elasticsearch.h3.H3;
|
|
|
-import org.elasticsearch.h3.LatLng;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
/** Implementation of a lucene {@link LatLonGeometry} that covers the extent of a provided H3 bin. Note that
|
|
|
* H3 bin are polygons on the sphere. */
|
|
|
-class H3LatLonGeometry extends LatLonGeometry {
|
|
|
+class H3SphericalGeometry extends LatLonGeometry {
|
|
|
|
|
|
- private final String h3Address;
|
|
|
+ private final long h3;
|
|
|
|
|
|
- H3LatLonGeometry(String h3Address) {
|
|
|
- this.h3Address = h3Address;
|
|
|
+ H3SphericalGeometry(long h3) {
|
|
|
+ this.h3 = h3;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected Component2D toComponent2D() {
|
|
|
- return new H3Polygon2D(h3Address);
|
|
|
+ return new H3Polygon2D(h3);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean equals(Object o) {
|
|
|
if (this == o) return true;
|
|
|
- if (o instanceof H3LatLonGeometry h3) {
|
|
|
- return Objects.equals(h3Address, h3.h3Address);
|
|
|
+ if (o instanceof H3SphericalGeometry geom) {
|
|
|
+ return h3 == geom.h3;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int hashCode() {
|
|
|
- return Objects.hashCode(h3Address);
|
|
|
+ return Long.hashCode(h3);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -60,7 +52,7 @@ class H3LatLonGeometry extends LatLonGeometry {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.append("H3 : ");
|
|
|
sb.append("\"");
|
|
|
- sb.append(h3Address);
|
|
|
+ sb.append(h3);
|
|
|
sb.append("\"");
|
|
|
return sb.toString();
|
|
|
}
|
|
@@ -75,13 +67,12 @@ class H3LatLonGeometry extends LatLonGeometry {
|
|
|
private final GeoPolygon hexagon;
|
|
|
private final double minX, maxX, minY, maxY;
|
|
|
|
|
|
- private H3Polygon2D(String h3Address) {
|
|
|
- h3 = H3.stringToH3(h3Address);
|
|
|
- res = H3.getResolution(h3Address);
|
|
|
- final CellBoundary cellBoundary = H3.h3ToGeoBoundary(h3Address);
|
|
|
- hexagon = getGeoPolygon(cellBoundary);
|
|
|
+ private H3Polygon2D(long h3) {
|
|
|
+ this.h3 = h3;
|
|
|
+ this.res = H3.getResolution(h3);
|
|
|
+ this.hexagon = H3SphericalUtil.toGeoPolygon(h3);
|
|
|
final LatLonBounds bounds = new LatLonBounds();
|
|
|
- hexagon.getBounds(bounds);
|
|
|
+ this.hexagon.getBounds(bounds);
|
|
|
final double minY = bounds.checkNoBottomLatitudeBound() ? GeoUtils.MIN_LAT_INCL : Math.toDegrees(bounds.getMinLatitude());
|
|
|
final double maxY = bounds.checkNoTopLatitudeBound() ? GeoUtils.MAX_LAT_INCL : Math.toDegrees(bounds.getMaxLatitude());
|
|
|
final double minX;
|
|
@@ -102,15 +93,6 @@ class H3LatLonGeometry extends LatLonGeometry {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private GeoPolygon getGeoPolygon(CellBoundary cellBoundary) {
|
|
|
- final List<GeoPoint> points = new ArrayList<>(cellBoundary.numPoints());
|
|
|
- for (int i = 0; i < cellBoundary.numPoints(); i++) {
|
|
|
- final LatLng latLng = cellBoundary.getLatLon(i);
|
|
|
- points.add(new GeoPoint(PlanetModel.SPHERE, latLng.getLatRad(), latLng.getLonRad()));
|
|
|
- }
|
|
|
- return GeoPolygonFactory.makeGeoPolygon(PlanetModel.SPHERE, points);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public double getMinX() {
|
|
|
return minX;
|