/** * Gets the geohash. * * @return the geohash */ public String getGeohash() { return GeoHashExtensions.encode(getLatitude(), getLongitude()); }
/** * {@inheritDoc} */ @Override public Object clone() { return new GeoHashPoint(getLatitude(), getLongitude()); }
/** * {@inheritDoc} */ @Override public Object clone() { final Position inst = new Point(this.latitude, this.longitude); return inst; }
/** * Returns the distance between two given geohash values. * * @param startGeohashValue * the geohash value from where to start the measurement. * @param endGeohashValue * the geohash value where to end the measurement. * @param unit * the measurement unit * @return the distance between the given geohash values. */ public static double distanceBetweenPoints(final String startGeohashValue, final String endGeohashValue, final MeasuringUnit unit) { return distanceBetweenPoints(new GeoHashPoint(startGeohashValue), new GeoHashPoint(endGeohashValue), unit); }
/** * Returns an array of two extreme points corresponding to center point and the distance from * the center point. These extreme points are the points with max/min latitude and longitude. * * @param point * the point * @param distance * the distance * @return the extreme points from */ public static Point[] getExtremePointsFrom(final Point point, final Double distance) { double longDiff = getExtremeLongitudesDiffForPoint(point, distance); double latDiff = getExtremeLatitudesDiffForPoint(point, distance); Point p1 = new Point(point.getLatitude() - latDiff, point.getLongitude() - longDiff); Point p2 = new Point(point.getLatitude() + latDiff, point.getLatitude() + longDiff); return new Point[] { p1, p2 }; }
/** * Gets the geohash from the given ip address or return an empty String if nothing is found. * * @param lookupService * the lookup service * @param ipAddress * the ip address * @return the geohash from ip address or an empty String if nothing is found. */ public static String getGeohashFromIpAddress(final LookupService lookupService, final String ipAddress) { final GeoHashPoint geoHashPoint = getGeoHashPoint(lookupService, ipAddress); if (geoHashPoint != null) { return geoHashPoint.getGeohash(); } return ""; }
/** * {@inheritDoc} */ @Override public String toString() { final StringBuilder buffer = new StringBuilder(); buffer.append("[GeoHashPoint:"); buffer.append(super.toString()); buffer.append(" Geohash : "); buffer.append(getGeohash()); buffer.append("]"); return buffer.toString(); }
/** * Gets the {@link GeoHashPoint} object from the given ip address or return null if nothing is * found. * * @param lookupService * the lookup service * @param ipAddress * the ip address * @return the {@link GeoHashPoint} object from the given ip address or return null if nothing * is found. */ public static GeoHashPoint getGeoHashPoint(final LookupService lookupService, final String ipAddress) { final Location lc = lookupService.getLocation(ipAddress); if (lc != null) { return new GeoHashPoint(lc.latitude, lc.longitude); } return null; }
/** * Gets the longitude from the given geohash value. * * @param geohash * the geohash * @return the longitude */ public static double getLongitude(final String geohash) { return decodeAndRound(geohash)[1]; }
/** * Decodes the given geohash into a latitude and longitude. * * @param geohash * the geohash * @return the double[] */ public static double[] decodeAndRound(final String geohash) { final double[] ge = decode(geohash); double latitude = ge[0]; double longitude = ge[1]; final double latitudeError = ge[2]; final double longitudeError = ge[3]; final double latitudePrecision = Math.max(1, Math.round(-Math.log10(latitudeError))) - 1; final double longitudePrecision = Math.max(1, Math.round(-Math.log10(longitudeError))) - 1; latitude = getPrecision(latitude, latitudePrecision); longitude = getPrecision(longitude, longitudePrecision); return new double[] { latitude, longitude }; }
/** * Returns the difference in degrees of longitude corresponding to the distance from the center * point. This distance can be used to find the extreme points. * * @param p1 * the p1 * @param distance * the distance * @return the extreme longitudes diff for point */ public static double getExtremeLongitudesDiffForPoint(final Point p1, final double distance) { double lat1 = p1.getLatitude(); lat1 = degreesToRadians(lat1); double longitudeRadius = Math.cos(lat1) * EARTH_RADIUS_KM; double diffLong = (distance / longitudeRadius); diffLong = radiansToDegrees(diffLong); return diffLong; }
/** * Instantiates a new FirstRingRegion object from the given geohash value. * * @param geohash * the center */ public FirstRingRegion(final String geohash) { this.center = geohash; this.east = GeoHashExtensions.getAdjacent(geohash, Adjacent.RIGHT); this.west = GeoHashExtensions.getAdjacent(geohash, Adjacent.LEFT); this.north = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP); this.south = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM); this.southEast = GeoHashExtensions.getAdjacent(this.south, Adjacent.RIGHT); this.northEast = GeoHashExtensions.getAdjacent(this.north, Adjacent.RIGHT); this.northWest = GeoHashExtensions.getAdjacent(this.north, Adjacent.LEFT); this.southWest = GeoHashExtensions.getAdjacent(this.south, Adjacent.LEFT); }
assert this.equals(other) : "compareTo inconsistent with equals."; return 0;
/** * Gets the longitude as BigDecimal object. * * @return the longitude as BigDecimal object. */ public BigDecimal getLng() { return BigDecimal.valueOf(getLongitude()); }
/** * Gets the latitude as BigDecimal object. * * @return the latitude as BigDecimal object. */ public BigDecimal getLat() { return BigDecimal.valueOf(getLatitude()); }
/** * Returns an array of two extreme points corresponding to center point and the distance from * the center point. These extreme points are the points with max/min latitude and longitude. * * @param point * the point * @param distance * the distance * @return the extreme points from */ public static Point[] getExtremePointsFrom(final Point point, final Double distance) { double longDiff = getExtremeLongitudesDiffForPoint(point, distance); double latDiff = getExtremeLatitudesDiffForPoint(point, distance); Point p1 = new Point(point.getLatitude() - latDiff, point.getLongitude() - longDiff); Point p2 = new Point(point.getLatitude() + latDiff, point.getLatitude() + longDiff); return new Point[] { p1, p2 }; }
/** * Gets the latitude from the given geohash value. * * @param geohash * the geohash * @return the latitude */ public static double getLatitude(final String geohash) { return decodeAndRound(geohash)[0]; }
/** * Gets the adjacent from the given directions. For instance if directions is 'top' and 'feft' * then the topleft adjacent geohash code will be returned. * * @param geohash * the geohash * @param directions * the directions * @return the geohash code for the adjacent from the given directions. */ public static String getAdjacent(final String geohash, final String... directions) { String geohashresult = geohash; for (final String direction : directions) { geohashresult = getAdjacent(geohashresult, direction); } return geohashresult; }
northNorth = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.TOP); northNorthWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.LEFT, Adjacent.TOP); northWestNorthWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.LEFT, Adjacent.TOP, Adjacent.LEFT); westNorthWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.LEFT, Adjacent.LEFT); northNorthEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.RIGHT, Adjacent.TOP); northEastNorthEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.RIGHT, Adjacent.TOP, Adjacent.RIGHT); eastNorthEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.TOP, Adjacent.RIGHT, Adjacent.RIGHT); eastEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.RIGHT, Adjacent.RIGHT); eastSouthEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.RIGHT, Adjacent.RIGHT); southSouthEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.RIGHT, Adjacent.BOTTOM); southEastSouthEast = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.RIGHT, Adjacent.BOTTOM, Adjacent.RIGHT); southSouth = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.BOTTOM); southSouthWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.LEFT, Adjacent.BOTTOM); southWestSouthWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.LEFT, Adjacent.BOTTOM, Adjacent.LEFT); westSouthWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.BOTTOM, Adjacent.LEFT, Adjacent.LEFT); westWest = GeoHashExtensions.getAdjacent(geohash, Adjacent.LEFT, Adjacent.LEFT);