Geo-Calc-XS
view release on metacpan or search on metacpan
lib/Geo/Calc/XS.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
B<Geo::Calc::XS> implements a variety of calculations for latitude/longitude points
All these formulas 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% ].
Benchmarking this module and L<Geo::Calc> I found out that this module is sometimes
more than 8000 times faster.
This module is designed to be thread-safe, although, of course,
interpreter-based threads are officially discouraged (see
lib/Geo/Calc/XS.pm view on Meta::CPAN
=cut
=head1 METHODS
=head2 distance_to
$gc->distance_to( $point[, $precision] )
$gc->distance_to( { lat => 40.422371, lon => -3.704298 } )
$gc->distance_to( Geo::Calc::XS->new( 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 ) ), in this object's distance unit.
=cut
lib/Geo/Calc/XS.pm view on Meta::CPAN
$gc->bearing_to( $point[, $precision] );
$gc->bearing_to( { lat => 40.422371, lon => -3.704298 }, -6 );
$gc->bearing_to( Geo::Calc::XS->new( 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 L<http://williams.best.vwh.net/avform.htm#Crs>
=cut
lib/Geo/Calc/XS.pm view on Meta::CPAN
See L<http://mathforum.org/library/drmath/view/51822.html> for derivation
=cut
=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.
C<$bearing> must be specified in degrees, where 0 is north and 90 is east, and
C<$distance> must be specified in this object's distance unit.
=cut
=head2 boundry_box
$gc->boundry_box( $width[, $height[, $precision]] );
$gc->boundry_box( 3, 4 ); # will generate a 3x4m box around the point, assuming the object's distance unit is meters
( run in 0.226 second using v1.01-cache-2.11-cpan-26ccb49234f )