aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Utils.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@fury.ukcod.org.uk>2011-02-11 11:14:20 +0000
committerMatthew Somerville <matthew@fury.ukcod.org.uk>2011-02-11 11:14:20 +0000
commit947f5f9d6c9c74bc5acea7fbc605b653e44f7ce7 (patch)
tree05f70a75d4f473274e897e8951ff71035c1890fb /perllib/Utils.pm
parentc8a9805bcb850cab7bf1c1b8c34ef5c4f22e1b73 (diff)
Helper function for all latlon to OSGB36 calls.
Diffstat (limited to 'perllib/Utils.pm')
-rw-r--r--perllib/Utils.pm28
1 files changed, 24 insertions, 4 deletions
diff --git a/perllib/Utils.pm b/perllib/Utils.pm
index d54e081c8..91dab033a 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,7 +94,7 @@ 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