File Coverage

blib/lib/PDLA/GIS/Proj.pm
Criterion Covered Total %
statement 75 75 100.0
branch 20 22 90.9
condition 4 4 100.0
subroutine 9 9 100.0
pod 3 6 50.0
total 111 116 95.6


line stmt bran cond sub pod time code
1              
2             #
3             # GENERATED WITH PDLA::PP! Don't modify!
4             #
5             package PDLA::GIS::Proj;
6              
7             @EXPORT_OK = qw( fwd_transform inv_transform get_proj_info PDLA::PP _fwd_trans fwd_trans_inplace PDLA::PP _fwd_trans_inplace PDLA::PP _inv_trans inv_trans_inplace PDLA::PP _inv_trans_inplace load_projection_descriptions load_projection_information );
8             %EXPORT_TAGS = (Func=>[@EXPORT_OK]);
9              
10 3     3   782 use PDLA::Core;
  3         7  
  3         24  
11 3     3   868 use PDLA::Exporter;
  3         6  
  3         21  
12 3     3   120 use DynaLoader;
  3         15  
  3         3092  
13              
14              
15              
16            
17             @ISA = ( 'PDLA::Exporter','DynaLoader' );
18             push @PDLA::Core::PP, __PACKAGE__;
19             bootstrap PDLA::GIS::Proj ;
20              
21              
22              
23              
24              
25              
26              
27              
28             =head1 NAME
29              
30             PDLA::GIS::Proj - PDLA interface to the Proj4 projection library.
31              
32             =head1 DESCRIPTION
33              
34             PDLA interface to the Proj4 projection library.
35              
36             For more information on the proj library, see: http://www.remotesensing.org/proj/
37              
38             =head1 AUTHOR
39              
40             Judd Taylor, Orbital Systems, Ltd.
41             judd dot t at orbitalsystems dot com
42              
43             =head1 DATE
44              
45             18 March 2003
46              
47             =head1 CHANGES
48              
49             =head2 1.32 (29 March 2006) Judd Taylor
50              
51             - Getting ready to merge this into the PDLA CVS.
52            
53             =head2 1.31 (???) Judd Taylor
54              
55             - Can't remember what was in that version
56              
57             =head2 1.30 (16 September 2003) Judd Taylor
58              
59             - The get_proj_info() function actually works now.
60              
61             =head2 1.20 (24 April 2003) Judd Taylor
62              
63             - Added get_proj_info().
64              
65             =head2 1.10 (23 April 2003) Judd Taylor
66              
67             - Changed from using the proj_init() type API in projects.h to the
68             - proj_init_plus() API in proj_api.h. The old one was not that stable...
69              
70             =head2 1.00 (18 March 2003) Judd Taylor
71              
72             - Initial version
73              
74             =head1 COPYRIGHT NOTICE
75              
76             Copyright 2003 Judd Taylor, USF Institute for Marine Remote Sensing (judd@marine.usf.edu).
77              
78             GPL Now!
79              
80             This program is distributed in the hope that it will be useful,
81             but WITHOUT ANY WARRANTY; without even the implied warranty of
82             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
83              
84             =head1 SUBROUTINES
85              
86             =cut
87              
88              
89              
90              
91              
92             =head2 fwd_transform($lon(pdl), $lat(pdl), $params)
93              
94             Proj4 forward transformation $params is a string of the projection transformation
95             parameters.
96              
97             Returns two pdls for x and y values respectively. The units are dependent on Proj4
98             behavior. They will be PDLA->null if an error has occurred.
99              
100             BadDoc: Ignores bad elements of $lat and $lon, and sets the corresponding elements
101             of $x and $y to BAD
102              
103             =cut
104              
105              
106             sub fwd_transform
107             {
108 2     2 1 3084 my ($lon, $lat, $params) = @_;
109 2         7 my $x = null;
110 2         26 my $y = null;
111              
112             #print "Projection transformation parameters: \'$params\'\n";
113              
114 2         335 _fwd_trans( $lon, $lat, $x, $y, $params );
115              
116 2         14 return ($x, $y);
117             } # End of fwd_transform()...
118              
119             =head2 inv_transform($x(pdl), $y(pdl), $params)
120              
121             Proj4 inverse transformation $params is a string of the projection transformation
122             parameters.
123              
124             Returns two pdls for lat and lon values respectively. The units are dependent on Proj4
125             behavior. They will be PDLA->null if an error has occurred.
126              
127             BadDoc: Ignores bad elements of $lat and $lon, and sets the corresponding elements
128             of $x and $y to BAD
129              
130             =cut
131              
132              
133             sub inv_transform
134             {
135 1     1 1 1109 my ($x, $y, $params) = @_;
136 1         6 my $lon = null;
137 1         15 my $lat = null;
138              
139             #print "Projection transformation parameters: \'$params\'\n";
140              
141 1         108 _inv_trans( $x, $y, $lon, $lat, $params );
142 1         7 return ($lon, $lat);
143             } # End of fwd_transform()...
144              
145             =head2 get_proj_info($params_string)
146              
147             Returns a string with information about what parameters proj will
148             actually use, this includes defaults, and +init=file stuff. It's
149             the same as running 'proj -v'. It uses the proj command line, so
150             it might not work with all shells. I've tested it with bash.
151              
152             =cut
153              
154              
155             sub get_proj_info
156             {
157 1     1 1 790 my $params = shift;
158 1         4897 my @a = split(/\n/, `echo | proj -v $params`);
159 1         25 pop(@a);
160 1         81 return join("\n", @a);
161             } # End of get_proj_info()...
162              
163              
164              
165              
166              
167             *_fwd_trans = \&PDLA::_fwd_trans;
168              
169              
170              
171             #
172             # Wrapper sub for _fwd_trans_inplace that sets a default for the quiet variable.
173             #
174             sub fwd_trans_inplace
175             {
176 6     6 0 18633 my $lon = shift;
177 6         21 my $lat = shift;
178 6         16 my $params = shift;
179 6   100     43 my $quiet = shift || 0;
180            
181 6         37353 _fwd_trans_inplace( $lon, $lat, $params, $quiet );
182             } # End of fwd_trans_inplace()...
183              
184              
185              
186              
187              
188             *_fwd_trans_inplace = \&PDLA::_fwd_trans_inplace;
189              
190              
191              
192              
193              
194             *_inv_trans = \&PDLA::_inv_trans;
195              
196              
197              
198             #
199             # Wrapper sub for _fwd_trans_inplace that sets a default for the quiet variable.
200             #
201             sub inv_trans_inplace
202             {
203 5     5 0 1298 my $lon = shift;
204 5         22 my $lat = shift;
205 5         15 my $params = shift;
206 5   100     33 my $quiet = shift || 0;
207            
208 5         115553 _inv_trans_inplace( $lon, $lat, $params, $quiet );
209             } # End of fwd_trans_inplace()...
210              
211              
212              
213              
214              
215             *_inv_trans_inplace = \&PDLA::_inv_trans_inplace;
216              
217              
218              
219              
220             sub load_projection_information
221             {
222 1     1 0 23443 my $descriptions = PDLA::GIS::Proj::load_projection_descriptions();
223            
224 1         11 my $info = {};
225            
226 1         27 foreach my $projection ( keys %$descriptions )
227             {
228 143         223 my $description = $descriptions->{$projection};
229            
230 143         192 my $hash = {};
231 143         276 $hash->{CODE} = $projection;
232            
233            
234            
235 143         342 my @lines = split( /\n/, $description );
236 143         213 chomp @lines;
237            
238             # Full name of this projection:
239 143         230 $hash->{NAME} = $lines[0];
240            
241             # The second line is usually a list of projection types this one is:
242 143         202 my $temp = $lines[1];
243 143         266 $temp =~ s/no inv\.*,*//;
244 143         202 $temp =~ s/or//;
245 143         526 my @temp_types = split(/[,&\s]/, $temp );
246 143         584 my @types = grep( /.+/, @temp_types );
247 143         266 $hash->{CATEGORIES} = \@types;
248            
249             # If there's more than 2 lines, then it usually is a listing of parameters:
250            
251             # General parameters for all projections:
252             $hash->{PARAMS}->{GENERAL} =
253 143         570 [ qw( x_0 y_0 lon_0 units init no_defs geoc over ) ];
254            
255             # Earth Figure Parameters:
256             $hash->{PARAMS}->{EARTH} =
257 143         598 [ qw( ellps b f rf e es R R_A R_V R_a R_g R_h R_lat_g ) ];
258            
259             # Projection Specific Parameters:
260 143         209 my @proj_params = ();
261 143 100       258 if( $#lines >= 2 )
262             {
263 49         103 foreach my $i ( 2 .. $#lines )
264             {
265 54         87 my $text = $lines[$i];
266 54         231 my @temp2 = split( /\s+/, $text );
267 54         200 my @params = grep( /.+/, @temp2 );
268 54         100 foreach my $param (@params)
269             {
270 138         285 $param =~ s/=//;
271 138         238 $param =~ s/[,\[\]]//sg;
272 138 100       253 next if $param =~ /^and$/;
273 129 100       217 next if $param =~ /^or$/;
274 125 100       198 next if $param =~ /^Special$/;
275 124 100       241 next if $param =~ /^for$/;
276 122 100       182 next if $param =~ /^Madagascar$/;
277 121 50       205 next if $param =~ /^fixed$/;
278 121 50       187 next if $param =~ /^Earth$/;
279 121 100       203 next if $param =~ /^For$/;
280 120 100       192 next if $param =~ /^CH1903$/;
281 119         263 push(@proj_params, $param);
282             }
283             }
284             }
285 143         239 $hash->{PARAMS}->{PROJ} = \@proj_params;
286            
287             # Can this projection do inverse?
288 143 100       331 $hash->{INVERSE} = ( $description =~ /no inv/ ) ? 0 : 1;
289            
290 143         417 $info->{$projection} = $hash;
291             }
292            
293             # A couple of overrides:
294             #
295             $info->{ob_tran}->{PARAMS}->{PROJ} =
296 1         16 [ 'o_proj', 'o_lat_p', 'o_lon_p', 'o_alpha', 'o_lon_c',
297             'o_lat_c', 'o_lon_1', 'o_lat_1', 'o_lon_2', 'o_lat_2' ];
298            
299 1         7 $info->{nzmg}->{CATEGORIES} = [ 'fixed Earth' ];
300              
301 1         6 return $info;
302             } # End of load_projection_information()...
303              
304              
305              
306              
307             ;
308              
309              
310              
311             # Exit with OK status
312              
313             1;
314              
315