Geo-Coordinates-ITM-0.02000755000765000120 011210046775 14250 5ustar00andyadmin000000000000Build.PL000444000765000120 74211210046775 15605 0ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02use strict; use warnings; use Module::Build; use lib 'inc'; use MyBuilder; my $builder = MyBuilder->new( module_name => 'Geo::Coordinates::ITM', license => 'perl', dist_author => 'Andy Armstrong ', dist_version_from => 'lib/Geo/Coordinates/ITM.pm', requires => { 'Test::More' => 0, 'Test::Number::Delta' => '1.03', }, add_to_cleanup => ['Geo-Coordinates-ITM-*'], ); $builder->create_build_script(); Changes000444000765000120 20711210046775 15600 0ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02Revision history for Geo-Coordinates-ITM 0.01 2009-05-17 - Initial release. 0.02 2009-05-29 - Move to GitHub. MANIFEST000444000765000120 22111210046775 15432 0ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02Build.PL Changes inc/MyBuilder.pm lib/Geo/Coordinates/ITM.pm MANIFEST MANIFEST.SKIP README t/00.load.t t/cvt.t t/pod-coverage.t t/pod.t META.yml MANIFEST.SKIP000444000765000120 101511210046775 16221 0ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02# Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \b_darcs\b \B\.git\b \B\.gitignore \B\.releaserc # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# #\.bak$ # Avoid Devel::Cover files. \bcover_db\b ^WWW-FogBugz- ^Session\.vim$ \.swp$ ^ref/ META.yml000444000765000120 120511210046775 15575 0ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02--- name: Geo-Coordinates-ITM version: 0.02 author: - 'Andy Armstrong ' abstract: Convert coordinates between lat/lon and Irish Transverse Mercator license: perl resources: bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Geo-Coordinates-ITM license: http://dev.perl.org/licenses/ repository: git://github.com/AndyA/Geo--Coordinates--ITM.git requires: Test::More: 0 Test::Number::Delta: 1.03 provides: Geo::Coordinates::ITM: file: lib/Geo/Coordinates/ITM.pm version: 0.02 generated_by: Module::Build version 0.33 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 README000444000765000120 53211210046775 15166 0ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02Geo-Coordinates-ITM version 0.02 INSTALLATION To install this module, run the following commands: perl Build.PL ./Build ./Build test ./Build install DEPENDENCIES None. COPYRIGHT AND LICENCE Copyright (C) 2009, Andy Armstrong This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. inc000755000765000120 011210046775 14742 5ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02MyBuilder.pm000444000765000120 353111210046775 17333 0ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02/incpackage MyBuilder; use base qw( Module::Build ); sub create_build_script { my ( $self, @args ) = @_; $self->_auto_mm; return $self->SUPER::create_build_script( @args ); } sub _auto_mm { my $self = shift; my $mm = $self->meta_merge; my @meta = qw( homepage bugtracker MailingList repository ); for my $meta ( @meta ) { next if exists $mm->{resources}{$meta}; my $auto = "_auto_$meta"; next unless $self->can( $auto ); my $av = $self->$auto(); $mm->{resources}{$meta} = $av if defined $av; } $self->meta_merge( $mm ); } sub _auto_repository { my $self = shift; if ( -d '.svn' ) { my $info = `svn info .`; return $1 if $info =~ /^URL:\s+(.+)$/m; } elsif ( -d '.git' ) { my $info = `git remote -v`; return unless $info =~ /^origin\s+(.+)$/m; my $url = $1; # Special case: patch up github URLs $url =~ s!^git\@github\.com:!git://github.com/!; return $url; } return; } sub _auto_bugtracker { 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=' . shift->dist_name; } sub ACTION_testauthor { my $self = shift; $self->test_files( 'xt/author' ); $self->ACTION_test; } sub ACTION_critic { exec qw( perlcritic -1 -q -profile perlcriticrc lib/ ), glob 't/*.t'; } sub ACTION_tags { exec( qw( ctags -f tags --recurse --totals --exclude=blib --exclude=.svn --exclude='*~' --languages=Perl t/ lib/ ) ); } sub ACTION_tidy { my $self = shift; my @extra = qw( Build.PL ); my %found_files = map { %$_ } $self->find_pm_files, $self->_find_file_by_type( 'pm', 't' ), $self->_find_file_by_type( 'pm', 'inc' ), $self->_find_file_by_type( 't', 't' ); my @files = ( keys %found_files, map { $self->localize_file_path( $_ ) } @extra ); for my $file ( @files ) { system 'perltidy', '-b', $file; unlink "$file.bak" if $? == 0; } } 1; lib000755000765000120 011210046775 14737 5ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02Geo000755000765000120 011210046775 15451 5ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02/libCoordinates000755000765000120 011210046775 17723 5ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02/lib/GeoITM.pm000444000765000120 1676611210046775 21107 0ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02/lib/Geo/Coordinatespackage Geo::Coordinates::ITM; use warnings; use strict; use base qw( Exporter ); our @EXPORT_OK = qw( ll_to_grid grid_to_ll ); use Carp; use Math::Trig; =head1 NAME Geo::Coordinates::ITM - Convert coordinates between lat/lon and Irish Transverse Mercator =head1 VERSION This document describes Geo::Coordinates::ITM version 0.02 =cut our $VERSION = '0.02'; =head1 SYNOPSIS use Geo::Coordinates::ITM qw( ll_to_grid grid_to_ll ); my ( $lat, $lon ) = grid_to_ll( $east, $north ); my ( $east, $north ) = ll_to_grid( $lat, $lon ); =head1 DESCRIPTION Convert back and forth between Irish Transverse Mercator grid and WGS84. The conversion code was stolen wholesale from L. http://svn.geograph.org.uk/svn/branches/british-isles/libs/geograph \ /conversionslatlong.class.php Nothing is exported by default. The exportable functions are C and C. =head1 INTERFACE =head2 C<< ll_to_grid >> Convert a latitude, longitude (WGS84) coordinate pair into an ITM easting and northing. my ( $east, $north ) = ll_to_grid( $lat, $lon ); =cut sub ll_to_grid { my ( $lat, $long ) = @_; return ( _ll2e( $lat, $long, 6378137, 6356752.314, 600000, 0.999820, 53.50000, -8.00000 ), _ll2n( $lat, $long, 6378137, 6356752.314, 600000, 750000, 0.999820, 53.50000, -8.00000 ) ); } =head2 C<< grid_to_ll >> Convert an ITM easting, northing pair to a WGS84 latitude, longitude. my ( $lat, $lon ) = grid_to_ll( $east, $north ); =cut sub grid_to_ll { my ( $e, $n ) = @_; return ( _en2lat( $e, $n, 6378137, 6356752.314, 600000, 750000, 0.999820, 53.50000, -8.00000 ), _en2lon( $e, $n, 6378137, 6356752.314, 600000, 750000, 0.999820, 53.50000, -8.00000 ) ); } sub _ll2e { my ( $PHI, $LAM, $a, $b, $e0, $f0, $PHI0, $LAM0 ) = @_; my $RadPHI = deg2rad( $PHI ); my $RadLAM = deg2rad( $LAM ); my $RadPHI0 = deg2rad( $PHI0 ); my $RadLAM0 = deg2rad( $LAM0 ); my $af0 = $a * $f0; my $bf0 = $b * $f0; my $e2 = ( $af0**2 - $bf0**2 ) / $af0**2; my $n = ( $af0 - $bf0 ) / ( $af0 + $bf0 ); my $nu = $af0 / ( sqrt( 1 - ( $e2 * sin( $RadPHI )**2 ) ) ); my $rho = ( $nu * ( 1 - $e2 ) ) / ( 1 - ( $e2 * sin( $RadPHI )**2 ) ); my $eta2 = ( $nu / $rho ) - 1; my $p = $RadLAM - $RadLAM0; my $IV = $nu * ( cos( $RadPHI ) ); my $V = ( $nu / 6 ) * ( cos( $RadPHI )**3 ) * ( ( $nu / $rho ) - ( tan( $RadPHI )**2 ) ); my $VI = ( $nu / 120 ) * ( cos( $RadPHI )**5 ) * ( 5 - ( 18 * ( tan( $RadPHI )**2 ) ) + ( tan( $RadPHI )**4 ) + ( 14 * $eta2 ) - ( 58 * ( tan( $RadPHI )**2 ) * $eta2 ) ); return $e0 + ( $p * $IV ) + ( $p**3 * $V ) + ( $p**5 * $VI ); } sub _ll2n { my ( $PHI, $LAM, $a, $b, $e0, $n0, $f0, $PHI0, $LAM0 ) = @_; my $RadPHI = deg2rad( $PHI ); my $RadLAM = deg2rad( $LAM ); my $RadPHI0 = deg2rad( $PHI0 ); my $RadLAM0 = deg2rad( $LAM0 ); my $af0 = $a * $f0; my $bf0 = $b * $f0; my $e2 = ( $af0**2 - $bf0**2 ) / $af0**2; my $n = ( $af0 - $bf0 ) / ( $af0 + $bf0 ); my $nu = $af0 / ( sqrt( 1 - ( $e2 * sin( $RadPHI )**2 ) ) ); my $rho = ( $nu * ( 1 - $e2 ) ) / ( 1 - ( $e2 * sin( $RadPHI )**2 ) ); my $eta2 = ( $nu / $rho ) - 1; my $p = $RadLAM - $RadLAM0; my $M = _marc( $bf0, $n, $RadPHI0, $RadPHI ); my $I = $M + $n0; my $II = ( $nu / 2 ) * ( sin( $RadPHI ) ) * ( cos( $RadPHI ) ); my $III = ( ( $nu / 24 ) * ( sin( $RadPHI ) ) * ( cos( $RadPHI )**3 ) ) * ( 5 - ( tan( $RadPHI )**2 ) + ( 9 * $eta2 ) ); my $IIIA = ( ( $nu / 720 ) * ( sin( $RadPHI ) ) * ( cos( $RadPHI )**5 ) ) * ( 61 - ( 58 * ( tan( $RadPHI )**2 ) ) + ( tan( $RadPHI )**4 ) ); return $I + ( $p**2 * $II ) + ( $p**4 * $III ) + ( $p**6 * $IIIA ); } sub _en2lat { my ( $East, $North, $a, $b, $e0, $n0, $f0, $PHI0, $LAM0 ) = @_; my $RadPHI0 = deg2rad( $PHI0 ); my $RadLAM0 = deg2rad( $LAM0 ); my $af0 = $a * $f0; my $bf0 = $b * $f0; my $e2 = ( $af0**2 - $bf0**2 ) / $af0**2; my $n = ( $af0 - $bf0 ) / ( $af0 + $bf0 ); my $Et = $East - $e0; my $PHId = _init_lat( $North, $n0, $af0, $RadPHI0, $n, $bf0 ); my $nu = $af0 / ( sqrt( 1 - ( $e2 * ( sin( $PHId )**2 ) ) ) ); my $rho = ( $nu * ( 1 - $e2 ) ) / ( 1 - ( $e2 * sin( $PHId )**2 ) ); my $eta2 = ( $nu / $rho ) - 1; my $VII = ( tan( $PHId ) ) / ( 2 * $rho * $nu ); my $VIII = ( ( tan( $PHId ) ) / ( 24 * $rho * $nu**3 ) ) * ( 5 + ( 3 * ( tan( $PHId )**2 ) ) + $eta2 - ( 9 * $eta2 * ( tan( $PHId )**2 ) ) ); my $IX = ( ( tan( $PHId ) ) / ( 720 * $rho * $nu**5 ) ) * ( 61 + ( 90 * ( ( tan( $PHId ) ) ^ 2 ) ) + ( 45 * ( tan( $PHId )**4 ) ) ); return ( 180 / pi ) * ( $PHId - ( $Et**2 * $VII ) + ( $Et**4 * $VIII ) - ( ( $Et**6 ) * $IX ) ); } sub _en2lon { my ( $East, $North, $a, $b, $e0, $n0, $f0, $PHI0, $LAM0 ) = @_; my $RadPHI0 = deg2rad( $PHI0 ); my $RadLAM0 = deg2rad( $LAM0 ); my $af0 = $a * $f0; my $bf0 = $b * $f0; my $e2 = ( $af0**2 - $bf0**2 ) / $af0**2; my $n = ( $af0 - $bf0 ) / ( $af0 + $bf0 ); my $Et = $East - $e0; my $PHId = _init_lat( $North, $n0, $af0, $RadPHI0, $n, $bf0 ); my $nu = $af0 / ( sqrt( 1 - ( $e2 * ( sin( $PHId )**2 ) ) ) ); my $rho = ( $nu * ( 1 - $e2 ) ) / ( 1 - ( $e2 * sin( $PHId )**2 ) ); my $eta2 = ( $nu / $rho ) - 1; my $X = ( cos( $PHId )**-1 ) / $nu; my $XI = ( ( cos( $PHId )**-1 ) / ( 6 * $nu**3 ) ) * ( ( $nu / $rho ) + ( 2 * ( tan( $PHId )**2 ) ) ); my $XII = ( ( cos( $PHId )**-1 ) / ( 120 * $nu**5 ) ) * ( 5 + ( 28 * ( tan( $PHId )**2 ) ) + ( 24 * ( tan( $PHId )**4 ) ) ); my $XIIA = ( ( cos( $PHId )**-1 ) / ( 5040 * $nu**7 ) ) * ( 61 + ( 662 * ( tan( $PHId )**2 ) ) + ( 1320 * ( tan( $PHId )**4 ) ) + ( 720 * ( tan( $PHId )**6 ) ) ); return ( 180 / pi ) * ( $RadLAM0 + ( $Et * $X ) - ( $Et**3 * $XI ) + ( $Et**5 * $XII ) - ( $Et**7 * $XIIA ) ); } sub _init_lat { my ( $North, $n0, $afo, $PHI0, $n, $bfo ) = @_; my $PHI1 = ( ( $North - $n0 ) / $afo ) + $PHI0; my $M = _marc( $bfo, $n, $PHI0, $PHI1 ); my $PHI2 = ( ( $North - $n0 - $M ) / $afo ) + $PHI1; while ( abs( $North - $n0 - $M ) > 0.00001 ) { $PHI2 = ( ( $North - $n0 - $M ) / $afo ) + $PHI1; $M = _marc( $bfo, $n, $PHI0, $PHI2 ); $PHI1 = $PHI2; } return $PHI2; } sub _marc { my ( $bf0, $n, $PHI0, $PHI ) = @_; return $bf0 * ( ( ( 1 + $n + ( ( 5 / 4 ) * $n**2 ) + ( ( 5 / 4 ) * $n**3 ) ) * ( $PHI - $PHI0 ) ) - ( ( ( 3 * $n ) + ( 3 * $n**2 ) + ( ( 21 / 8 ) * $n**3 ) ) * ( sin( $PHI - $PHI0 ) ) * ( cos( $PHI + $PHI0 ) ) ) + ( ( ( ( 15 / 8 ) * $n**2 ) + ( ( 15 / 8 ) * $n**3 ) ) * ( sin( 2 * ( $PHI - $PHI0 ) ) ) * ( cos( 2 * ( $PHI + $PHI0 ) ) ) ) - ( ( ( 35 / 24 ) * $n**3 ) * ( sin( 3 * ( $PHI - $PHI0 ) ) ) * ( cos( 3 * ( $PHI + $PHI0 ) ) ) ) ); } 1; __END__ =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. =head1 AUTHOR Andy Armstrong C<< >> Code gratefully stolen from L http://svn.geograph.org.uk/svn/branches/british-isles/libs/geograph \ /conversionslatlong.class.php =head1 LICENCE AND COPYRIGHT Copyright (c) 2009, Andy Armstrong C<< >>. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. t000755000765000120 011210046775 14434 5ustar00andyadmin000000000000Geo-Coordinates-ITM-0.0200.load.t000444000765000120 22511210046775 16072 0ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02/tuse Test::More tests => 1; BEGIN { use_ok( 'Geo::Coordinates::ITM' ); } diag( "Testing Geo::Coordinates::ITM $Geo::Coordinates::ITM::VERSION" ); cvt.t000444000765000120 132611210046775 15554 0ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02/t#!perl use strict; use warnings; use Test::More; use Test::Number::Delta within => 0.001; use Geo::Coordinates::ITM qw( ll_to_grid grid_to_ll ); my @case = ( { name => 'Spire of Dublin', itm => [ 715830, 734697 ], ll => [ 53.3497939132163, -6.26024777285805 ] }, { name => 'GPS station', itm => [ 709885.081, 736167.699 ], ll => [ 53.3642734370663, -6.34898734665306 ] }, ); plan tests => @case * 2; for my $case ( @case ) { my $name = $case->{name}; my @ll = grid_to_ll( @{ $case->{itm} } ); delta_ok [@ll], $case->{ll}, "$name: grid_to_ll"; my @grid = ll_to_grid( @{ $case->{ll} } ); delta_ok [@grid], $case->{itm}, "$name: ll_to_grid"; } # vim:ts=2:sw=2:et:ft=perl pod-coverage.t000444000765000120 36211210046775 17312 0ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02/t#!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok( { private => [ qr{^BUILD|DEMOLISH|AUTOMETHOD|START$}, qr{^_} ] } ); pod.t000444000765000120 21411210046775 15515 0ustar00andyadmin000000000000Geo-Coordinates-ITM-0.02/t#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok();