Nigel.Wetters at lshtm.ac.uk
Fri Sep 5 08:27:16 PDT 2003
I've just uploaded a module to CPAN named Geo::Approx. It should hit the
mirrors tomorrow morning. Basically, it provides methods for converting
between a single integer, representing a positoon, to a longitude and
latitude, and it does this at various precisions (the integer can be 0
to 32 bits in length).
Here's the POD
Geo::Approx - represents an approximate global position by a single
my $ga = Geo::Approx($precision);
my $pos = $ga->latlon2int($lat,$lon);
my ($approx_lat,$approx_lon) = $ga->int2latlon($pos);
It is sometimes useful to condense the information present in a
latitude and longitude into a single number (for example, when storing
the position within a database). This module provides methods for
this conversion. By default, the precision of the position is set
at 32 bits
Assuming the surface area of the earth is 5.1 x 10^8 sq km, the area
represented by the single number at each precision is as follows:
0.12 sq km at 32 bits
0.24 sq km at 31 bits
0.47 sq km at 30 bits
0.95 sq km at 29 bits
and so on (5.1E8 / 2^precision)
These areas are constant across all latitudes and longitudes.
Thus, if you want to be fairly precise about positions, you can store
fairly large numbers, whereas if you want to be fairly imprecise,
you can use small numbers.
The constructor takes one optional argument - a number between zero
and 32 indicating precision.
my $ga = Geo::Aprox->new(24);
By default, the precision is 32 bits.
=head1 OBJECT METHODS
=item $pos = $ga-E<gt>latlon2int($lat,$lon);
Converts a latitude and longitude to an integer integer representing
position. Latitude must be between -90 and 90. Longitude must be
between -180 and 180.
=item ($lat,$lon) = $ga-E<gt>int2latlon($pos);
Converts a position represented by an integer into a latitude and
=head1 SEE ALSO
the post that raised my interest.
Copyright (C) 2002,2003 Nigel Wetters. All Rights Reserved.
NO WARRANTY. This module is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
More information about the Geowanking