diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/Alert.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Tilma/Original.pm | 5 | ||||
-rw-r--r-- | perllib/Utils.pm | 28 |
5 files changed, 27 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/Alert.pm b/perllib/FixMyStreet/Alert.pm index 45985502f..cdc070290 100644 --- a/perllib/FixMyStreet/Alert.pm +++ b/perllib/FixMyStreet/Alert.pm @@ -30,7 +30,6 @@ use mySociety::DBHandle qw(dbh); use mySociety::Email; use mySociety::EmailUtil; use mySociety::Gaze; -use mySociety::GeoUtil; use mySociety::Locale; use mySociety::MaPit; use mySociety::Random qw(random_bytes); diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 9ab958cd9..14cedbaeb 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -18,8 +18,8 @@ use URI::Escape; use Cobrand; use Page; +use Utils; use mySociety::Config; -use mySociety::GeoUtil; use mySociety::Locale; use mySociety::MaPit; use mySociety::PostcodeUtil; @@ -63,9 +63,7 @@ sub geocoded_string_coordinates { $longitude = $1; $latitude = $2; try { - my ($easting, $northing) = mySociety::Locale::in_gb_locale { - mySociety::GeoUtil::wgs84_to_national_grid($latitude, $longitude, 'G'); - }; + my ($easting, $northing) = Utils::convert_latlon_to_en( $latitude, $longitude ); } catch Error::Simple with { $error = shift; $error = _('That location does not appear to be in Britain; please try again.') diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index 0902914dd..a9978103f 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -14,7 +14,6 @@ use Problems; use Cobrand; use mySociety::Config; use mySociety::Gaze; -use mySociety::GeoUtil qw(national_grid_to_wgs84); use mySociety::Locale; use mySociety::Web qw(ent NewURL); use Utils; diff --git a/perllib/FixMyStreet/Map/Tilma/Original.pm b/perllib/FixMyStreet/Map/Tilma/Original.pm index 4dc4a5817..e32d62442 100644 --- a/perllib/FixMyStreet/Map/Tilma/Original.pm +++ b/perllib/FixMyStreet/Map/Tilma/Original.pm @@ -12,16 +12,13 @@ use strict; use LWP::Simple; use Cobrand; -use mySociety::GeoUtil; use mySociety::Locale; use mySociety::Web qw(ent NewURL); use Utils; sub _ll_to_en { my ($lat, $lon) = @_; - return mySociety::Locale::in_gb_locale { - mySociety::GeoUtil::wgs84_to_national_grid( $lat, $lon, 'G' ); - }; + return Utils::convert_latlon_to_en( $lat, $lon ); } sub header_js { 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 |