Package com.google.common.geometry

Examples of com.google.common.geometry.S2LatLng


      GeoQueryRequest geoQueryRequest) {

    List<Map<String, AttributeValue>> result = new ArrayList<Map<String, AttributeValue>>();

    S2LatLngRect latLngRect = null;
    S2LatLng centerLatLng = null;
    double radiusInMeter = 0;
    if (geoQueryRequest instanceof QueryRectangleRequest) {
      latLngRect = S2Util.getBoundingLatLngRect(geoQueryRequest);
    } else if (geoQueryRequest instanceof QueryRadiusRequest) {
      GeoPoint centerPoint = ((QueryRadiusRequest) geoQueryRequest).getCenterPoint();
      centerLatLng = S2LatLng.fromDegrees(centerPoint.getLatitude(), centerPoint.getLongitude());

      radiusInMeter = ((QueryRadiusRequest) geoQueryRequest).getRadiusInMeter();
    }

    for (Map<String, AttributeValue> item : list) {
      String geoJson = item.get(config.getGeoJsonAttributeName()).getS();
      GeoPoint geoPoint = GeoJsonMapper.geoPointFromString(geoJson);

      S2LatLng latLng = S2LatLng.fromDegrees(geoPoint.getLatitude(), geoPoint.getLongitude());
      if (latLngRect != null && latLngRect.contains(latLng)) {
        result.add(item);
      } else if (centerLatLng != null && radiusInMeter > 0
          && centerLatLng.getEarthDistance(latLng) <= radiusInMeter) {
        result.add(item);
View Full Code Here


      GeoPoint maxPoint = queryRectangleRequest.getMaxPoint();

      S2LatLngRect latLngRect = null;

      if (minPoint != null && maxPoint != null) {
        S2LatLng minLatLng = S2LatLng.fromDegrees(minPoint.getLatitude(), minPoint.getLongitude());
        S2LatLng maxLatLng = S2LatLng.fromDegrees(maxPoint.getLatitude(), maxPoint.getLongitude());

        latLngRect = new S2LatLngRect(minLatLng, maxLatLng);
      }

      return latLngRect;
    } else if (geoQueryRequest instanceof QueryRadiusRequest) {
      QueryRadiusRequest queryRadiusRequest = (QueryRadiusRequest) geoQueryRequest;

      GeoPoint centerPoint = queryRadiusRequest.getCenterPoint();
      double radiusInMeter = queryRadiusRequest.getRadiusInMeter();

      S2LatLng centerLatLng = S2LatLng.fromDegrees(centerPoint.getLatitude(), centerPoint.getLongitude());

      double latReferenceUnit = centerPoint.getLatitude() > 0.0 ? -1.0 : 1.0;
      S2LatLng latReferenceLatLng = S2LatLng.fromDegrees(centerPoint.getLatitude() + latReferenceUnit,
          centerPoint.getLongitude());
      double lngReferenceUnit = centerPoint.getLongitude() > 0.0 ? -1.0 : 1.0;
      S2LatLng lngReferenceLatLng = S2LatLng.fromDegrees(centerPoint.getLatitude(), centerPoint.getLongitude()
          + lngReferenceUnit);

      double latForRadius = radiusInMeter / centerLatLng.getEarthDistance(latReferenceLatLng);
      double lngForRadius = radiusInMeter / centerLatLng.getEarthDistance(lngReferenceLatLng);

      S2LatLng minLatLng = S2LatLng.fromDegrees(centerPoint.getLatitude() - latForRadius,
          centerPoint.getLongitude() - lngForRadius);
      S2LatLng maxLatLng = S2LatLng.fromDegrees(centerPoint.getLatitude() + latForRadius,
          centerPoint.getLongitude() + lngForRadius);

      return new S2LatLngRect(minLatLng, maxLatLng);
    }
View Full Code Here

      assert false; // This should not happen.
    }
  }

  public static long generateGeohash(GeoPoint geoPoint) {
    S2LatLng latLng = S2LatLng.fromDegrees(geoPoint.getLatitude(), geoPoint.getLongitude());
    S2Cell cell = new S2Cell(latLng);
    S2CellId cellId = cell.id();

    return cellId.id();
  }
View Full Code Here

TOP

Related Classes of com.google.common.geometry.S2LatLng

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.