Package com.google.common.geometry
Class S2LatLng
- java.lang.Object
-
- com.google.common.geometry.S2LatLng
-
public class S2LatLng extends Object
This class represents a point on the unit sphere as a pair of latitude-longitude coordinates. Like the rest of the "geometry" package, the intent is to represent spherical geometry as a mathematical abstraction, so functions that are specifically related to the Earth's geometry (e.g. easting/northing conversions) should be put elsewhere.
-
-
Field Summary
Fields Modifier and Type Field Description static S2LatLngCENTERThe center point the lat/lng coordinate system.static doubleEARTH_RADIUS_METERSApproximate "effective" radius of the Earth in meters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description S2LatLngadd(S2LatLng o)Adds the given point to this point.booleanapproxEquals(S2LatLng o)Returns true if the given point is within1e-9radians of this point.booleanapproxEquals(S2LatLng o, double maxError)Returns true if both the latitude and longitude of the given point are withinmaxErrorradians of this point.booleanequals(Object that)static S2LatLngfromDegrees(double latDegrees, double lngDegrees)static S2LatLngfromE5(long latE5, long lngE5)static S2LatLngfromE6(long latE6, long lngE6)static S2LatLngfromE7(long latE7, long lngE7)static S2LatLngfromRadians(double latRadians, double lngRadians)S1AnglegetDistance(S2LatLng o)Return the distance (measured along the surface of the sphere) to the given point.doublegetDistance(S2LatLng o, double radius)Returns the surface distance to the given point assuming a constant radius.doublegetEarthDistance(S2LatLng o)Returns the surface distance to the given point assuming the default Earth radius ofEARTH_RADIUS_METERS.inthashCode()booleanisValid()Return true if the latitude is between -90 and 90 degrees inclusive and the longitude is between -180 and 180 degrees inclusive.S1Anglelat()Returns the latitude of this point as a new S1Angle.doublelatDegrees()Returns the latitude of this point as degrees.static S1Anglelatitude(S2Point p)doublelatRadians()Returns the latitude of this point as radians.S1Anglelng()Returns the longitude of this point as a new S1Angle.doublelngDegrees()Returns the longitude of this point as degrees.doublelngRadians()Returns the longitude of this point as radians.static S1Anglelongitude(S2Point p)S2LatLngmul(double m)Scales this point by the given scaling factor.S2LatLngnormalized()Returns a new S2LatLng based on this instance for whichisValid()will betrue.S2LatLngsub(S2LatLng o)Subtracts the given point from this point.S2PointtoPoint()Convert an S2LatLng to the equivalent unit-length vector (S2Point).StringtoString()StringtoStringDegrees()
-
-
-
Field Detail
-
EARTH_RADIUS_METERS
public static final double EARTH_RADIUS_METERS
Approximate "effective" radius of the Earth in meters.- See Also:
- Constant Field Values
-
CENTER
public static final S2LatLng CENTER
The center point the lat/lng coordinate system.
-
-
Constructor Detail
-
S2LatLng
public S2LatLng(S1Angle lat, S1Angle lng)
Basic constructor. The latitude and longitude must be within the ranges allowed by is_valid() below. TODO(dbeaumont): Make this a static factory method (fromLatLng() ?).
-
S2LatLng
public S2LatLng()
Default constructor for convenience when declaring arrays, etc. TODO(dbeaumont): Remove the default constructor (just use CENTER).
-
S2LatLng
public S2LatLng(S2Point p)
Convert a point (not necessarily normalized) to an S2LatLng. TODO(dbeaumont): Make this a static factory method (fromPoint() ?).
-
-
Method Detail
-
fromRadians
public static S2LatLng fromRadians(double latRadians, double lngRadians)
-
fromDegrees
public static S2LatLng fromDegrees(double latDegrees, double lngDegrees)
-
fromE5
public static S2LatLng fromE5(long latE5, long lngE5)
-
fromE6
public static S2LatLng fromE6(long latE6, long lngE6)
-
fromE7
public static S2LatLng fromE7(long latE7, long lngE7)
-
lat
public S1Angle lat()
Returns the latitude of this point as a new S1Angle.
-
latRadians
public double latRadians()
Returns the latitude of this point as radians.
-
latDegrees
public double latDegrees()
Returns the latitude of this point as degrees.
-
lng
public S1Angle lng()
Returns the longitude of this point as a new S1Angle.
-
lngRadians
public double lngRadians()
Returns the longitude of this point as radians.
-
lngDegrees
public double lngDegrees()
Returns the longitude of this point as degrees.
-
isValid
public boolean isValid()
Return true if the latitude is between -90 and 90 degrees inclusive and the longitude is between -180 and 180 degrees inclusive.
-
normalized
public S2LatLng normalized()
Returns a new S2LatLng based on this instance for whichisValid()will betrue.- Latitude is clipped to the range
[-90, 90] - Longitude is normalized to be in the range
[-180, 180]
If the current point is valid then the returned point will have the same coordinates.
- Latitude is clipped to the range
-
toPoint
public S2Point toPoint()
Convert an S2LatLng to the equivalent unit-length vector (S2Point).
-
getDistance
public S1Angle getDistance(S2LatLng o)
Return the distance (measured along the surface of the sphere) to the given point.
-
getDistance
public double getDistance(S2LatLng o, double radius)
Returns the surface distance to the given point assuming a constant radius.
-
getEarthDistance
public double getEarthDistance(S2LatLng o)
Returns the surface distance to the given point assuming the default Earth radius ofEARTH_RADIUS_METERS.
-
add
public S2LatLng add(S2LatLng o)
Adds the given point to this point. Note that there is no guarantee that the new point will be valid.
-
sub
public S2LatLng sub(S2LatLng o)
Subtracts the given point from this point. Note that there is no guarantee that the new point will be valid.
-
mul
public S2LatLng mul(double m)
Scales this point by the given scaling factor. Note that there is no guarantee that the new point will be valid.
-
approxEquals
public boolean approxEquals(S2LatLng o, double maxError)
Returns true if both the latitude and longitude of the given point are withinmaxErrorradians of this point.
-
approxEquals
public boolean approxEquals(S2LatLng o)
Returns true if the given point is within1e-9radians of this point. This corresponds to a distance of less than1cmat the surface of the Earth.
-
toStringDegrees
public String toStringDegrees()
-
-