File Coverage

blib/lib/Alien/Proj4.pm
Criterion Covered Total %
statement 52 61 85.2
branch 8 10 80.0
condition n/a
subroutine 6 11 54.5
pod 0 7 0.0
total 66 89 74.1


line stmt bran cond sub pod time code
1             package Alien::Proj4;
2              
3 4     4   445490 use strict;
  4         32  
  4         126  
4 4     4   21 use warnings;
  4         8  
  4         121  
5 4     4   870 use parent qw( Alien::Base );
  4         657  
  4         28  
6              
7             our $VERSION = '2.019113';
8              
9             # most of the following are for compat with PDLA Makefiles
10             # and should not be used by other code
11 0     0 0 0 sub installed {1}
12              
13             sub import {
14             # do nothing
15 4     4   3746 return;
16             }
17              
18             sub default_lib {
19 0     0 0 0 return;
20             }
21              
22             sub default_inc {
23 0     0 0 0 return;
24             }
25              
26             sub libflags {
27 0     0 0 0 my ($class) = @_;
28 0         0 my $flags = join ' ', $class->libs;
29 0         0 return $flags;
30             }
31              
32             sub incflags {
33 0     0 0 0 my ($class) = @_;
34 0         0 my $flags = $class->cflags;
35 0         0 return $flags;
36             }
37              
38             # dup of code currently in PDLA::GIS::Proj
39             sub load_projection_descriptions {
40 1     1 0 3 my ($class) = @_;
41 1         3 my $incflags = $class->cflags;
42 1         148 my $libflags = $class->libs;
43              
44 1         820 require Inline;
45 1 50       39561 Inline->bind(C => <<'EOF', inc => $incflags, libs => $libflags) unless defined &list_projections;
46             #include "projects.h"
47             HV *list_projections() {
48             struct PJ_LIST *lp;
49             SV* scalar_val;
50             HV *hv = newHV();
51             for (lp = pj_get_list_ref() ; lp->id ; ++lp) {
52             scalar_val = newSVpv( *lp->descr, 0 );
53             hv_store( hv, lp->id, strlen( lp->id ), scalar_val, 0 );
54             }
55             return hv;
56             }
57             EOF
58 1         1530284 list_projections();
59             }
60              
61             # dup of code currently in PDLA::GIS::Proj
62             sub load_projection_information {
63 1     1 0 41615 my ($class) = @_;
64 1         3 my $descriptions = $class->load_projection_descriptions();
65 1         36 my $info = {};
66 1         32 foreach my $projection ( keys %$descriptions ) {
67 143         274 my $description = $descriptions->{$projection};
68 143         329 my @lines = split( /\n/, $description );
69 143         227 chomp @lines;
70             # skip conversion entries if they appear
71 143 50       300 next if !defined $lines[1];
72              
73 143         211 my $hash = {};
74 143         284 $hash->{CODE} = $projection;
75             # Full name of this projection:
76 143         224 $hash->{NAME} = $lines[0];
77             # The second line is usually a list of projection types this one is:
78 143         198 my $temp = $lines[1];
79 143         277 $temp =~ s/no inv\.*,*//;
80 143         208 $temp =~ s/or//;
81 143         643 my @temp_types = split(/[,&\s]/, $temp );
82 143         555 my @types = grep( /.+/, @temp_types );
83 143         264 $hash->{CATEGORIES} = \@types;
84             # If there's more than 2 lines, then it usually is a listing of parameters:
85             # General parameters for all projections:
86             $hash->{PARAMS}->{GENERAL} =
87 143         567 [ qw( x_0 y_0 lon_0 units init no_defs geoc over ) ];
88             # Earth Figure Parameters:
89             $hash->{PARAMS}->{EARTH} =
90 143         593 [ qw( ellps b f rf e es R R_A R_V R_a R_g R_h R_lat_g ) ];
91             # Projection Specific Parameters:
92 143         270 my @proj_params = ();
93 143 100       285 if( $#lines >= 2 ) {
94 49         117 foreach my $i ( 2 .. $#lines ) {
95 54         92 my $text = $lines[$i];
96 54         239 my @temp2 = split( /\s+/, $text );
97 54         212 my @params = grep( /.+/, @temp2 );
98 54         97 foreach my $param (@params) {
99 138         281 $param =~ s/=//;
100 138         256 $param =~ s/[,\[\]]//sg;
101 138 100       417 next if $param =~ /^and|or|Special|for|Madagascar|fixed|Earth|For|CH1903$/;
102 118         275 push(@proj_params, $param);
103             }
104             }
105             }
106 143         253 $hash->{PARAMS}->{PROJ} = \@proj_params;
107             # Can this projection do inverse?
108 143 100       340 $hash->{INVERSE} = ( $description =~ /no inv/ ) ? 0 : 1;
109 143         462 $info->{$projection} = $hash;
110             }
111             # A couple of overrides:
112             $info->{ob_tran}->{PARAMS}->{PROJ} =
113 1         27 [ 'o_proj', 'o_lat_p', 'o_lon_p', 'o_alpha', 'o_lon_c',
114             'o_lat_c', 'o_lon_1', 'o_lat_1', 'o_lon_2', 'o_lat_2' ];
115 1         13 $info->{nzmg}->{CATEGORIES} = [ 'fixed Earth' ];
116 1         12 return $info;
117             }
118              
119              
120             1;
121              
122             __END__