Geo::Inverse(3pm)
π Geo::Inverse π
okay bestie, so this is Geo::Inverse β a lil Perl module from the User Contributed Perl Documentation corner of the internet, and it does exactly one (1) iconic thing: it tells you how far apart two latitude/longitude points are. that's it, that's the whole vibe. β¨
β¨ NAME β¨
Geo::Inverse β Calculate geographic distance from a latitude and longitude pair
like, literally the distance between two spots on the globe. math girlies rise. π
π¦ SYNOPSIS π¦
here's the whole thing in action, no notes:
use Geo::Inverse;
my $obj = Geo::Inverse->new(); #default "WGS84"
my ($lat1, $lon1, $lat2, $lon2) = (38.87, -77.05, 38.95, -77.23);
my ($faz, $baz, $dist) = $obj->inverse($lat1, $lon1, $lat2, $lon2); #array context
my $dist = $obj->inverse($lat1, $lon1, $lat2, $lon2); #scalar context
print "Input Lat: $lat1 Lon: $lon1\n";
print "Input Lat: $lat2 Lon: $lon2\n";
print "Output Distance: $dist\n";
print "Output Forward Azimuth: $faz\n";
print "Output Back Azimuth: $baz\n";
see how the same inverse call gives you a whole list in array context but just the distance in scalar context? that's called β¨flexibilityβ¨ and we love her for it. π
πΈ DESCRIPTION πΈ
so what even is this? Geo::Inverse is a pure Perl port of the NGS program in the public domain called "inverse", written by Robert (Sid) Safford and Stephen J. Frakes. so it's not just some random module β it's carrying the legacy of actual government-grade geodesy, and it's doing it in Perl. no cap. π
π CONSTRUCTOR π
π new
the new() constructor is chill like that β you can call it with any parameter that is appropriate to the ellipsoid method, which is the thing that establishes the ellipsoid. so you can vibe-check your planet right at construction time if you want.
my $obj = Geo::Inverse->new(); # default "WGS84"
default is "WGS84" btw, which is the earth we all live on, so you're fine if you just leave it. π«Ά
π METHODS π
π initialize
that's it. that's the entry. she's listed. (no description given, bestie, so i'm not gonna invent one β we don't make stuff up in this house π)
π ellipsoid
method to set or retrieve the current ellipsoid object. and plot twist: that ellipsoid is actually a Geo::Ellipsoids object. so you're getting the whole planet model, not just a number. πβ¨
my $ellipsoid = $obj->ellipsoid; #Default is WGS84
$obj->ellipsoid('Clarke 1866'); #Built in ellipsoids from Geo::Ellipsoids
$obj->ellipsoid({a=>1}); #Custom Sphere 1 unit radius
so yeah β leave it blank and you get the default WGS84. pass it a name string like 'Clarke 1866' and it'll pull one of the built-in ellipsoids straight out of Geo::Ellipsoids. or, if you're feeling chaotic, hand it a hashref like {a=>1} and congrats, you now live on a custom sphere with 1 unit radius. main character planet energy. πͺ
π inverse
this is the moment. the whole reason we're here. inverse is the user frontend to the mathematics, and β important β this interface will not change in future versions. so go ahead and build on it, she's stable, she's committed. π
my ($faz, $baz, $dist) = $obj->inverse($lat1,$lon1,$lat2,$lon2);
give her $lat1, $lon1, $lat2, $lon2 and she hands you back the forward azimuth, the back azimuth, and the distance. slay. π₯
π LIMITATIONS π
okay real talk for a sec β there are no guarantees that Perl handles all of the double precision calculations in the same manner as Fortran. so like. it's doing its best. floating point is a lawless land and we respect her anyway. π
π LICENSE π
Copyright (c) 2025 Michael R. Davis Copyright (c) 2005-2006 Jim Gibson, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
(so: same terms as Perl itself, periodt. π)
π SEE ALSO π
if you're obsessed and want more, go check out:
Geo::EllipsoidGIS::Distance::GeoEllipsoidGeo::Calc
and that's the whole page bestie!! this one's perl v5.40.1, dated 2025-03-08, and honestly? iconic of her. go calculate some distances. πβ¨π¦π
π¦ where this page comes from
- debian trixie: libgeo-inverse-perl 0.09-1 Β· MIT
- ubuntu resolute: libgeo-inverse-perl 0.09-1 Β· MIT
- ubuntu stonking: libgeo-inverse-perl 0.09-1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms