Class GeoLocation
java.lang.Object
rgu.transport.geospatial.GeoLocation
- All Implemented Interfaces:
TwoDTree.Point
Represents a location on Earth, uniquely defined by latitude and longitude.
- Author:
- Lee A. Christie
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic Metric<GeoLocation, Distance> The haversine distance, the "great circle" distance across the surface of the Earth as a distance.static GeoLocationThe coordinates 0, 0. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if the other object is the same latitude and longitude.doubleEstimates the ratio by which the Euclidean distance would need to be stretched at this point to adjust for the curvature of the Earth.static Iterable<GeoLocation> grid(Latitude latMin, Latitude latMax, BigDecimal latDelta, Longitude lonMin, Longitude lonMax, BigDecimal lonDelta) Returns a grid of locations in a rectangle bounded by latitude and longitude, with given increments.inthashCode()Returns a hash code for this location.latitude()Returns the latitude of this location.Returns the latitude as a decimal.doubleReturns the latitude as a double.Returns the longitude of this location.Returns the longitude as a decimal.doubleReturns the longitude as a double.static NearestFinder<GeoLocation> nearestHaversine(Collection<GeoLocation> elements) Returns a nearest finder for the given collection of points, using the Euclidean distance.static NearestFinder<GeoLocation> nearestHaversine(Collection<GeoLocation> elements, Distance maxDistance) Returns a nearest finder for the given collection of points, using the Euclidean distance, limited to a given maximum distance.static NearestFinder<GeoLocation> nearestStretchedEuclidean(double ratio, Collection<GeoLocation> elements) Returns a nearest finder for the given collection of points, using the Euclidean distance.static NearestFinder<GeoLocation> nearestStretchedEuclidean(double ratio, Collection<GeoLocation> elements, double maxDistance) Returns a nearest finder for the given collection of points, using the Euclidean distance, limited to a given maximum distance.static GeoLocationReturns an instance of location for the specified latitude and longitude.static GeoLocationofRounded(double latitude, double longitude) Rounds the specified doubles to a location.static GeoLocationparseLocation(String latitude, String longitude) Parses and returns latitude, longitude pair of strings.static GeoLocationparseLocationTruncate(String latitude, String longitude) Parses and returns latitude, longitude pair of strings.static GeoLocationReads a location from the specified input stream.static Predicate<GeoLocation> Returns a predicate which tests whether a point is contained within a given rectangle.static Metric<GeoLocation, Double> stretchedEuclidean(double ratio) The Euclidean distance, with a stretch ratio set.toString()Returns a String object representing this location's value.voidwrite(ObjectOutputStream out) Writes this location to the specified output stream.doublex()Returns the x-coordinate of the point.doubley()Returns the y-coordinate of the point.
-
Field Details
-
NULL_ISLAND
The coordinates 0, 0. -
HAVERSINE
The haversine distance, the "great circle" distance across the surface of the Earth as a distance.
-
-
Method Details
-
stretchedEuclidean
The Euclidean distance, with a stretch ratio set.- Parameters:
ratio- the skew ratio, finite, positive
-
of
Returns an instance of location for the specified latitude and longitude.- Parameters:
latitude- the latitude, not nulllongitude- the longitude, not null- Returns:
- a location
-
ofRounded
Rounds the specified doubles to a location.- Parameters:
latitude- the latitude as a double, finitelongitude- the longitude as a double, finite- Returns:
- a location
-
parseLocation
Parses and returns latitude, longitude pair of strings.- Parameters:
latitude- the latitudelongitude- the longitude- Returns:
- the parsed location
-
parseLocationTruncate
Parses and returns latitude, longitude pair of strings.- Parameters:
latitude- the latitudelongitude- the longitude- Returns:
- the parsed location
-
latitude
-
latitudeAsDecimal
Returns the latitude as a decimal.- Returns:
- the latitude as a decimal
-
latitudeAsDouble
public double latitudeAsDouble()Returns the latitude as a double.- Returns:
- the latitude as a double
-
longitudeAsDecimal
Returns the longitude as a decimal.- Returns:
- the longitude as a decimal
-
longitude
-
longitudeAsDouble
public double longitudeAsDouble()Returns the longitude as a double.- Returns:
- the longitude as a double
-
rectangle
-
grid
public static Iterable<GeoLocation> grid(Latitude latMin, Latitude latMax, BigDecimal latDelta, Longitude lonMin, Longitude lonMax, BigDecimal lonDelta) Returns a grid of locations in a rectangle bounded by latitude and longitude, with given increments.- Parameters:
latMin- the minimum latitude, not nulllatMax- the maximum latitude, not nulllatDelta- the delta to step by in the latitude directionlonMin- the minimum longitude, not nulllonMax- the maximum longitude, not nulllonDelta- the delta to step by in the longitude direction- Returns:
- an iterable grid of locations
-
hashCode
-
x
public double x()Description copied from interface:TwoDTree.PointReturns the x-coordinate of the point.- Specified by:
xin interfaceTwoDTree.Point- Returns:
- the x-coordinate
-
y
public double y()Description copied from interface:TwoDTree.PointReturns the y-coordinate of the point.- Specified by:
yin interfaceTwoDTree.Point- Returns:
- the y-coordinate
-
equals
-
toString
-
nearestHaversine
Returns a nearest finder for the given collection of points, using the Euclidean distance.- Parameters:
elements- the set of elements, not null- Returns:
- a nearest finder
-
nearestHaversine
public static NearestFinder<GeoLocation> nearestHaversine(Collection<GeoLocation> elements, Distance maxDistance) Returns a nearest finder for the given collection of points, using the Euclidean distance, limited to a given maximum distance.- Parameters:
elements- the set of elements, not nullmaxDistance- the maximum distance, not null, [0, inf)- Returns:
- a nearest finder
-
nearestStretchedEuclidean
public static NearestFinder<GeoLocation> nearestStretchedEuclidean(double ratio, Collection<GeoLocation> elements) Returns a nearest finder for the given collection of points, using the Euclidean distance.- Parameters:
ratio- the stretch ratio, finite, positiveelements- the set of elements, not null- Returns:
- a nearest finder
-
nearestStretchedEuclidean
public static NearestFinder<GeoLocation> nearestStretchedEuclidean(double ratio, Collection<GeoLocation> elements, double maxDistance) Returns a nearest finder for the given collection of points, using the Euclidean distance, limited to a given maximum distance.- Parameters:
ratio- the stretch ratio, finite, positiveelements- the set of elements, not nullmaxDistance- the maximum distance, [0, inf)- Returns:
- a nearest finder
-
write
Writes this location to the specified output stream.- Parameters:
out- the output stream, not null- Throws:
IOException- if an exception occurred writing
-
read
Reads a location from the specified input stream.- Parameters:
in- the input stream, not null- Returns:
- the location
- Throws:
IOException- if an exception occurred reading
-
estimateCurvature
public double estimateCurvature()Estimates the ratio by which the Euclidean distance would need to be stretched at this point to adjust for the curvature of the Earth.- Returns:
- the estimated curvature
-