source: trunk/npemap.org.uk/perllib/NPEMap/GeoConverter.pm @ 461

Last change on this file since 461 was 461, checked in by Nick Burch, 13 years ago

Pull out e+n -> lat+long into a npemap perl module, and use from the geocoder

  • Property svn:eol-style set to native
File size: 970 bytes
Line 
1package NPEMap::GeoConverter;
2
3use vars qw(@ISA @EXPORT);
4use warnings;
5use strict;
6
7use vars qw($tt_config);
8
9use FindBin;
10use lib "$FindBin::Bin/../";
11
12# Include stuff, so we can offer lat+long
13use Geo::HelmertTransform;
14use Geography::NationalGrid;
15use Geography::NationalGrid::GB;
16
17require Exporter;
18@ISA    = qw(Exporter);
19@EXPORT = qw(eastingNorthingToLatLong);
20
21sub eastingNorthingToLatLong {
22        my ($e,$n) = @_;
23
24        # Turn e+n into OSGB lat+long
25        my $point = Geography::NationalGrid::GB->new( Easting=>$e, Northing=>$n );
26        my $oslat = $point->latitude;
27        my $oslong = $point->longitude;
28
29        # Turn OSGB lat+long into WGS84 lat+long
30        my $osgb_helper = Geo::HelmertTransform::datum("Airy1830");
31        my $wgs84_helper = Geo::HelmertTransform::datum('WGS84');
32
33        my ($lat,$long,$h) = 
34                Geo::HelmertTransform::convert_datum($osgb_helper, $wgs84_helper, $oslat, $oslong, 0);
35
36        return ($lat,$long);
37}
38
39############################################################################
40
Note: See TracBrowser for help on using the repository browser.