Package com.google.common.geometry
Class S2LatLng
- java.lang.Object
-
- com.google.common.geometry.S2LatLng
-
- All Implemented Interfaces:
java.io.Serializable
@Immutable @GwtCompatible(serializable=true, emulated=true) public final class S2LatLng extends java.lang.Object implements java.io.Serializable
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. Note that the serialized form of this class is not stable and should not be relied upon for long-term persistence.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static S2LatLng
CENTER
The center point the lat/lng coordinate system.private double
latRadians
private double
lngRadians
-
Constructor Summary
Constructors Modifier Constructor Description S2LatLng()
Default constructor for convenience when declaring arrays, etc.private
S2LatLng(double latRadians, double lngRadians)
This is internal to avoid ambiguity about which units are expected.S2LatLng(S1Angle lat, S1Angle lng)
Basic constructor.S2LatLng(S2Point p)
Convert a point (not necessarily normalized) to an S2LatLng.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description S2LatLng
add(S2LatLng o)
Adds the given point to this point.boolean
approxEquals(S2LatLng o)
Returns true if the given point is within1e-9
radians of this point.boolean
approxEquals(S2LatLng o, double maxError)
Returns true if both the latitude and longitude of the given point are withinmaxError
radians of this point.boolean
equals(java.lang.Object that)
static S2LatLng
fromDegrees(double latDegrees, double lngDegrees)
Returns a new S2LatLng converted from degrees.static S2LatLng
fromE5(int latE5, int lngE5)
Returns a new S2LatLng converted from tens of microdegrees.static S2LatLng
fromE6(int latE6, int lngE6)
Returns a new S2LatLng converted from microdegrees.static S2LatLng
fromE7(int latE7, int lngE7)
Returns a new S2LatLng converted from tenths of a microdegree.static S2LatLng
fromRadians(double latRadians, double lngRadians)
Returns a new S2LatLng specified in radians.S1Angle
getDistance(S2LatLng o)
Return the distance (measured along the surface of the sphere) to the given point.double
getDistance(S2LatLng o, double radius)
Returns the surface distance to the given point assuming a constant radius.int
hashCode()
boolean
isValid()
Return true if the latitude is between -90 and 90 degrees inclusive and the longitude is between -180 and 180 degrees inclusive.S1Angle
lat()
Returns the latitude of this point as a new S1Angle.double
latDegrees()
Returns the latitude of this point as degrees.static S1Angle
latitude(S2Point p)
double
latRadians()
Returns the latitude of this point as radians.S1Angle
lng()
Returns the longitude of this point as a new S1Angle.double
lngDegrees()
Returns the longitude of this point as degrees.double
lngRadians()
Returns the longitude of this point as radians.static S1Angle
longitude(S2Point p)
S2LatLng
mul(double m)
Scales this point by the given scaling factor.S2LatLng
normalized()
Returns a new S2LatLng based on this instance for whichisValid()
will betrue
.S2LatLng
sub(S2LatLng o)
Subtracts the given point from this point.S2Point
toPoint()
Convert an S2LatLng to the equivalent unit-length vector (S2Point).java.lang.String
toString()
java.lang.String
toStringDegrees()
-
-
-
Field Detail
-
CENTER
public static final S2LatLng CENTER
The center point the lat/lng coordinate system.
-
latRadians
private final double latRadians
-
lngRadians
private final double lngRadians
-
-
Constructor Detail
-
S2LatLng
private S2LatLng(double latRadians, double lngRadians)
This is internal to avoid ambiguity about which units are expected.
-
S2LatLng
public S2LatLng(S1Angle lat, S1Angle lng)
Basic constructor. The latitude and longitude must be within the ranges allowed by is_valid() below.
-
S2LatLng
public S2LatLng()
Default constructor for convenience when declaring arrays, etc.
-
S2LatLng
public S2LatLng(S2Point p)
Convert a point (not necessarily normalized) to an S2LatLng.
-
-
Method Detail
-
fromRadians
public static S2LatLng fromRadians(double latRadians, double lngRadians)
Returns a new S2LatLng specified in radians.
-
fromDegrees
public static S2LatLng fromDegrees(double latDegrees, double lngDegrees)
Returns a new S2LatLng converted from degrees.
-
fromE5
public static S2LatLng fromE5(int latE5, int lngE5)
Returns a new S2LatLng converted from tens of microdegrees.
-
fromE6
public static S2LatLng fromE6(int latE6, int lngE6)
Returns a new S2LatLng converted from microdegrees.
-
fromE7
public static S2LatLng fromE7(int latE7, int lngE7)
Returns a new S2LatLng converted from tenths of a microdegree.
-
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
@CheckReturnValue 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.
-
add
@CheckReturnValue 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
@CheckReturnValue 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
@CheckReturnValue 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.
-
equals
public boolean equals(java.lang.Object that)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
approxEquals
public boolean approxEquals(S2LatLng o, double maxError)
Returns true if both the latitude and longitude of the given point are withinmaxError
radians of this point.
-
approxEquals
public boolean approxEquals(S2LatLng o)
Returns true if the given point is within1e-9
radians of this point. This corresponds to a distance of less than1cm
at the surface of the Earth.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toStringDegrees
public java.lang.String toStringDegrees()
-
-