de.fhpotsdam.unfolding.utils
Class GeoUtils

java.lang.Object
  extended by de.fhpotsdam.unfolding.utils.GeoUtils

public class GeoUtils
extends java.lang.Object

Basic geo-spatial utility methods.


Field Summary
static double EARTH_RADIUS_KM
           
static double MAX_LAT
           
static double MAX_LON
           
static double MIN_LAT
           
static double MIN_LON
           
 
Constructor Summary
GeoUtils()
           
 
Method Summary
static java.util.List<Location> decodeOSRMPolyline(java.lang.String encoded)
           
static java.util.List<Location> decodePolyline(java.lang.String encoded)
           
static java.util.List<Location> decodePolyline(java.lang.String encoded, int precision)
          Decodes an encoded polyline string to a list of locations.
static double getAngleBetween(Location location1, Location location2)
          Gets the angle between two locations.
static float getArea(Feature feature)
          Calculates the area of a shape feature.
static float getArea(java.util.List<Location> vertices)
          Calculates the area of a polygon.
static float getArea(Marker marker)
          Calculates the area of a shape marker.
static Location[] getBoundingBox(java.util.List<Location> locations)
          Returns the bounding box for the list of locations.
static Location getCentroid(Feature feature)
          Convenience method for getCentroid(Feature, boolean).
static Location getCentroid(Feature feature, boolean useLargestForMulti)
          Returns the centroid of a feature.
static Location getCentroid(java.util.List<Location> originalVertices)
          Returns the geometric center of the locations of a polygon.
static Location getCentroid(Marker marker)
          Gets the geometric center of the marker.
static Location getCentroidFromFeatures(java.util.List<Feature> features)
          Gets the overall geometric center of all features.
static java.util.List<Location> getClosedPolygon(java.util.List<Location> originalVertices)
          Returns a closed polygon with the last vertex the same as the first.
static Location getDecimal(java.lang.Integer latDegrees, java.lang.Integer latMinutes, java.lang.Integer latSeconds, java.lang.String latDirection, java.lang.Integer lonDegrees, java.lang.Integer lonMinutes, java.lang.Integer lonSeconds, java.lang.String lonDirection)
          Super simplistic method to convert a geo-position as a Location.
static Location getDestinationLocation(Location location, float bearing, float distance)
          Gets the location specified by a start location, a bearing, and a distance.
static double getDistance(double lat1, double lon1, double lat2, double lon2)
          Get distance in kilometers between two points on the earth.
static double getDistance(Location location1, Location location2)
          Get distance in kilometers between two points on the earth.
static Location getEuclideanCentroid(java.util.List<Location> locations)
          Returns the center of the locations.
static Feature getLargestFeature(MultiFeature multiFeature)
          Returns the largest feature of a MultiFeature by area size.
static Marker getLargestMarker(MultiMarker multiMarker)
          Returns the largest marker of a MultiMarker by area size.
static java.util.List<Location> getLocations(Feature feature)
          Returns all locations of a feature.
static java.util.List<Location> getLocations(Marker marker)
          Returns all locations of a marker.
static java.util.List<Location> getLocationsFromFeatures(java.util.List<Feature> features)
          Returns all locations of all features.
static java.util.List<Location> getLocationsFromMarkers(java.util.List<Marker> markers)
          Returns all locations of all markers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EARTH_RADIUS_KM

public static final double EARTH_RADIUS_KM
See Also:
Constant Field Values

MIN_LAT

public static final double MIN_LAT
See Also:
Constant Field Values

MAX_LAT

public static final double MAX_LAT
See Also:
Constant Field Values

MIN_LON

public static final double MIN_LON
See Also:
Constant Field Values

MAX_LON

public static final double MAX_LON
See Also:
Constant Field Values
Constructor Detail

GeoUtils

public GeoUtils()
Method Detail

getDistance

public static double getDistance(double lat1,
                                 double lon1,
                                 double lat2,
                                 double lon2)
Get distance in kilometers between two points on the earth. Using the great-circle distance formula with the approximated radius of a spherical earth.

Parameters:
lat1 - Latitude of first point, in decimal degrees.
lon1 - Longitude of first point, in decimal degrees.
lat2 - Latitude of second point, in decimal degrees.
lon2 - Longitude of second point, in decimal degrees.
Returns:
Distance in kilometers.

getDistance

public static double getDistance(Location location1,
                                 Location location2)
Get distance in kilometers between two points on the earth. Using the great-circle distance formula with the approximated radius of a spherical earth.

Parameters:
location1 - Location of first point
location2 - Location of second point
Returns:
Distance in kilometers.

getDestinationLocation

public static Location getDestinationLocation(Location location,
                                              float bearing,
                                              float distance)
Gets the location specified by a start location, a bearing, and a distance.

Parameters:
location - The start location.
bearing - The bearing in degrees.
distance - The distance in kilometers.
Returns:
The destination location.

getAngleBetween

public static double getAngleBetween(Location location1,
                                     Location location2)
Gets the angle between two locations.

Parameters:
location1 - First location.
location2 - Second location.
Returns:
The angle in radians.

getDecimal

