Author: kake Date: 2012-03-02 21:06:35 +0000 (Fri, 02 Mar 2012) New Revision: 1306
Modified: trunk/Build.PL trunk/INSTALL trunk/lib/OpenGuides/Search.pm trunk/lib/OpenGuides/Template.pm trunk/t/25_write_geo_data.t trunk/t/26_geo_data_search_form.t trunk/t/27_geo_data_edit_form.t trunk/t/33_search_advanced_search.t trunk/t/34_search_paging.t trunk/t/35_search_two_searches.t trunk/t/38_search_params.t trunk/t/39_search_form.t trunk/t/62_bug_trailing_whitespace.t trunk/wiki.cgi Log: Switched from Geography::NationalGrid (which no longer exists on CPAN) to Geo::Coordinates::OSGB/ITM
Modified: trunk/Build.PL =================================================================== --- trunk/Build.PL 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/Build.PL 2012-03-02 21:06:35 UTC (rev 1306) @@ -298,7 +298,6 @@ 'File::Spec::Functions' => 0, 'File::Temp' => 0, 'Geo::Coordinates::UTM' => 0, - 'Geography::NationalGrid' => 0, 'HTML::Entities' => 0, 'LWP::Simple' => 0, 'MIME::Lite' => 0,
Modified: trunk/INSTALL =================================================================== --- trunk/INSTALL 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/INSTALL 2012-03-02 21:06:35 UTC (rev 1306) @@ -331,8 +331,8 @@ will be able to choose between entering location data as lat/long or as grid co-ordinates.
-You must have Geography::NationalGrid::GB installed to use the British -National Grid, Geography::NationalGrid::IE to use the Irish National +You must have Geo::Coordinates::OSGB installed to use the British +National Grid, Geo::Coordinates::ITM to use the Irish National Grid, and Geo::Coordinates::UTM to use a UTM ellipsoid.
If you want to use a UTM ellipsoid, WGS-84 is the best choice, as it
Modified: trunk/lib/OpenGuides/Search.pm =================================================================== --- trunk/lib/OpenGuides/Search.pm 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/lib/OpenGuides/Search.pm 2012-03-02 21:06:35 UTC (rev 1306) @@ -706,21 +706,17 @@ && defined $vars{latlong_dist} ) { # All handlers can do lat/long, but they all do it differently. if ( $self->config->geo_handler eq 1 ) { - require Geography::NationalGrid::GB; - my $point = Geography::NationalGrid::GB->new( - Latitude => $vars{latitude}, - Longitude => $vars{longitude}, - ); - $self->{x} = $point->easting; - $self->{y} = $point->northing; + require Geo::Coordinates::OSGB; + my ( $x, $y ) = Geo::Coordinates::OSGB::ll_to_grid( + $vars{latitude}, $vars{longitude} ); + $self->{x} = sprintf( "%d", $x ); + $self->{y} = sprintf( "%d", $y ); } elsif ( $self->config->geo_handler eq 2 ) { - require Geography::NationalGrid::IE; - my $point = Geography::NationalGrid::IE->new( - Latitude => $vars{latitude}, - Longitude => $vars{longitude}, - ); - $self->{x} = $point->easting; - $self->{y} = $point->northing; + require Geo::Coordinates::ITM; + my ( $x, $y ) = Geo::Coordinates::ITM::ll_to_grid( + $vars{latitude}, $vars{longitude} ); + $self->{x} = sprintf( "%d", $x ); + $self->{y} = sprintf( "%d", $y ); } elsif ( $self->config->geo_handler eq 3 ) { require Geo::Coordinates::UTM; my ($zone, $x, $y) = Geo::Coordinates::UTM::latlon_to_utm(
Modified: trunk/lib/OpenGuides/Template.pm =================================================================== --- trunk/lib/OpenGuides/Template.pm 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/lib/OpenGuides/Template.pm 2012-03-02 21:06:35 UTC (rev 1306) @@ -6,8 +6,6 @@
use Carp qw( croak ); use CGI; # want to get rid of this and put the burden on the templates -use Geography::NationalGrid; -use Geography::NationalGrid::GB; use OpenGuides; # for $VERSION for template variable use OpenGuides::CGI; use Template; @@ -448,7 +446,8 @@
my $geo_handler = $config->geo_handler; if ( $geo_handler == 1 ) { - require Geography::NationalGrid::GB; + require Geo::Coordinates::OSGB; + my $os_x = $q->param("os_x"); my $os_y = $q->param("os_y"); my $lat = $q->param("latitude"); @@ -462,15 +461,15 @@
# If we were sent x and y, work out lat/long; and vice versa. if ( defined $os_x && length $os_x && defined $os_y && length $os_y ) { - my $point = Geography::NationalGrid::GB->new( Easting =>$os_x, - Northing=>$os_y); - $lat = sprintf("%.6f", $point->latitude); - $long = sprintf("%.6f", $point->longitude); + ( $lat, $long ) = Geo::Coordinates::OSGB::grid_to_ll( + $os_x, $os_y ); + $lat = sprintf( "%.6f", $lat ); + $long = sprintf( "%.6f", $long ); } elsif ( defined $lat && length $lat && defined $long && length $long ) { - my $point = Geography::NationalGrid::GB->new(Latitude => $lat, - Longitude => $long); - $os_x = $point->easting; - $os_y = $point->northing; + ( $os_x, $os_y ) = Geo::Coordinates::OSGB::ll_to_grid( + $lat, $long ); + $os_x = sprintf( "%d", $os_x ); + $os_y = sprintf( "%d", $os_y ); }
if ( defined $os_x && length $os_x && defined $os_y && length $os_y ) { @@ -495,7 +494,8 @@ ); } } elsif ( $geo_handler == 2 ) { - require Geography::NationalGrid::IE; + require Geo::Coordinates::ITM; + my $osie_x = $q->param("osie_x"); my $osie_y = $q->param("osie_y"); my $lat = $q->param("latitude"); @@ -507,15 +507,15 @@
# If we were sent x and y, work out lat/long; and vice versa. if ( defined $osie_x && length $osie_x && defined $osie_y && length $osie_y ) { - my $point = Geography::NationalGrid::IE->new(Easting=>$osie_x, - Northing=>$osie_y); - $lat = sprintf("%.6f", $point->latitude); - $long = sprintf("%.6f", $point->longitude); + ( $lat, $long ) = Geo::Coordinates::ITM::grid_to_ll( + $osie_x, $osie_y ); + $lat = sprintf( "%.6f", $lat ); + $long = sprintf( "%.6f", $long ); } elsif ( defined $lat && length $lat && defined $long && length $long ) { - my $point = Geography::NationalGrid::GB->new(Latitude => $lat, - Longitude => $long); - $osie_x = $point->easting; - $osie_y = $point->northing; + ( $osie_x, $osie_y ) = Geo::Coordinates::ITM::ll_to_grid( + $lat, $long ); + $osie_x = sprintf( "%d", $osie_x ); + $osie_y = sprintf( "%d", $osie_y ); } if ( defined $osie_x && length $osie_x && defined $osie_y && length $osie_y ) { %vars = ( @@ -582,13 +582,38 @@ foreach my $var ( qw( latitude longitude ) ) { next unless defined $vars{$var} && length $vars{$var}; $vars{$var."_unmunged"} = $vars{$var}; - $vars{$var} = Geography::NationalGrid->deg2string($vars{$var}); + $vars{$var} = _deg2string($vars{$var}); } }
return %vars; }
+# Slightly modified from the no-longer-available Geography::NationalGrid +# module, which was written by P Kent and distributed under the Artistic +# Licence. +sub _deg2string { + my $degrees = shift; + + # make positive + my $isneg = 0; + if ($degrees < 0) { + $isneg = 1; + $degrees = abs( $degrees ); + } elsif ($degrees == 0) { + return '0d 0m 0s'; + } + + my $d = int( $degrees ); + $degrees -= $d; + $degrees *= 60; + my $m = int( $degrees ); + $degrees -= $m; + my $s = $degrees * 60; + + return sprintf("%s%dd %um %.2fs", ($isneg?'-':''), $d, $m, $s); +} + =back
=head1 AUTHOR
Modified: trunk/t/25_write_geo_data.t =================================================================== --- trunk/t/25_write_geo_data.t 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/t/25_write_geo_data.t 2012-03-02 21:06:35 UTC (rev 1306) @@ -18,13 +18,18 @@
# Strictly speaking we don't need to skip _all_ tests if we don't have # the modules below. Revisit this when not in a hurry. -# We only actually need the former for the National Grid tests and the +# We only actually need the former two for the National Grid tests and the # latter for the UTM tests. -eval { require Geography::NationalGrid; }; +eval { require Geo::Coordinates::OSGB; }; if ( $@ ) { - plan skip_all => "Geography::NationalGrid not installed"; + plan skip_all => "Geo::Coordinates::OSGB not installed"; }
+eval { require Geo::Coordinates::ITM; }; +if ( $@ ) { + plan skip_all => "Geo::Coordinates::ITM not installed"; +} + eval { require Geo::Coordinates::UTM; }; if ( $@ ) { plan skip_all => "Geo::Coordinates::UTM not installed";
Modified: trunk/t/26_geo_data_search_form.t =================================================================== --- trunk/t/26_geo_data_search_form.t 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/t/26_geo_data_search_form.t 2012-03-02 21:06:35 UTC (rev 1306) @@ -22,13 +22,18 @@
# Strictly speaking we don't need to skip _all_ tests if we don't have # the modules below. Revisit this when not in a hurry. -# We only actually need the former for the National Grid tests and the +# We only actually need the former two for the National Grid tests and the # latter for the UTM tests. -eval { require Geography::NationalGrid; }; +eval { require Geo::Coordinates::OSGB; }; if ( $@ ) { - plan skip_all => "Geography::NationalGrid not installed"; + plan skip_all => "Geo::Coordinates::OSGB not installed"; }
+eval { require Geo::Coordinates::ITM; }; +if ( $@ ) { + plan skip_all => "Geo::Coordinates::ITM not installed"; +} + eval { require Geo::Coordinates::UTM; }; if ( $@ ) { plan skip_all => "Geo::Coordinates::UTM not installed";
Modified: trunk/t/27_geo_data_edit_form.t =================================================================== --- trunk/t/27_geo_data_edit_form.t 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/t/27_geo_data_edit_form.t 2012-03-02 21:06:35 UTC (rev 1306) @@ -22,13 +22,18 @@
# Strictly speaking we don't need to skip _all_ tests if we don't have # the modules below. Revisit this when not in a hurry. -# We only actually need the former for the National Grid tests and the +# We only actually need the former two for the National Grid tests and the # latter for the UTM tests. -eval { require Geography::NationalGrid; }; +eval { require Geo::Coordinates::OSGB; }; if ( $@ ) { - plan skip_all => "Geography::NationalGrid not installed"; + plan skip_all => "Geo::Coordinates::OSGB not installed"; }
+eval { require Geo::Coordinates::ITM; }; +if ( $@ ) { + plan skip_all => "Geo::Coordinates::ITM not installed"; +} + eval { require Geo::Coordinates::UTM; }; if ( $@ ) { plan skip_all => "Geo::Coordinates::UTM not installed";
Modified: trunk/t/33_search_advanced_search.t =================================================================== --- trunk/t/33_search_advanced_search.t 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/t/33_search_advanced_search.t 2012-03-02 21:06:35 UTC (rev 1306) @@ -17,9 +17,9 @@ plan skip_all => "Plucene not installed"; }
-eval { require Geography::NationalGrid::GB; }; +eval { require Geo::Coordinates::OSGB; }; if ( $@ ) { - plan skip_all => "Geography::NationalGrid::GB not installed"; + plan skip_all => "Geo::Coordinates::OSGB not installed"; }
plan tests => 8;
Modified: trunk/t/34_search_paging.t =================================================================== --- trunk/t/34_search_paging.t 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/t/34_search_paging.t 2012-03-02 21:06:35 UTC (rev 1306) @@ -28,9 +28,9 @@ my $guide = OpenGuides->new( config => $config );
# Test with OS co-ords. -eval { require Geography::NationalGrid::GB; }; +eval { require Geo::Coordinates::OSGB; }; SKIP: { - skip "Geography::NationalGrid::GB not installed", 3 if $@; + skip "Geo::Coordinates::OSGB not installed", 3 if $@; $config->geo_handler( 1 );
foreach my $i ( 1 .. 50 ) { @@ -67,9 +67,9 @@ }
# Test with OSIE co-ords. -eval { require Geography::NationalGrid::IE; }; +eval { require Geo::Coordinates::ITM; }; SKIP: { - skip "Geography::NationalGrid::IE not installed", 3 if $@; + skip "Geo::Coordinates::ITM not installed", 3 if $@;
# We must create a new search object after changing the geo_handler # in order to force it to create a fresh locator.
Modified: trunk/t/35_search_two_searches.t =================================================================== --- trunk/t/35_search_two_searches.t 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/t/35_search_two_searches.t 2012-03-02 21:06:35 UTC (rev 1306) @@ -18,13 +18,18 @@
# Strictly speaking we don't need to skip _all_ tests if we don't have # the modules below. Revisit this when not in a hurry. -# We only actually need the former for the National Grid tests and the +# We only actually need the former two for the National Grid tests and the # latter for the UTM tests. -eval { require Geography::NationalGrid; }; +eval { require Geo::Coordinates::OSGB; }; if ( $@ ) { - plan skip_all => "Geography::NationalGrid not installed"; + plan skip_all => "Geo::Coordinates::OSGB not installed"; }
+eval { require Geo::Coordinates::ITM; }; +if ( $@ ) { + plan skip_all => "Geo::Coordinates::ITM not installed"; +} + eval { require Geo::Coordinates::UTM; }; if ( $@ ) { plan skip_all => "Geo::Coordinates::UTM not installed";
Modified: trunk/t/38_search_params.t =================================================================== --- trunk/t/38_search_params.t 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/t/38_search_params.t 2012-03-02 21:06:35 UTC (rev 1306) @@ -19,12 +19,18 @@
# Strictly speaking we don't need to skip _all_ tests if we don't have # the modules below. Revisit this when not in a hurry. -# We only actually need them for the tests where lat/long are converted. -eval { require Geography::NationalGrid; }; +# We only actually need the former two for the National Grid tests and the +# latter for the UTM tests. +eval { require Geo::Coordinates::OSGB; }; if ( $@ ) { - plan skip_all => "Geography::NationalGrid not installed"; + plan skip_all => "Geo::Coordinates::OSGB not installed"; }
+eval { require Geo::Coordinates::ITM; }; +if ( $@ ) { + plan skip_all => "Geo::Coordinates::ITM not installed"; +} + eval { require Geo::Coordinates::UTM; }; if ( $@ ) { plan skip_all => "Geo::Coordinates::UTM not installed";
Modified: trunk/t/39_search_form.t =================================================================== --- trunk/t/39_search_form.t 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/t/39_search_form.t 2012-03-02 21:06:35 UTC (rev 1306) @@ -22,13 +22,18 @@
# Strictly speaking we don't need to skip _all_ tests if we don't have # the modules below. Revisit this when not in a hurry. -# We only actually need the former for the National Grid tests and the +# We only actually need the former two for the National Grid tests and the # latter for the UTM tests. -eval { require Geography::NationalGrid; }; +eval { require Geo::Coordinates::OSGB; }; if ( $@ ) { - plan skip_all => "Geography::NationalGrid not installed"; + plan skip_all => "Geo::Coordinates::OSGB not installed"; }
+eval { require Geo::Coordinates::ITM; }; +if ( $@ ) { + plan skip_all => "Geo::Coordinates::ITM not installed"; +} + eval { require Geo::Coordinates::UTM; }; if ( $@ ) { plan skip_all => "Geo::Coordinates::UTM not installed";
Modified: trunk/t/62_bug_trailing_whitespace.t =================================================================== --- trunk/t/62_bug_trailing_whitespace.t 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/t/62_bug_trailing_whitespace.t 2012-03-02 21:06:35 UTC (rev 1306) @@ -22,8 +22,8 @@ my $guide = OpenGuides->new( config => $config );
SKIP: { - eval { require Geography::NationalGrid::GB; }; - skip "Geography::NationalGrid::GB not installed", 2 if $@; + eval { require Geo::Coordinates::OSGB; }; + skip "Geo::Coordinates::OSGB not installed", 2 if $@;
my $q = CGI->new( "" ); $q->param( -name => "os_x", -value => " 123456 " ); @@ -43,8 +43,8 @@ }
SKIP: { - eval { require Geography::NationalGrid::IE; }; - skip "Geography::NationalGrid::IE not installed", 2 if $@; + eval { require Geo::Coordinates::ITM; }; + skip "Geo::Coordinates::ITM not installed", 2 if $@;
$config->geo_handler( 2 ); my $q = CGI->new( "" );
Modified: trunk/wiki.cgi =================================================================== --- trunk/wiki.cgi 2012-03-01 22:18:12 UTC (rev 1305) +++ trunk/wiki.cgi 2012-03-02 21:06:35 UTC (rev 1306) @@ -10,8 +10,6 @@ use CGI qw/:standard/; use CGI::Carp qw(croak); use Wiki::Toolkit; -use Geography::NationalGrid; -use Geography::NationalGrid::GB; use OpenGuides; use OpenGuides::CGI; use OpenGuides::Config;
openguides-commits@lists.openguides.org