openlr.map.utils
Class GeometryUtils

java.lang.Object
  extended by openlr.map.utils.GeometryUtils

public final class GeometryUtils
extends Object

The GeometryUtils offer methods for the calculation of distances of points and bearings of lines.

OpenLR is a trade mark of TomTom International B.V.

email: software@openlr.org

Author:
TomTom International B.V.

Nested Class Summary
static class GeometryUtils.BearingDirection
          The Enum BearingDirection defines the direction off a line being used for the bearing calculation.
 
Field Summary
static int FULL_CIRCLE_DEGREE
          degree in a full circle
static double HALF_CIRCLE
          The Constant HALF_CIRCLE.
static float MAX_LAT
          The Constant MAX_LAT.
static float MAX_LON
          The Constant MAX_LON.
static float MIN_LAT
          The Constant MIN_LAT.
static float MIN_LON
          The Constant MIN_LON.
static double QUARTER_CIRCLE
          The Constant QUARTER_CIRCLE.
static double THREE_QUARTER_CIRCLE
          The Constant QUARTER_CIRCLE.
static double ZERO_CIRCLE
          The Constant ZERO_CIRCLE.
 
Method Summary
static double bearing(double p1Longitude, double p1Latitude, double p2Longitude, double p2Latitude)
          Return the bearing (degrees clockwise from North) of p2 from p1 (the direction that must be traveled from p1 in order to arrive at p2).
static double bearing(GeoCoordinates coord1, GeoCoordinates coord2)
          Return the bearing (degrees clockwise from North) of p2 from p1 (the direction that must be traveled from p1 in order to arrive at p2).
static double calculateLineBearing(Line line, GeometryUtils.BearingDirection dir, int pointDistance, int projectionAlongLine)
          Calculates and returns the line bearing.
static boolean checkCoordinateBounds(double lon, double lat)
          Check coordinate bounds.
static GeoCoordinates determineCoordinateInDistance(double lon, double lat, int angle, double distanceKm)
          Determine coordinate in distance.
static GeoCoordinates determineCoordinateInDistance(GeoCoordinates coord, int angle, double distanceKm)
          Determine coordinate in distance.
static double distance(double longitude1, double latitude1, double longitude2, double latitude2)
          Returns the distance in meters between two points specified in degrees longitude (x) and latitude (y).
static double distance(GeoCoordinates coord1, GeoCoordinates coord2)
          Returns the distance in meters between two points specified in degrees longitude (x) and latitude (y).
static GeoCoordinates intersectStraights(double longitude1, double latitude1, double bear1, double longitude2, double latitude2, double bear2)
          Intersects two straights given by rsp.
static GeoCoordinates intersectStraights(GeoCoordinates coord1, double bear1, GeoCoordinates coord2, double bear2)
          Intersects two straights given by rsp.
static boolean lineIntersection(GeoCoordinates gc1Start, GeoCoordinates gc1End, GeoCoordinates gc2Start, GeoCoordinates gc2End)
          Line intersection.
static GeoCoordinates pointAlongLine(double longitudeA, double latitudeA, double longitudeB, double latitudeB, double offset)
          Calculates a point on the straight line defined by point a and b.
static GeoCoordinates pointAlongLine(GeoCoordinates coord1, GeoCoordinates coord2, double offset)
          Calculates a point on the straight line defined by point a and b.
static double round(double val)
          Round.
static double round(double val, int decimalPlaces)
          Rounds a coordinate value (longitude or latitude) to a specific precision.
static GeoCoordinates scaleUpperRightCoordinate(double lowerLeftLon, double lowerLeftLat, double upperRightLon, double upperRightLat, double xfactor, double yfactor)
          Scale the upperright point of a rectangle given by lowerleft and upperright wrt to given factors in x- and y-direction.
static GeoCoordinates scaleUpperRightCoordinate(GeoCoordinates lowerLeft, GeoCoordinates upperRight, double xfactor, double yfactor)
          Scale the upperright point of a rectangle given by lowerleft and upperright wrt to given factors in x- and y-direction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_LAT

public static final float MAX_LAT
The Constant MAX_LAT.

See Also:
Constant Field Values

MIN_LAT

public static final float MIN_LAT
The Constant MIN_LAT.

See Also:
Constant Field Values

MAX_LON

public static final float MAX_LON
The Constant MAX_LON.

See Also:
Constant Field Values

MIN_LON

public static final float MIN_LON
The Constant MIN_LON.

See Also:
Constant Field Values

ZERO_CIRCLE

public static final double ZERO_CIRCLE
The Constant ZERO_CIRCLE.

See Also:
Constant Field Values

HALF_CIRCLE

public static final double HALF_CIRCLE
The Constant HALF_CIRCLE.

See Also:
Constant Field Values

QUARTER_CIRCLE

public static final double QUARTER_CIRCLE
The Constant QUARTER_CIRCLE.

See Also:
Constant Field Values

THREE_QUARTER_CIRCLE

