Java Code Examples for org.apache.lucene.geo.GeoEncodingUtils#decodeLongitude()

The following examples show how to use org.apache.lucene.geo.GeoEncodingUtils#decodeLongitude() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: crate   File: GeoPointColumnReference.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Point value() {
    try {
        if (values.advanceExact(docId)) {
            switch (values.docValueCount()) {
                case 1:
                    long encoded = values.nextValue();
                    return new PointImpl(
                        GeoEncodingUtils.decodeLongitude((int) encoded),
                        GeoEncodingUtils.decodeLatitude((int) (encoded >>> 32)),
                        JtsSpatialContext.GEO
                    );

                default:
                    throw new GroupByOnArrayUnsupportedException(columnName);
            }
        } else {
            return null;
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 2
Source Project: lucene-solr   File: LatLonShapeQuery.java    License: Apache License 2.0 5 votes vote down vote up
@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 component2D.relate(minLon, maxLon, minLat, maxLat);
}
 
Example 3
private double getDistanceKeyFromEncoded(long encoded) {
  int latitudeBits = (int)(encoded >> 32);
  int longitudeBits = (int)(encoded & 0xFFFFFFFF);
  double lat = GeoEncodingUtils.decodeLatitude(latitudeBits);
  double lon = GeoEncodingUtils.decodeLongitude(longitudeBits);
  return SloppyMath.haversinSortKey(originLat, originLon, lat, lon);
}
 
Example 4
Source Project: lucene-solr   File: TestLatLonShape.java    License: Apache License 2.0 5 votes vote down vote up
public void testIndexAndQuerySamePolygon() throws Exception {
  Directory dir = newDirectory();
  RandomIndexWriter w = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  Polygon polygon;
  while(true) {
    try {
      polygon = GeoTestUtil.nextPolygon();
      // quantize the polygon
      double[] lats = new double[polygon.numPoints()];
      double[] lons = new double[polygon.numPoints()];
      for (int i = 0; i < polygon.numPoints(); i++) {
        lats[i] = GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(polygon.getPolyLat(i)));
        lons[i] = GeoEncodingUtils.decodeLongitude(GeoEncodingUtils.encodeLongitude(polygon.getPolyLon(i)));
      }
      polygon = new Polygon(lats, lons);
      Tessellator.tessellate(polygon);
      break;
    } catch (Exception e) {
      // invalid polygon, try a new one
    }
  }
  addPolygonsToDoc(FIELDNAME, doc, polygon);
  w.addDocument(doc);
  w.forceMerge(1);

  ///// search //////
  IndexReader reader = w.getReader();
  w.close();
  IndexSearcher searcher = newSearcher(reader);

  Query q = LatLonShape.newPolygonQuery(FIELDNAME, QueryRelation.WITHIN, polygon);
  assertEquals(1, searcher.count(q));
  q = LatLonShape.newPolygonQuery(FIELDNAME, QueryRelation.INTERSECTS, polygon);
  assertEquals(1, searcher.count(q));
  q = LatLonShape.newPolygonQuery(FIELDNAME, QueryRelation.DISJOINT, polygon);
  assertEquals(0, searcher.count(q));

  IOUtils.close(w, reader, dir);
}
 
Example 5
/**
 * Decodes the docValues number into latitude and longitude components, formatting as "lat,lon".
 * The encoding is governed by {@code LatLonDocValuesField}.  The decimal output representation is reflective
 * of the available precision.
 * @param value Non-null; stored location field data
 * @return Non-null; "lat, lon"
 */
public static String decodeDocValueToString(long value) {
  final double latDouble = GeoEncodingUtils.decodeLatitude((int) (value >> 32));
  final double lonDouble = GeoEncodingUtils.decodeLongitude((int) (value & 0xFFFFFFFFL));
  // This # decimal places gets us close to our available precision to 1.40cm; we have a test for it.
  // CEILING round-trips (decode then re-encode then decode to get identical results). Others did not. It also
  //   reverses the "floor" that occurred when we encoded.
  final int DECIMAL_PLACES = 7;
  final RoundingMode ROUND_MODE = CEILING;
  BigDecimal latitudeDecoded = BigDecimal.valueOf(latDouble).setScale(DECIMAL_PLACES, ROUND_MODE);
  BigDecimal longitudeDecoded = BigDecimal.valueOf(lonDouble).setScale(DECIMAL_PLACES, ROUND_MODE);
  return latitudeDecoded.stripTrailingZeros().toPlainString() + ","
      + longitudeDecoded.stripTrailingZeros().toPlainString();
  // return ((float)latDouble) + "," + ((float)lonDouble);  crude but not quite as accurate
}
 
Example 6
Source Project: lucene-solr   File: TestNearest.java    License: Apache License 2.0 4 votes vote down vote up
private double quantizeLon(double lonRaw) {
  return GeoEncodingUtils.decodeLongitude(GeoEncodingUtils.encodeLongitude(lonRaw));
}
 
Example 7
@Override
protected double quantizeLon(double lonRaw) {
  return GeoEncodingUtils.decodeLongitude(GeoEncodingUtils.encodeLongitude(lonRaw));
}
 
Example 8
@Override
protected double quantizeLon(double lonRaw) {
  return GeoEncodingUtils.decodeLongitude(GeoEncodingUtils.encodeLongitude(lonRaw));
}
 
Example 9
@Override
protected double decodeX(int xEncoded) {
  return GeoEncodingUtils.decodeLongitude(xEncoded);
}
 
Example 10
public static double decodeLongitude(long encodedLatLon) {
    return GeoEncodingUtils.decodeLongitude((int) (encodedLatLon & 0xFFFFFFFFL));
}