Geo-Calc
view release on metacpan or search on metacpan
- now returns numbers not strings
- added more tests
- code cleaning
version 0.04: Mon Feb 14 07:41:45 EST 2011
- fixed the boundry_box bug ( used the default 45 deg always )
- cleaned up the POD
- added distance_at and tests for it
- changed destination_point to destination_point_hs
- added destination_point using Vincenty inverse formula for ellipsoids
- new destination_point uses meters insted of km
- changed boundry_box to meters
version 0.03: Wed Feb 9 06:31:18 EST 2011
- speed impriovements
- changed from sub to method using MooseX::Method::Signatures
version 0.02: Tue Feb 8 11:31:35 EST 2011
lib/Geo/Calc.pm view on Meta::CPAN
my $bbox = $gc->boundry_box( 3, 4, -6 );
my $r_distance = $gc->rhumb_distance_to( { lat => 40.422371, lon => -3.704298 }, -6 );
my $r_brng = $gc->rhumb_bearing_to( { lat => 40.422371, lon => -3.704298 }, -6 );
my $r_destination = $gc->rhumb_destination_point( 30, 1, -6 );
my $point = $gc->intersection( 90, { lat => 40.422371, lon => -3.704298 }, 180, -6 );
=head1 DESCRIPTION
C<Geo::Calc> implements a variety of calculations for latitude/longitude points
All these formulare are for calculations on the basis of a spherical earth
(ignoring ellipsoidal effects) which is accurate enough* for most purposes.
[ In fact, the earth is very slightly ellipsoidal; using a spherical model
gives errors typically up to 0.3% ].
=head1 Geo::Calc->new()
$gc = Geo::Calc->new( lat => 40.417875, lon => -3.710205 ); # Somewhere in Madrid
$gc = Geo::Calc->new( lat => 51.503269, lon => 0, units => 'k-m' ); # The O2 Arena in London
lib/Geo/Calc.pm view on Meta::CPAN
}
}
=head1 METHODS
=head2 distance_to
$gc->distance_to( $point[, $precision] )
$gc->distance_to( { lat => 40.422371, lon => -3.704298 } )
This uses the "haversine" formula to calculate great-circle distances between
the two points - that is, the shortest distance over the earth's surface -
giving an `as-the-crow-flies` distance between the points (ignoring any hills!)
The haversine formula `remains particularly well-conditioned for numerical
computation even at small distances` - unlike calculations based on the spherical
law of cosines. It was published by R W Sinnott in Sky and Telescope, 1984,
though known about for much longer by navigators. (For the curious, c is the
angular distance in radians, and a is the square of half the chord length between
the points).
Returns with the distance using the precision defined or -6
( -6 = 6 decimals ( eg 4.000001 ) )
=cut
lib/Geo/Calc.pm view on Meta::CPAN
$gc->bearing_to( $point[, $precision] );
$gc->bearing_to( { lat => 40.422371, lon => -3.704298 }, -6 );
In general, your current heading will vary as you follow a great circle path
(orthodrome); the final heading will differ from the initial heading by varying
degrees according to distance and latitude (if you were to go from say 35N,45E
(Baghdad) to 35N,135E (Osaka), you would start on a heading of 60 and end up on
a heading of 120!).
This formula is for the initial bearing (sometimes referred to as forward
azimuth) which if followed in a straight line along a great-circle arc will take
you from the start point to the end point
Returns the (initial) bearing from this point to the supplied point, in degrees
with the specified pricision
see http://williams.best.vwh.net/avform.htm#Crs
=cut
lib/Geo/Calc.pm view on Meta::CPAN
lon => $self->_precision( Math::Trig::rad2deg($lon3), $precision ),
};
}
=head2 destination_point
$gc->destination_point( $bearing, $distance[, $precision] );
$gc->destination_point( 90, 1 );
Returns the destination point and the final bearing using Vincenty inverse
formula for ellipsoids.
=cut
method destination_point ( Num $brng!, Num $s!, Int $precision? = -6 ) returns (HashRef[Num]) {
my $lat1 = $self->get_lat();
my $lon1 = $self->get_lon();
$s = Math::Units::convert( $s, $self->get_units(), 'm' );
my $r_major = 6378137; # Equatorial Radius, WGS84
( run in 2.954 seconds using v1.01-cache-2.11-cpan-3cd7ad12f66 )