public static final double THREE_QUARTER_CIRCLE
The Constant QUARTER_CIRCLE.

See Also:
Constant Field Values

FULL_CIRCLE_DEGREE

public static final int FULL_CIRCLE_DEGREE
degree in a full circle

See Also:
Constant Field Values
Method Detail

distance

public static double distance(GeoCoordinates coord1,
                              GeoCoordinates coord2)
Returns the distance in meters between two points specified in degrees longitude (x) and latitude (y).
The distance calculation works with the WGS84-orthodrome and thus accounts for the oblateness of the earth, resulting in increased preciseness.

Parameters:
coord1 - the GeoCoordinate of the first point
coord2 - the GeoCoordinate of the second point
Returns:
the distance between the two points in meter

distance

public static double distance(double longitude1,
                              double latitude1,
                              double longitude2,
                              double latitude2)
Returns the distance in meters between two points specified in degrees longitude (x) and latitude (y).
The distance calculation works with the WGS84-orthodrome and thus accounts for the oblateness of the earth, resulting in increased preciseness.

Parameters:
longitude1 - the longitude of the first point
latitude1 - the latitude of the first point
longitude2 - the longitude of the second point
latitude2 - the latitude of the second point
Returns:
the distance between the two points in meter

bearing

public static double bearing(GeoCoordinates coord1,
                             GeoCoordinates coord2)
Return the bearing (degrees clockwise from North) of p2 from p1 (the direction that must be traveled from p1 in order to arrive at p2).

Parameters:
coord1 - the GeoCoordinates of the first point
coord2 - the GeoCoordinates of the second point
Returns:
the bearing

bearing

public static double bearing(double p1Longitude,
                             double p1Latitude,
                             double p2Longitude,
                             double p2Latitude)
Return the bearing (degrees clockwise from North) of p2 from p1 (the direction that must be traveled from p1 in order to arrive at p2).

Parameters:
p1Longitude - the longitude of the first point
p1Latitude - the latitude of the first point
p2Longitude - the longitude of the second point
p2Latitude - the latitude of the second point
Returns:
the bearing

calculateLineBearing

public static double calculateLineBearing(Line line,
                                          GeometryUtils.BearingDirection dir,
                                          int pointDistance,
                                          int projectionAlongLine)
Calculates and returns the line bearing. The bearing will be calculated in degrees clockwise from North. The GeometryUtils.BearingDirection indicates the direction for the measurement.
The projectionAlongLine will be used if the given value is greater than 0 and refers to a position along the line being projectionAlongLine meters away from the start of the line. In such a case the first point for the measurement is equal to the position defined by projectionAlongLine.
The second point will be pointDistance meters away from the first point. If dir equals IN_DIRECTION the second point will be determined in the direction of the line (from start to end) otherwise if dir equals AGAINST_DIRECTION the second point will be determined against the direction of the line.
If projectionAlongLine equals 0 then the first point will be determined as the start node of the line if dir is IN_DIRECTION and if dir is AGAINST_DIRECTION the end node of the line will be used.
If the remaining line is shorter than pointDistance the next node of the line will be used.
The bearing is the angle between the North and the line being defined by the first and second point.

Parameters:
line - the line
dir - the direction of the line being used
pointDistance - the point distance of the second point
projectionAlongLine - the projection along line in meter
Returns:
the bearing value for the line and -1.0 if the line is null

checkCoordinateBounds

public static boolean checkCoordinateBounds(double lon,
                                            double lat)
Check coordinate bounds.

Parameters:
lon - the lon
lat - the lat
Returns:
true, if coordinate is valid

intersectStraights

public static GeoCoordinates intersectStraights(GeoCoordinates coord1,
                                                double bear1,
                                                GeoCoordinates coord2,
                                                double bear2)
                                         throws InvalidMapDataException
Intersects two straights given by rsp. start points and initial bearings. The geodesic coordinates are interpreted as being sufficiently close to a equidistant cartesic coordinate system.

Parameters:
coord1 - the GeoCoordinates of the first straight's start point
bear1 - the bearing angle of the first straight
coord2 - the GeoCoordinates of the second straight's start point
bear2 - the bearing angle of the second straight
Returns:
the intersection point as a pair of lon/lat (Doubles)
Throws:
InvalidMapDataException - the invalid map data exception

intersectStraights

public static GeoCoordinates intersectStraights(double longitude1,
                                                double latitude1,
                                                double bear1,
                                                double longitude2,
                                                double latitude2,
                                                double bear2)
                                         throws InvalidMapDataException
Intersects two straights given by rsp. start points and initial bearings. The geodesic coordinates are interpreted as being sufficiently close to a equidistant cartesic coordinate system.

Parameters:
longitude1 - the longitude of the first straight's start point
latitude1 - the latitude of the first straight's start point
bear1 - the bearing angle of the first straight
longitude2 - the longitude of the second straight's start point
latitude2 - the latitude of the second straigth's start point
bear2 - the bearing angle of the second straight
Returns:
the intersection point as a pair of lon/lat (Doubles)
Throws:
InvalidMapDataException - the invalid map data exception

