File: ll_to_bng.pl

package info (click to toggle)
libgeo-coordinates-osgb-perl 2.06-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,300 kB
  • ctags: 55
  • sloc: perl: 310,920; makefile: 7
file content (36 lines) | stat: -rw-r--r-- 904 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/perl -w

# Toby Thurston ---  6 May 2009
# Parse LL and show as National Grid ref

use strict;
use warnings;

use Geo::Coordinates::OSGB qw/
        parse_ISO_ll
        ll_to_grid
        shift_ll_from_WGS84
        format_ll_trad
        format_grid_trad
        format_grid_landranger/;

if ( @ARGV == 0 ) {
    die "Usage: $0 lat lon\n"
}

my ($lat, $lon);
if ( @ARGV == 1 ) {
    ($lat, $lon) = parse_ISO_ll($ARGV[0]);
} else {
    ($lat, $lon) = @ARGV;
}

my ($gla, $glo, undef) = shift_ll_from_WGS84($lat, $lon);
my ($ge, $gn) = ll_to_grid($gla, $glo);
my ($e,  $n)  = ll_to_grid($lat, $lon);

print "Your input: @ARGV\n";
printf "is %s\n", scalar format_ll_trad($lat, $lon);

printf "== %d %d from OSGB  (%s)\n", $e, $n, scalar format_grid_landranger($e, $n);
printf "or %d %d from WGS84 (%s)\n", $ge, $gn, scalar format_grid_landranger($ge, $gn);