Geo-CheapRuler
view release on metacpan or search on metacpan
Geo::CheapRuler
A collection of very fast approximations to common geodesic measurements. Useful for performance-sensitive code that measures things on a city scale (less than 500km, not near the poles). Can be an order of magnitude faster than Haversine based metho...
A Perl port of Mapbox's cheap-ruler v4.0.0 https://github.com/mapbox/cheap-ruler
Very fast as they use just 1 trig function per call.
The Maths model is based upon the Earth's actual shape (a squashed sphere). For 'city' scale work, it is more accurate than
the Haversine formulae (which uses several trig calls based upon a spherical Earth). The Cheap\_Ruler Github page explains it better!
See:
https://github.com/aavmurphy/CheapRuler/REAME.md
INSTALLATION
To install this module, run the following commands:
perl Makefile.PL
lib/Geo/CheapRuler.pm view on Meta::CPAN
A collection of very fast approximations to common geodesic measurements. Useful for performance-sensitive code that measures things on a city scale (less than 500km, not near the poles).
Can be an order of magnitude faster than Haversine based methods.
A Perl port of Mapbox's cheap-ruler v4.0.0 https://github.com/mapbox/cheap-ruler
Very fast as they use just 1 trig function per call.
=head1 MATHS MODEL
The Maths model is based upon an approximation to Vincenty's formulae, which uses the Earth's actual shape, an oblate ellipsoid (squashed sphere). For 'city' scale work, it is still more accurate than
the Haversine formulae (which uses several trig calls based upon a spherical Earth). For an explanation, see
https://blog.mapbox.com/fast-geodesic-approximations-with-cheap-ruler-106f229ad016
=head1 EXPORT
Nothing
=head1 WEBSITE
https://github.com/aavmurphy/CheapRuler
lib/Geo/CheapRuler.pm view on Meta::CPAN
$ruler = CheapRuler->new(35.05, 'miles');
=cut
sub new ( $class, $lat, $units='kilometers' ) {
croak( 'No latitude given.') if ! defined $lat;
croak( "Unknown unit $units. Use one of: " + join( ', ', keys(%FACTORS) ) ) if $units && ! $FACTORS{ $units };
my $self = bless {};
# Curvature formulas from https://en.wikipedia.org/wiki/Earth_radius#Meridional
my $m = $RAD * $RE * ( $units ? $FACTORS{ $units } : 1 );
my $coslat = cos( $lat * $RAD );
my $w2 = 1 / (1 - $E2 * (1 - $coslat**2) );
my $w = sqrt($w2);
# multipliers for converting longitude and latitude degrees into distance
$self->{kx} = $m * $w * $coslat; # based on normal radius of curvature
$self->{ky} = $m * $w * $w2 * (1 - $E2); # based on meridonal radius of curvature
return $self;
lib/Geo/CheapRuler.pm view on Meta::CPAN
return $deg;
}
=head1 SEE ALSO
GIS::Distance
https://metacpan.org/pod/GIS::Distance
Group of modules with XS versions which implement Haversine and Vincenty distance formulas
Consider for longer than 'city scale' distances, or near the Poles.
GIS::Distance::Vincenty
The more accurate formulae which this module approximates. There is an XS version of it.
https://metacpan.org/pod/GIS::Distance::Vincenty
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Geo::CheapRuler
Or at
( run in 0.575 second using v1.01-cache-2.11-cpan-179a2ef0c17 )