List of usage examples for com.google.common.geometry S2LatLngRect contains
public boolean contains(S2Point p)
From source file:com.grublr.geo.GeoDataManager.java
/** * Filter out any points outside of the queried area from the input list. * //from www. j av a 2s .com * @param list * List of items return by Amazon DynamoDB. It may contains points outside of the actual area queried. * * @param latLngRect * Queried area. Any points outside of this area need to be discarded. * * @return List of items within the queried area. */ private List<Map<String, AttributeValue>> filter(List<Map<String, AttributeValue>> list, 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); } } return result; }