Geo::Inverse(3pm)

πŸ“¦
version 0.09 Β· 5 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– 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::Ellipsoid
  • GIS::Distance::GeoEllipsoid
  • Geo::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