Geo-Coordinates-OSGB

 view release on metacpan or  search on metacpan

lib/Geo/Coordinates/OSGB/Grid.pm  view on Meta::CPAN

    my $w = 0;
    for (my $i=0; $i < $#$poly; $i++ ) {
        if ( $poly->[$i][1] <= $y ) {
            if ($poly->[$i+1][1]  > $y && _is_left($x, $y, $poly->[$i], $poly->[$i+1]) > 0 ) {
                $w++;
            }
        }
        else {
            if ($poly->[$i+1][1] <= $y && _is_left($x, $y, $poly->[$i], $poly->[$i+1]) < 0 ) {
                $w--;
            }
        }
    }
    return $w;
}

1;

__END__

=pod

=head1 NAME

Geo::Coordinates::OSGB::Grid - Format and parse British National Grid references

=head1 VERSION

2.20

=head1 SYNOPSIS

  use Geo::Coordinates::OSGB::Grid qw/parse_grid format_grid/;

  my ($e,$n) = parse_grid('TQ 23451 09893');
  my $gr     = format_grid($e, $n); # "TQ 234 098"

=head1 DESCRIPTION

This module provides useful functions for parsing and formatting OSGB
grid references.  Some detailed background is given in C<background.pod>
and on the OS web site.

=head1 SUBROUTINES AND METHODS

=head2 C<format_grid(e, n)>

Formats an (easting, northing) pair into traditional `full national grid
reference' with two letters and two sets of three numbers, like this `SU
387 147'.

    $gridref = format_grid(438710.908, 114792.248); # SU 387 147

If you want the individual components call it in a list context.

    ($sq, $e, $n) = format_grid(438710.908, 114792.248); # ('SU', 387, 147)

Note that rather than being rounded, the easting and northing are
B<truncated> to hectometres (as the OS system demands), so the grid
reference refers to the lower left corner of the relevant 100m square.
The system is described below the legend on all OS Landranger maps.

The format grid routine takes an optional third argument to control the
form of grid reference returned.  This should be a hash reference with
one or more of the keys shown below (with the default values).

    format_grid(e, n, {form => 'SS EEE NNN', maps => 0, series => 'ABCHJ'})

=head3 Options for C<format_grid>

=over 4

=item form

Controls the format of the grid reference.  With C<$e, $n> set as above:

    Format          produces        Format            produces
    ----------------------------------------------------------------
    'SS'            SU
    'SSEN'          SU31            'SS E N'          SU 3 1
    'SSEENN'        SU3814          'SS EE NN'        SU 38 14
    'SSEEENNN'      SU387147        'SS EEE NNN'      SU 387 147
    'SSEEEENNNN'    SU38711479      'SS EEEE NNNN'    SU 3871 1479
    'SSEEEEENNNNN'  SU3871014792    'SS EEEEE NNNNN'  SU 38710 14792

You can't leave out the SS, you can't have N before E, and there must be
the same number of Es and Ns.

There are two other special formats:

     form => 'TRAD' is equivalent to form => 'SS EEE NNN'
     form => 'GPS'  is equivalent to form => 'SS EEEEE NNNNN'

In a list context, this option means that the individual components are
returned appropriately truncated as shown.  So with C<SS EEE NNN> you
get back C<('SU', 387, 147)> and B<not> C<('SU', 387.10908, 147.92248)>.
The format can be given as upper case or lower case or a mixture.  If
you want just the local easting and northing without the grid square,
get the individual parts in a list context and format them yourself:

    my $gr = sprintf('Grid ref %2$s %3$s on Sheet %4$s', format_grid_landranger($e, $n))
    # returns: Grid ref 387 147 on Sheet 196

=item maps

Controls whether to include a list of map sheets after the grid
reference.  Set it to 1 (or any true value) to include the list, and to
0 (or any false value) to leave it out.  The default is C<< maps => 0
>>.

In a scalar context you get back a string like this:

    SU 387 147 on A:196, B:OL22E, C:180

In a list context you get back a list like this:

    ('SU', 387, 147, A:196, B:OL22E, C:180)

=item series

This option is only used when C<maps> is true.  It controls which series



( run in 1.795 second using v1.01-cache-2.11-cpan-13bb782fe5a )