Changeset 870
- Timestamp:
- 09/17/06 17:26:28 (2 years ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
lib/OpenGuides/Utils.pm (modified) (2 diffs)
-
t/28_wgs84_coords.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/OpenGuides/Utils.pm
r867 r870 236 236 or croak "No longitude supplied to get_wgs84_coords"; 237 237 croak "geo_handler not defined!" unless $config->geo_handler; 238 238 239 if ($config->force_wgs84) { 239 240 # Only as a rough approximation, good enough for large scale guides 240 241 return ($longitude, $latitude); 241 } elsif ($config->geo_handler == 1) { 242 } 243 244 # If we don't have a lat and long, return undef right away 245 unless($args{longitude} || $args{latitude}) { 246 return undef; 247 } 248 249 # Try to load a provider of Helmert Transforms 250 my $helmert; 251 # First up, try the MySociety Geo::HelmertTransform 252 unless($helmert) { 253 eval { 254 require Geo::HelmertTransform; 255 $helmert = sub($$$) { 256 my ($datum,$oldlat,$oldlong) = @_; 257 my $datum_helper = Geo::HelmertTransform::datum($datum); 258 my $wgs84_helper = Geo::HelmertTransform::datum('WGS84'); 259 unless($datum_helper) { 260 croak("No convertion helper for datum '$datum'"); 261 return undef; 262 } 263 264 my ($lat,$long,$h) = 265 Geo::HelmertTransform::convert_datum($datum_helper,$wgs84_helper,$oldlat,$oldlong,0); 266 return ($long,$lat); 267 }; 268 }; 269 } 270 # Next, try ..... 271 unless($helmert) { 272 eval { 273 }; 274 } 275 # Give up, return undef 276 unless($helmert) { 277 return undef; 278 } 279 280 281 if ($config->geo_handler == 1) { 242 282 # Do conversion here 243 return undef;283 return &$helmert('Airy1830',$latitude,$longitude); 244 284 } elsif ($config->geo_handler == 2) { 245 285 # Do conversion here 246 return undef;286 return &$helmert('Airy1830Modified',$latitude,$longitude); 247 287 } elsif ($config->geo_handler == 3) { 248 288 if ($config->ellipsoid eq "WGS-84") { … … 250 290 } else { 251 291 # Do conversion here 252 return undef;292 return &$helmert($config->ellipsoid,$latitude,$longitude); 253 293 } 254 294 } else { -
trunk/t/28_wgs84_coords.t
r792 r870 5 5 use Test::More; 6 6 7 plan tests => 2;7 plan tests => 4; 8 8 9 9 # Clear out the database from any previous runs. … … 18 18 my $guide = OpenGuides->new( config => $config ); 19 19 20 my ($longitude, $latitude) = ( 0, 0);20 my ($longitude, $latitude) = (10, 12); 21 21 22 22 my ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords( … … 29 29 is( $wgs_lat, $latitude, 30 30 "get_wgs84_coords returns the original latitude when force_wgs84 is on"); 31 32 33 # Now claim to be in the UK 34 eval{ require Geo::HelmertTransform; }; 35 my $have_helmert = $@ ? 0 : 1; 36 SKIP : { 37 skip "Geo::HelmertTransform not installed - can't do transforms", 2 38 unless $have_helmert; 39 40 $config->force_wgs84(0); 41 $config->geo_handler(1); 42 43 # Set our location to be somewhere known 44 ($longitude,$latitude) = (-1.258200,51.754349); 45 my ($wgs84_lon,$wgs84_lat) = (-1.259687,51.754813); 46 47 ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords( 48 longitude => $longitude, 49 latitude => $latitude, 50 config => $config); 51 52 # Round to 5 dp 53 my $fivedp = 1 * 1000 * 100; 54 $wgs_long = int($wgs_long * $fivedp)/$fivedp; 55 $wgs_lat = int($wgs_lat * $fivedp)/$fivedp; 56 $wgs84_lon = int($wgs84_lon * $fivedp)/$fivedp; 57 $wgs84_lat = int($wgs84_lat * $fivedp)/$fivedp; 58 59 is( $wgs_long, $wgs84_lon, 60 "get_wgs84_coords does Airy1830 -> WGS84 convertion properly"); 61 is( $wgs_lat, $wgs84_lat, 62 "get_wgs84_coords does Airy1830 -> WGS84 convertion properly"); 63 }
