diff options
-rwxr-xr-x | bin/test-run | 23 | ||||
-rw-r--r-- | db/migrate_from_osgb36_to_wgs84.pl | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Tilma/Original.pm | 5 | ||||
-rwxr-xr-x | web/alert.cgi | 5 | ||||
-rwxr-xr-x | web/import.cgi | 4 | ||||
-rwxr-xr-x | web/index.cgi | 17 | ||||
-rwxr-xr-x | web/rss.cgi | 10 |
8 files changed, 48 insertions, 34 deletions
diff --git a/bin/test-run b/bin/test-run index 69e29f4f1..85ce87797 100755 --- a/bin/test-run +++ b/bin/test-run @@ -34,6 +34,7 @@ use File::Find; use lib "$FindBin::Bin/../perllib"; use Cobrand; use FixMyStreet::Geocode; +use Utils; my @actions = ('report', 'update', 'questionnaire', 'alert', 'static', 'cobrand', 'unit', 'eha_alert', 'import', 'rss'); my %actions_desc = ( @@ -216,10 +217,10 @@ sub submit_report { my ($postcode, $x, $y, $easting, $northing, $user_num, $council, $texts, $cobrand ) = @_; my @messages = @{$texts}; - # convert easting, northing to lat lon - my ( $latitude, $longitude ) = - mySociety::GeoUtil::national_grid_to_wgs84( $easting, $northing, 'G' ); - + # convert easting, northing to lat lon + ( $latitude, $longitude ) = + Utils::convert_en_to_latlon( $easting, $northing ); + submit_postcode($cobrand, $postcode, $messages[0]); { # Writing values to hidden fields, so switching @@ -392,7 +393,9 @@ sub do_alert { my $n = 673533; # get the lat,lon from the postcode so that it matches - my ( $lat, $lon ) = FixMyStreet::Geocode::lookup( $postcode, undef ); + my ( $lat, $lon ) = + map { Utils::truncate_coordinate($_) } + FixMyStreet::Geocode::lookup( $postcode, undef ); my $messages = english_fms_messages(); submit_postcode('', $postcode, 'Problems in this area'); @@ -436,7 +439,9 @@ sub do_eha_alert { my $y = 4175; my $n = 673533; # get the lat,lon from the postcode so that it matches - my ( $lat, $lon ) = FixMyStreet::Geocode::lookup( $postcode, undef ); + my ( $lat, $lon ) = + map { Utils::truncate_coordinate($_) } + FixMyStreet::Geocode::lookup( $postcode, undef ); my @texts = ('Eiddo gwag yn yr ardal hon', 'Adrodd am eiddo gwag', @@ -536,9 +541,9 @@ sub do_rss { my %redirects = ( # should always go to lat lon - '/rss/n/406886,289126' => '/rss/l/52.4999935999706,-1.89999324167977', - '/rss/2524/1779' => '/rss/l/52.4802940052892,-1.89693098994692', - '/rss/pc/SW1A1AA' => '/rss/l/51.5010096115539,-0.141587067110009', + '/rss/n/406886,289126' => '/rss/l/52.499993,-1.899993', + '/rss/2524/1779' => '/rss/l/52.480294,-1.896931', + '/rss/pc/SW1A1AA' => '/rss/l/51.501010,-0.141587', '/rss/l/52.5/-1.9' => '/rss/l/52.5/-1.9', # go to reports diff --git a/db/migrate_from_osgb36_to_wgs84.pl b/db/migrate_from_osgb36_to_wgs84.pl index 0861659a0..62eac8296 100644 --- a/db/migrate_from_osgb36_to_wgs84.pl +++ b/db/migrate_from_osgb36_to_wgs84.pl @@ -16,7 +16,7 @@ use lib "$FindBin::Bin/../commonlib/perllib"; use mySociety::Config; use mySociety::DBHandle qw(dbh); -use mySociety::GeoUtil qw(national_grid_to_wgs84); +use Utils; BEGIN { mySociety::Config::set_file("$FindBin::Bin/../conf/general"); @@ -74,7 +74,7 @@ sub migrate_problem_table { last unless $rows_to_convert_query->rows; while ( my $r = $rows_to_convert_query->fetchrow_hashref ) { my ( $latitude, $longitude ) = - _e_n_to_lat_lon( $r->{easting}, $r->{northing} ); + Utils::convert_en_to_latlon( $r->{easting}, $r->{northing} ); print "update problem $r->{id}: ( $latitude, $longitude )\n"; $update_lat_lon_query->execute( $latitude, $longitude, $r->{id} ); } @@ -187,7 +187,7 @@ sub migrate_alert_table { last unless $rows_to_convert_query->rows; while ( my $r = $rows_to_convert_query->fetchrow_hashref ) { my ( $latitude, $longitude ) = - _e_n_to_lat_lon( $r->{parameter}, $r->{parameter2} ); + Utils::convert_en_to_latlon( $r->{parameter}, $r->{parameter2} ); print "update alert $r->{id}: ( $latitude, $longitude )\n"; $update_lat_lon_query->execute( $latitude, $longitude, $r->{id} ); } @@ -199,12 +199,3 @@ sub migrate_alert_table { $dbh->commit; } -=head2 HELPERS - -=cut - -sub _e_n_to_lat_lon { - my ( $e, $n ) = @_; - my ( $lat, $lon ) = national_grid_to_wgs84( $e, $n, 'G' ); - return ( $lat, $lon ); -} diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index 0313fbe4f..0902914dd 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -17,6 +17,7 @@ use mySociety::Gaze; use mySociety::GeoUtil qw(national_grid_to_wgs84); use mySociety::Locale; use mySociety::Web qw(ent NewURL); +use Utils; # Run on module boot up load(); @@ -60,7 +61,7 @@ conversion. sub map_features_easting_northing { my ( $q, $easting, $northing, $interval ) = @_; - my ( $lat, $lon ) = national_grid_to_wgs84( $easting, $northing, 'G' ); + my ( $lat, $lon ) = Utils::convert_en_to_latlon( $easting, $northing ); return map_features( $q, $lat, $lon, $interval ); } diff --git a/perllib/FixMyStreet/Map/Tilma/Original.pm b/perllib/FixMyStreet/Map/Tilma/Original.pm index 5f5a102ac..81b123b30 100644 --- a/perllib/FixMyStreet/Map/Tilma/Original.pm +++ b/perllib/FixMyStreet/Map/Tilma/Original.pm @@ -13,7 +13,8 @@ use LWP::Simple; use Cobrand; use mySociety::Web qw(ent NewURL); -use mySociety::GeoUtil qw(national_grid_to_wgs84); +use mySociety::GeoUtil; +use Utils; sub _ll_to_en { my ($lat, $lon) = @_; @@ -239,7 +240,7 @@ sub tile_xy_to_wgs84 { my $easting = tile_to_os($x); my $northing = tile_to_os($y); - my ( $lat, $lon ) = national_grid_to_wgs84( $easting, $northing, 'G' ); + my ( $lat, $lon ) = Utils::convert_en_to_latlon( $easting, $northing ); return ( $lat, $lon ); } diff --git a/web/alert.cgi b/web/alert.cgi index d5d7cff13..896ca9ccc 100755 --- a/web/alert.cgi +++ b/web/alert.cgi @@ -24,6 +24,7 @@ use mySociety::MaPit; use mySociety::VotingArea; use mySociety::Web qw(ent); use Cobrand; +use Utils; sub main { my $q = shift; @@ -87,6 +88,10 @@ sub alert_list { $error = shift; }; } + + # truncate the lat,lon for nicer urls + ( $lat, $lon ) = map { Utils::truncate_coordinate($_) } ( $lat, $lon ); + return FixMyStreet::Geocode::list_choices($error, '/alert', $q) if ref($error) eq 'ARRAY'; return alert_front_page($q, $error) if $error; diff --git a/web/import.cgi b/web/import.cgi index 0f807ecb0..e7746f589 100755 --- a/web/import.cgi +++ b/web/import.cgi @@ -16,7 +16,7 @@ use mySociety::AuthToken; use mySociety::Config; use mySociety::EmailUtil; use mySociety::EvEl; -use mySociety::GeoUtil qw(national_grid_to_wgs84); +use mySociety::GeoUtil; sub main { my $q = shift; @@ -41,7 +41,7 @@ sub main { ) { ( $latitude, $longitude ) = - national_grid_to_wgs84( $input{easting}, $input{northing}, 'G' ); + Utils::convert_en_to_latlon( $input{easting}, $input{northing}); } my $fh = $q->upload('photo'); # MUST come before $q->header, don't know why! diff --git a/web/index.cgi b/web/index.cgi index 41f913dd1..62a882e6b 100755 --- a/web/index.cgi +++ b/web/index.cgi @@ -24,13 +24,14 @@ use mySociety::AuthToken; use mySociety::Config; use mySociety::DBHandle qw(select_all); use mySociety::EmailUtil; -use mySociety::GeoUtil qw(national_grid_to_wgs84); +use mySociety::GeoUtil; use mySociety::Locale; use mySociety::MaPit; use mySociety::PostcodeUtil; use mySociety::Random; use mySociety::VotingArea; use mySociety::Web qw(ent NewURL); +use Utils; sub debug (@) { return; @@ -792,7 +793,7 @@ sub redirect_from_osgb_to_wgs84 { my $e = $q->param('e'); my $n = $q->param('n'); - my ( $lat, $lon ) = national_grid_to_wgs84( $e, $n, 'G' ); + my ( $lat, $lon ) = Utils::convert_en_to_latlon_truncated( $e, $n ); my $lat_lon_url = NewURL( $q, @@ -929,6 +930,12 @@ sub display_location { 'submit_map'=>1, skipped=>1 ); my $pc_h = ent($q->param('pc') || ''); + + # truncate the lat,lon for nicer rss urls + my ( $short_lat, $short_lon ) = + map { Utils::truncate_coordinate($_) } # + ( $latitude, $longitude ); + my %vars = ( 'map' => FixMyStreet::Map::display_map($q, latitude => $latitude, longitude => $longitude, @@ -938,8 +945,8 @@ sub display_location { ), map_end => FixMyStreet::Map::display_map_end(1), url_home => Cobrand::url($cobrand, '/', $q), - url_rss => Cobrand::url($cobrand, NewURL($q, -retain => 1, -url=> "/rss/l/$latitude,$longitude", pc => undef, x => undef, y => undef, lat => undef, lon => undef ), $q), - url_email => Cobrand::url($cobrand, NewURL($q, -retain => 1, pc => undef, lat => $latitude, lon => $longitude, -url=>'/alert', feed=>"local:$latitude:$longitude"), $q), + url_rss => Cobrand::url($cobrand, NewURL($q, -retain => 1, -url=> "/rss/l/$short_lat,$short_lon", pc => undef, x => undef, y => undef, lat => undef, lon => undef ), $q), + url_email => Cobrand::url($cobrand, NewURL($q, -retain => 1, pc => undef, lat => $short_lat, lon => $short_lon, -url=>'/alert', feed=>"local:$short_lat:$short_lon"), $q), url_skip => $url_skip, email_me => _('Email me new local problems'), rss_alt => _('RSS feed'), @@ -959,7 +966,7 @@ sub display_location { ); my %params = ( - rss => [ _('Recent local problems, FixMyStreet'), "/rss/l/$latitude,$longitude" ], + rss => [ _('Recent local problems, FixMyStreet'), "/rss/l/$short_lat,$short_lon" ], robots => 'noindex,nofollow', ); diff --git a/web/rss.cgi b/web/rss.cgi index 9dcd9a3b4..9a9b4ce18 100755 --- a/web/rss.cgi +++ b/web/rss.cgi @@ -17,6 +17,7 @@ use FixMyStreet::Geocode; use mySociety::MaPit; use mySociety::GeoUtil; use mySociety::Gaze; +use Utils; sub main { my $q = shift; @@ -87,11 +88,11 @@ sub rss_local_problems { # 5000/31 as initial scale factor for these RSS feeds, now variable so redirect. $e = int( ($x * 5000/31) + 0.5 ); $n = int( ($y * 5000/31) + 0.5 ); - ($lat, $lon) = mySociety::GeoUtil::national_grid_to_wgs84($e, $n, 'G'); + ($lat, $lon) = Utils::convert_en_to_latlon($e, $n); print $q->redirect(-location => "$base/rss/l/$lat,$lon$d_str$state_qs"); return ''; } elsif ($e && $n) { - ($lat, $lon) = mySociety::GeoUtil::national_grid_to_wgs84($e, $n, 'G'); + ($lat, $lon) = Utils::convert_en_to_latlon($e, $n); print $q->redirect(-location => "$base/rss/l/$lat,$lon$d_str$state_qs"); return ''; } elsif ($pc) { @@ -110,7 +111,10 @@ sub rss_local_problems { } else { die "Missing E/N, x/y, lat/lon, or postcode parameter in RSS feed"; } - + + # truncate the lat,lon for nicer urls + ( $lat, $lon ) = map { Utils::truncate_coordinate($_) } ( $lat, $lon ); + my $qs = "?lat=$lat;lon/=$lon"; if ($d) { |