diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-02-22 14:25:17 +0000 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-02-22 14:25:17 +0000 |
commit | 7da8f20c36726fd205ae48130f07db49fab745e0 (patch) | |
tree | 9573ce8c11fd8a067ad74a1aedb452784654b076 /perllib/Utils.pm | |
parent | 36e118f44144e24e6f1a98ea845b4cc2fed799d8 (diff) | |
parent | a88db262384d3800c36589bb6d1a933b9319e2df (diff) |
Merge branch 'master' into migrate_to_catalyst
Diffstat (limited to 'perllib/Utils.pm')
-rw-r--r-- | perllib/Utils.pm | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/perllib/Utils.pm b/perllib/Utils.pm index d54e081c8..21994d20b 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -14,6 +14,7 @@ package Utils; use strict; use mySociety::DBHandle qw(dbh); use mySociety::GeoUtil; +use mySociety::Locale; sub workaround_pg_bytea { my ( $st, $img_idx, @elements ) = @_; @@ -33,11 +34,30 @@ sub workaround_pg_bytea { $s->execute(); } +=head2 convert_latlon_to_en + + ( $easting, $northing ) = Utils::convert_en_to_latlon( $latitude, $longitude ); + +Takes the WGS84 latitude and longitude and returns OSGB36 easting and northing. + +=cut + +sub convert_latlon_to_en { + my ( $latitude, $longitude ) = @_; + + my ( $easting, $northing ) = + mySociety::Locale::in_gb_locale { + mySociety::GeoUtil::wgs84_to_national_grid( $latitude, $longitude, 'G' ); + }; + + return ( $easting, $northing ); +} + =head2 convert_en_to_latlon ( $latitude, $longitude ) = Utils::convert_en_to_latlon( $easting, $northing ); -Takes the easting and northing and returns latitude and longitude. +Takes the OSGB36 easting and northing and returns WGS84 latitude and longitude. =cut @@ -56,8 +76,8 @@ sub convert_en_to_latlon { ( $lat, $lon ) = Utils::convert_en_to_latlon( $easting, $northing ); -Takes the easting and northing and returns latitude and longitude (truncated -using C<Utils::truncate_coordinate>). +Takes the OSGB36 easting and northing and returns WGS84 latitude and longitude +(truncated using C<Utils::truncate_coordinate>). =cut @@ -74,13 +94,15 @@ sub convert_en_to_latlon_truncated { $short = Utils::truncate_coordinate( $long ); Given a long coordinate returns a shorter one - rounded to 6 decimal places - -which is < 1m at the equator. +which is < 1m at the equator, if you're using WGS84 lat/lon. =cut sub truncate_coordinate { my $in = shift; - my $out = sprintf( '%0.6f', $in ); + my $out = mySociety::Locale::in_gb_locale { + sprintf( '%0.6f', $in ); + }; $out =~ s{\.?0+\z}{} if $out =~ m{\.}; return $out; } |