public static Location getDecimal(java.lang.Integer latDegrees,
                                  java.lang.Integer latMinutes,
                                  java.lang.Integer latSeconds,
                                  java.lang.String latDirection,
                                  java.lang.Integer lonDegrees,
                                  java.lang.Integer lonMinutes,
                                  java.lang.Integer lonSeconds,
                                  java.lang.String lonDirection)
Super simplistic method to convert a geo-position as a Location.


getEuclideanCentroid

public static Location getEuclideanCentroid(java.util.List<Location> locations)
Returns the center of the locations. The returned location minimizes the sum of squared Euclidean distances between itself and each location in the list.

Returns:
The centroid location.

getCentroid

public static Location getCentroid(java.util.List<Location> originalVertices)
Returns the geometric center of the locations of a polygon. The returned location is the center of the polygon, unfazed by unbalanced vertices. (You probably want to use this algorithm, but check out getEuclideanCentroid(List) for an alternative.)

Returns:
The centroid location.

getClosedPolygon

public static java.util.List<Location> getClosedPolygon(java.util.List<Location> originalVertices)
Returns a closed polygon with the last vertex the same as the first.

Parameters:
originalVertices - List of locations of original polygon.
Returns:
List of location of closed polygon.

getArea

public static float getArea(java.util.List<Location> vertices)
Calculates the area of a polygon.

Parameters:
vertices - The vertices of the polygon.
Returns:
The area.

getArea

public static float getArea(Feature feature)
Calculates the area of a shape feature.

Parameters:
feature - The feature containing location vertices.
Returns:
The area.

getArea

public static float getArea(Marker marker)
Calculates the area of a shape marker.

Parameters:
marker - The marker containing location vertices.
Returns:
The area.

getCentroid

public static Location getCentroid(Feature feature,
                                   boolean useLargestForMulti)
Returns the centroid of a feature. Returns the single location for a PointFeature, the geometric center for LineFeature and PolygonFeature, and — depending on the second parameter — either the overall geometric center of all features, or the geometric center of the largest feature in a MultiFeature.

Parameters:
feature - The feature to get the centroid for.
useLargestForMulti - Set to true if you want to use only the largest feature for MultiFeatures.
Returns:
The location of the geometric center.

getLargestFeature

public static Feature getLargestFeature(MultiFeature multiFeature)
Returns the largest feature of a MultiFeature by area size.

Parameters:
multiFeature - The MultiFeature consisting of multiple features.
Returns:
The largest feature.

getLargestMarker

public static Marker getLargestMarker(MultiMarker multiMarker)
Returns the largest marker of a MultiMarker by area size.

Parameters:
multiMarker - The MultiMarker consisting of multiple markers.
Returns:
The largest marker.

getCentroid

public static Location getCentroid(Feature feature)
Convenience method for getCentroid(Feature, boolean).


getCentroid

public static Location getCentroid(Marker marker)
Gets the geometric center of the marker.

Parameters:
marker - The marker to check.
Returns:
The centroid location.

getCentroidFromFeatures

public static Location getCentroidFromFeatures(java.util.List<Feature> features)
Gets the overall geometric center of all features.

Parameters:
features - A list of features.
Returns:
The centroid location.

getLocationsFromFeatures

public static java.util.List<Location> getLocationsFromFeatures(java.util.List<Feature> features)
Returns all locations of all features.

Parameters:
features - A list of features.
Returns:
A list of locations.

getLocations

public static java.util.List<Location> getLocations(Feature feature)
Returns all locations of a feature. That is a single location for a point, all locations for lines or polygons, and all locations of all features of a MultiFeature.

Parameters:
feature - The feature to get locations from.
Returns:
A list of locations.

getLocationsFromMarkers

public static java.util.List<Location> getLocationsFromMarkers(java.util.List<Marker> markers)
Returns all locations of all markers.

Parameters:
markers - A list of markers.
Returns:
A list of locations.

getLocations

public static java.util.List<Location> getLocations(Marker marker)
Returns all locations of a marker. That is a single location for a point, all locations for lines or polygons, and all locations of all markers of a MultiMarker.

Parameters:
marker - The marker to get locations from.
Returns:
A list of locations.

getBoundingBox

public static Location[] getBoundingBox(java.util.List<Location> locations)
Returns the bounding box for the list of locations. Does not return the minimum bounding box, i.e. locations spanning the 180th meridian will result in a very large box.

Parameters:
locations - List of locations to get the bounding box for.
Returns:
An array of two locations consisting of the north-west and the south-east bounds.

decodePolyline

public static java.util.List<Location> decodePolyline(java.lang.String encoded)

decodeOSRMPolyline

public static java.util.List<Location> decodeOSRMPolyline(java.lang.String encoded)

decodePolyline

public static java.util.List<Location> decodePolyline(java.lang.String encoded,
                                                      int precision)
Decodes an encoded polyline string to a list of locations. Polyline format is used by various geo services.

Parameters:
encoded - The encoded String.
Returns:
An list of locations.
See Also:
RoutingGeometry.js - Adapted algorithm by OSRM (precision: 6 digits), Encoded Polyline Algorithm Format - Original algorithm by Google (precision: 5 digits)