lineIntersection

public static boolean lineIntersection(GeoCoordinates gc1Start,
                                       GeoCoordinates gc1End,
                                       GeoCoordinates gc2Start,
                                       GeoCoordinates gc2End)
Line intersection.

Parameters:
gc1Start - the gc1 start
gc1End - the gc1 end
gc2Start - the gc2 start
gc2End - the gc2 end
Returns:
true, if successful

pointAlongLine

public static GeoCoordinates pointAlongLine(GeoCoordinates coord1,
                                            GeoCoordinates coord2,
                                            double offset)
                                     throws InvalidMapDataException
Calculates a point on the straight line defined by point a and b. The parameter offset defines the position of the desired point on that line relative to point a. If it is above 0 it will deliver a point in direction to point 2 or above. The offset can even be negative- it then defines a point in the opposite direction.

Parameters:
coord1 - the GeoCoordinates of the straight's start point
coord2 - the GeoCoordinates of the straight's end point
offset - The offset on the line from a to b measured from a. Can be in negative or positive direction.
Returns:
the calculated point on the line.
Throws:
InvalidMapDataException - If the calculation results in an invalid geo coordinate according to WGS84.

pointAlongLine

public static GeoCoordinates pointAlongLine(double longitudeA,
                                            double latitudeA,
                                            double longitudeB,
                                            double latitudeB,
                                            double offset)
                                     throws InvalidMapDataException
Calculates a point on the straight line defined by point a and b. The parameter offset defines the position of the desired point on that line relative to point a. If it is above 0 it will deliver a point in direction to point 2 or above. The offset can even be negative- it then defines a point in the opposite direction.

Parameters:
longitudeA - the longitude of the straight's start point
latitudeA - the latitude of the straight's start point
longitudeB - the longitude of the straight's end point
latitudeB - the latitude of the straight's end point
offset - The offset on the line from a to b measured from a. Can be in negative or positive direction.
Returns:
the calculated point on the line.
Throws:
InvalidMapDataException - If the calculation results in an invalid geo coordinate according to WGS84.

scaleUpperRightCoordinate

public static GeoCoordinates scaleUpperRightCoordinate(GeoCoordinates lowerLeft,
                                                       GeoCoordinates upperRight,
                                                       double xfactor,
                                                       double yfactor)
                                                throws InvalidMapDataException
Scale the upperright point of a rectangle given by lowerleft and upperright wrt to given factors in x- and y-direction.

Parameters:
lowerLeft - the lower left GeoCoordinates
upperRight - the upper right GeoCoordinates
xfactor - the scaling factor in x-direction
yfactor - the scaling factor in y-direction
Returns:
the pair (lon,lat) of the new rightmost
Throws:
InvalidMapDataException - the invalid map data exception

scaleUpperRightCoordinate

public static GeoCoordinates scaleUpperRightCoordinate(double lowerLeftLon,
                                                       double lowerLeftLat,
                                                       double upperRightLon,
                                                       double upperRightLat,
                                                       double xfactor,
                                                       double yfactor)
                                                throws InvalidMapDataException
Scale the upperright point of a rectangle given by lowerleft and upperright wrt to given factors in x- and y-direction.

Parameters:
lowerLeftLon - the longitude of the leftmost
lowerLeftLat - the latitude of the leftmost
upperRightLon - the longitude of the rightmost
upperRightLat - the latitude of the rightmost
xfactor - the scaling factor in x-direction
yfactor - the scaling factor in y-direction
Returns:
the pair (lon,lat) of the new rightmost
Throws:
InvalidMapDataException - the invalid map data exception

round

public static double round(double val)
Round.

Parameters:
val - the val
Returns:
the double

round

public static double round(double val,
                           int decimalPlaces)
Rounds a coordinate value (longitude or latitude) to a specific precision.

Parameters:
val - The coordinate value.
decimalPlaces - The number of decimal place to round to.
Returns:
The rounded value.

determineCoordinateInDistance

public static GeoCoordinates determineCoordinateInDistance(GeoCoordinates coord,
                                                           int angle,
                                                           double distanceKm)
                                                    throws InvalidMapDataException
Determine coordinate in distance.

Parameters:
coord - the GeoCoordinates the lon
angle - the angle
distanceKm - the distance in kilometers
Returns:
the geo coordinates
Throws:
InvalidMapDataException - the invalid map data exception

determineCoordinateInDistance

public static GeoCoordinates determineCoordinateInDistance(double lon,
                                                           double lat,
                                                           int angle,
                                                           double distanceKm)
                                                    throws InvalidMapDataException
Determine coordinate in distance.

Parameters:
lon - the lon
lat - the lat
angle - the angle
distanceKm - the distance in kilometers
Returns:
the geo coordinates
Throws:
InvalidMapDataException - the invalid map data exception


Copyright © 2013 TomTom International B.V.. All Rights Reserved.