/** * Turns quantized value from byte array back into a double. * @param src byte array containing 4 bytes to decode at {@code offset} * @param offset offset into {@code src} to decode from. * @return decoded longitude value. */ public static double decodeLongitude(byte[] src, int offset) { return decodeLongitude(NumericUtils.sortableBytesToInt(src, offset)); }
@Override protected String toString(int dimension, byte[] value) { if (dimension == 0) { return Double.toString(decodeLatitude(value, 0)); } else if (dimension == 1) { return Double.toString(decodeLongitude(value, 0)); } else { throw new AssertionError(); } } };
@Override public String toString() { StringBuilder result = new StringBuilder(); result.append(getClass().getSimpleName()); result.append(" <"); result.append(name); result.append(':'); long currentValue = (Long)fieldsData; result.append(decodeLatitude((int)(currentValue >> 32))); result.append(','); result.append(decodeLongitude((int)(currentValue & 0xFFFFFFFF))); result.append('>'); return result.toString(); }
@Override public String toString(String field) { StringBuilder sb = new StringBuilder(); if (!this.field.equals(field)) { sb.append(this.field); sb.append(':'); } sb.append("box(minLat=").append(GeoEncodingUtils.decodeLatitude(minLatitude)); sb.append(", maxLat=").append(GeoEncodingUtils.decodeLatitude(maxLatitude)); sb.append(", minLon=").append(GeoEncodingUtils.decodeLongitude(minLongitude)); sb.append(", maxLon=").append(GeoEncodingUtils.decodeLongitude(maxLongitude)); return sb.append(")").toString(); }
@Override public String toString() { StringBuilder result = new StringBuilder(); result.append(getClass().getSimpleName()); result.append(" <"); result.append(name); result.append(':'); byte bytes[] = ((BytesRef) fieldsData).bytes; result.append(decodeLatitude(bytes, 0)); result.append(','); result.append(decodeLongitude(bytes, Integer.BYTES)); result.append('>'); return result.toString(); }
double docLongitude = decodeLongitude(longitudeBits); cmp = Math.max(cmp, Double.compare(bottom, SloppyMath.haversinSortKey(latitude, longitude, docLatitude, docLongitude)));
double sortKey(int doc) throws IOException { if (doc > currentDocs.docID()) { currentDocs.advance(doc); } double minValue = Double.POSITIVE_INFINITY; if (doc == currentDocs.docID()) { setValues(); int numValues = currentDocs.docValueCount(); for (int i = 0; i < numValues; i++) { long encoded = currentValues[i]; double docLatitude = decodeLatitude((int)(encoded >> 32)); double docLongitude = decodeLongitude((int)(encoded & 0xFFFFFFFF)); minValue = Math.min(minValue, SloppyMath.haversinSortKey(latitude, longitude, docLatitude, docLongitude)); } } return minValue; }
/** Check whether the given point is within the considered polygon. * NOTE: this operates directly on the encoded representation of points. */ public boolean test(int lat, int lon) { final int lat2 = ((lat - Integer.MIN_VALUE) >>> latShift); if (lat2 < latBase || lat2 >= latBase + maxLatDelta) { return false; } int lon2 = ((lon - Integer.MIN_VALUE) >>> lonShift); if (lon2 < lonBase) { // wrap lon2 += 1 << (32 - lonShift); } assert Integer.toUnsignedLong(lon2) >= lonBase; assert lon2 - lonBase >= 0; if (lon2 - lonBase >= maxLonDelta) { return false; } final int relation = relations[(lat2 - latBase) * maxLonDelta + (lon2 - lonBase)]; if (relation == Relation.CELL_CROSSES_QUERY.ordinal()) { return tree.contains(decodeLatitude(lat), decodeLongitude(lon)); } else { return relation == Relation.CELL_INSIDE_QUERY.ordinal(); } } }
/** Check whether the given point is within a distance of another point. * NOTE: this operates directly on the encoded representation of points. */ public boolean test(int lat, int lon) { final int lat2 = ((lat - Integer.MIN_VALUE) >>> latShift); if (lat2 < latBase || lat2 >= latBase + maxLatDelta) { return false; } int lon2 = ((lon - Integer.MIN_VALUE) >>> lonShift); if (lon2 < lonBase) { // wrap lon2 += 1 << (32 - lonShift); } assert Integer.toUnsignedLong(lon2) >= lonBase; assert lon2 - lonBase >= 0; if (lon2 - lonBase >= maxLonDelta) { return false; } final int relation = relations[(lat2 - latBase) * maxLonDelta + (lon2 - lonBase)]; if (relation == Relation.CELL_CROSSES_QUERY.ordinal()) { return SloppyMath.haversinSortKey( decodeLatitude(lat), decodeLongitude(lon), this.lat, this.lon) <= distanceKey; } else { return relation == Relation.CELL_INSIDE_QUERY.ordinal(); } } }
public static double decodeLongitude(long encodedLatLon) { return GeoEncodingUtils.decodeLongitude((int) (encodedLatLon & 0xFFFFFFFFL)); }
decodeLongitude(boxMinLon), decodeLongitude(boxMaxLon))).ordinal();
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("Rectangle(lat="); sb.append(decodeLatitude(minY)); sb.append(" TO "); sb.append(decodeLatitude(maxY)); sb.append(" lon="); sb.append(decodeLongitude(minX)); sb.append(" TO "); sb.append(decodeLongitude(maxX)); if (maxX < minX) { sb.append(" [crosses dateline!]"); } sb.append(")"); return sb.toString(); } }
@Override protected boolean queryMatches(byte[] t, int[] scratchTriangle) { XLatLonShape.decodeTriangle(t, scratchTriangle); double alat = GeoEncodingUtils.decodeLatitude(scratchTriangle[0]); double alon = GeoEncodingUtils.decodeLongitude(scratchTriangle[1]); double blat = GeoEncodingUtils.decodeLatitude(scratchTriangle[2]); double blon = GeoEncodingUtils.decodeLongitude(scratchTriangle[3]); double clat = GeoEncodingUtils.decodeLatitude(scratchTriangle[4]); double clon = GeoEncodingUtils.decodeLongitude(scratchTriangle[5]); if (queryRelation == QueryRelation.WITHIN) { return poly2D.relateTriangle(alon, alat, blon, blat, clon, clat) == Relation.CELL_INSIDE_QUERY; } // INTERSECTS return poly2D.relateTriangle(alon, alat, blon, blat, clon, clat) != Relation.CELL_OUTSIDE_QUERY; }
@Override protected boolean queryMatches(byte[] t, int[] scratchTriangle) { XLatLonShape.decodeTriangle(t, scratchTriangle); double alat = GeoEncodingUtils.decodeLatitude(scratchTriangle[0]); double alon = GeoEncodingUtils.decodeLongitude(scratchTriangle[1]); double blat = GeoEncodingUtils.decodeLatitude(scratchTriangle[2]); double blon = GeoEncodingUtils.decodeLongitude(scratchTriangle[3]); double clat = GeoEncodingUtils.decodeLatitude(scratchTriangle[4]); double clon = GeoEncodingUtils.decodeLongitude(scratchTriangle[5]); if (queryRelation == XLatLonShape.QueryRelation.WITHIN) { return line2D.relateTriangle(alon, alat, blon, blat, clon, clat) == Relation.CELL_INSIDE_QUERY; } // INTERSECTS return line2D.relateTriangle(alon, alat, blon, blat, clon, clat) != Relation.CELL_OUTSIDE_QUERY; }
@Override public GeoPoint nextValue() throws IOException { final long encoded = numericValues.nextValue(); point.reset(GeoEncodingUtils.decodeLatitude((int) (encoded >>> 32)), GeoEncodingUtils.decodeLongitude((int) encoded)); return point; } };
public GeoPoint resetFromIndexableField(IndexableField field) { if (field instanceof LatLonPoint) { BytesRef br = field.binaryValue(); byte[] bytes = Arrays.copyOfRange(br.bytes, br.offset, br.length); return this.reset( GeoEncodingUtils.decodeLatitude(bytes, 0), GeoEncodingUtils.decodeLongitude(bytes, Integer.BYTES)); } else if (field instanceof LatLonDocValuesField) { long encoded = (long)(field.numericValue()); return this.reset( GeoEncodingUtils.decodeLatitude((int)(encoded >>> 32)), GeoEncodingUtils.decodeLongitude((int)encoded)); } return resetFromIndexHash(Long.parseLong(field.stringValue())); }
@Override protected Relation relateRangeBBoxToQuery(int minXOffset, int minYOffset, byte[] minTriangle, int maxXOffset, int maxYOffset, byte[] maxTriangle) { double minLat = GeoEncodingUtils.decodeLatitude(NumericUtils.sortableBytesToInt(minTriangle, minYOffset)); double minLon = GeoEncodingUtils.decodeLongitude(NumericUtils.sortableBytesToInt(minTriangle, minXOffset)); double maxLat = GeoEncodingUtils.decodeLatitude(NumericUtils.sortableBytesToInt(maxTriangle, maxYOffset)); double maxLon = GeoEncodingUtils.decodeLongitude(NumericUtils.sortableBytesToInt(maxTriangle, maxXOffset)); // check internal node against query return line2D.relate(minLat, maxLat, minLon, maxLon); }
@Override protected Relation relateRangeBBoxToQuery(int minXOffset, int minYOffset, byte[] minTriangle, int maxXOffset, int maxYOffset, byte[] maxTriangle) { double minLat = GeoEncodingUtils.decodeLatitude(NumericUtils.sortableBytesToInt(minTriangle, minYOffset)); double minLon = GeoEncodingUtils.decodeLongitude(NumericUtils.sortableBytesToInt(minTriangle, minXOffset)); double maxLat = GeoEncodingUtils.decodeLatitude(NumericUtils.sortableBytesToInt(maxTriangle, maxYOffset)); double maxLon = GeoEncodingUtils.decodeLongitude(NumericUtils.sortableBytesToInt(maxTriangle, maxXOffset)); // check internal node against query return poly2D.relate(minLat, maxLat, minLon, maxLon); }
private static double approxBestDistance(byte[] minPackedValue, byte[] maxPackedValue, double pointLat, double pointLon) { double minLat = decodeLatitude(minPackedValue, 0); double minLon = decodeLongitude(minPackedValue, Integer.BYTES); double maxLat = decodeLatitude(maxPackedValue, 0); double maxLon = decodeLongitude(maxPackedValue, Integer.BYTES); return approxBestDistance(minLat, maxLat, minLon, maxLon, pointLat, pointLon); }
@Override protected Relation relateRangeBBoxToQuery(int minXOffset, int minYOffset, byte[] minTriangle, int maxXOffset, int maxYOffset, byte[] maxTriangle) { double minLat = GeoEncodingUtils.decodeLatitude(LatLonShape.decodeTriangleBoxVal(minTriangle, minYOffset)); double minLon = GeoEncodingUtils.decodeLongitude(LatLonShape.decodeTriangleBoxVal(minTriangle, minXOffset)); double maxLat = GeoEncodingUtils.decodeLatitude(LatLonShape.decodeTriangleBoxVal(maxTriangle, maxYOffset)); double maxLon = GeoEncodingUtils.decodeLongitude(LatLonShape.decodeTriangleBoxVal(maxTriangle, maxXOffset)); // check internal node against query return line2D.relate(minLat, maxLat, minLon, maxLon); }