lib/Geo/LibProj/FFI.pm

filter: Statementstmt 75.0% 6 / 8 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 81.8% 9 / 11 CC 1 SCAR 0.9
CC
1
Cov
75%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 12 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 # ABSTRACT: Foreign function interface to PROJ coordinate transformation software
5 package Geo::LibProj::FFI 1.01;
6  
7  
8 0 ▶use Alien::proj 1.07;
Subroutine BEGIN: called CC=1 SCAR=2.6
9 use FFI::Platypus 1.50;
10 use FFI::C 0.08;
11 use Convert::Binary::C 0.04;
12  
13 use Exporter::Easy (TAGS => [
14 context => [qw(
15 proj_context_create
16 proj_context_destroy
17 proj_context_use_proj4_init_rules
18 )],
19 setup => [qw(
20 proj_create
21 proj_create_argv
22 proj_create_crs_to_crs
23 proj_create_crs_to_crs_from_pj
24 proj_normalize_for_visualization
25 proj_destroy
26 )],
27 area => [qw(
28 proj_area_create
29 proj_area_set_bbox
30 proj_area_destroy
31 )],
32 transform => [qw(
33 proj_trans
34 )],
35 error => [qw(
36 proj_context_errno
37 proj_errno
38 proj_errno_set
39 proj_errno_reset
40 proj_errno_restore
41 proj_errno_string
42 proj_context_errno_string
43 )],
44 logging => [qw(
45 proj_log_level
46 proj_log_func
47 )],
48 info => [qw(
49 proj_info
50 proj_pj_info
51 proj_grid_info
52 proj_init_info
53 )],
54 lists => [qw(
55 proj_list_operations
56 proj_list_ellps
57 proj_list_units
58 proj_list_angular_units
59 proj_list_prime_meridians
60 )],
61 distance => [qw(
62 proj_lp_dist
63 proj_lpz_dist
64 proj_xy_dist
65 proj_xyz_dist
66 proj_geod
67 )],
68 misc => [qw(
69 proj_coord
70 )],
71 const => [qw(
72 PJ_DEFAULT_CTX
73 PJ_LOG_NONE PJ_LOG_ERROR PJ_LOG_DEBUG PJ_LOG_TRACE PJ_LOG_TELL
74 PJ_FWD PJ_IDENT PJ_INV
75 )],
76 all => [qw(
77 :context
78 :setup
79 :area
80 :transform
81 :error
82 :logging
83 :info
84 :lists
85 :distance
86 :misc
87 :const
88 proj_cleanup
89 )],
90 ]);
91  
92 my $ffi = FFI::Platypus->new(
93 api => 2,
94 lang => 'C',
95 lib => [Alien::proj->dynamic_libs],
96 );
97 FFI::C->ffi($ffi);
98  
99 my $c = Convert::Binary::C->new(Alignment => 0);
100  
101 $ffi->load_custom_type('::StringPointer' => 'string_pointer');
102 # string* should also work, but doesn't in $ffi->cast
103 $ffi->load_custom_type('::StringArray' => 'string_array');
104 # string[] should also work, but causes strlen in proj_create_crs_to_crs_from_pj to segfault
105  
106  
107  
108 # based on proj.h version 8.0.0
109  
110 # ***************************************************************************
111 # Copyright (c) 2016, 2017, Thomas Knudsen / SDFE
112 # Copyright (c) 2018, Even Rouault
113 #
114 # Permission is hereby granted, free of charge, to any person obtaining a
115 # copy of this software and associated documentation files (the "Software"),
116 # to deal in the Software without restriction, including without limitation
117 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
118 # and/or sell copies of the Software, and to permit persons to whom the
119 # Software is furnished to do so, subject to the following conditions:
120 #
121 # The above copyright notice and this permission notice shall be included
122 # in all copies or substantial portions of the Software.
123 #
124 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
125 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
126 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO COORD SHALL
127 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
128 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
129 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
130 # DEALINGS IN THE SOFTWARE.
131 # ***************************************************************************
132  
133 # C API new generation
134  
135 $ffi->type('opaque' => 'PJ_AREA');
136  
137 # Data type for projection/transformation information
138 $ffi->type('opaque' => 'PJ'); # the PJ object herself
139  
140 # Data types for list of operations, ellipsoids, datums and units used in PROJ.4
141 $c->parse(<<ENDC);
142 struct PJ_LIST {
143 const char *id; /* projection keyword */
144 void *(*proj)(void *); /* projection entry point */
145 const char * const *descr; /* description text */
146 };
147 ENDC
148 $ffi->custom_type( 'PJ_OPERATIONS' => {
149 native_to_perl => sub {
150 my ($ptr) = @_;
151 my $size = $c->sizeof('PJ_LIST');
152 my @list;
153 while () {
154 $ptr += $size;
155 my $item = $c->unpack('PJ_LIST', $ffi->cast( 'opaque' => "record($size)*", $ptr ));
156 last unless $item->{id};
157 $item->{id} = $ffi->cast( 'opaque' => 'string', $item->{id} );
158 $item->{descr} = $ffi->cast( 'opaque' => 'string_pointer', $item->{descr} );
159 push @list, $item;
160 }
161 return \@list;
162 },
163 });
164  
165 sub _unpack_list {
166 my ($type, $ptr) = @_;
167 my $size = $c->sizeof($type);
168 my @list;
169 while () {
170 my $item = $c->unpack($type, $ffi->cast( 'opaque' => "record($size)*", $ptr ));
171 last unless $item->{id};
172 $item->{$_} = $ffi->cast( 'opaque' => 'string', $item->{$_} )
173 for grep { $c->typeof("$type.$_") eq 'char *' } keys %$item;
174 push @list, $item;
175 $ptr += $size;
176 }
177 return \@list;
178 }
179  
180 $c->parse(<<ENDC);
181 struct PJ_ELLPS {
182 const char *id; /* ellipse keyword name */
183 const char *major; /* a= value */
184 const char *ell; /* elliptical parameter */
185 const char *name; /* comments */
186 };
187 ENDC
188 $ffi->custom_type( 'PJ_ELLPS' => {
189 native_to_perl => sub { _unpack_list(PJ_ELLPS => @_) },
190 });
191  
192 $c->parse(<<ENDC);
193 struct PJ_UNITS {
194 const char *id; /* units keyword */
195 const char *to_meter; /* multiply by value to get meters */
196 const char *name; /* comments */
197 double factor; /* to_meter factor in actual numbers */
198 };
199 ENDC
200 $ffi->custom_type( 'PJ_UNITS' => {
201 native_to_perl => sub { _unpack_list(PJ_UNITS => @_) },
202 });
203  
204 $c->parse(<<ENDC);
205 struct PJ_PRIME_MERIDIANS {
206 const char *id; /* prime meridian keyword */
207 const char *defn; /* offset from greenwich in DMS format. */
208 };
209 ENDC
210 $ffi->custom_type( 'PJ_PRIME_MERIDIANS' => {
211 native_to_perl => sub { _unpack_list(PJ_PRIME_MERIDIANS => @_) },
212 });
213  
214  
215 # Geodetic, mostly spatiotemporal coordinate types
216 {
217 package Geo::LibProj::FFI::PJ_XYZT 1.01;
218 sub new { Geo::LibProj::FFI::PJ_COORD->_new($_[1], qw{ x y z t }) }
219 package Geo::LibProj::FFI::PJ_UVWT 1.01;
220 sub new { Geo::LibProj::FFI::PJ_COORD->_new($_[1], qw{ u v w t })->uvwt }
221 package Geo::LibProj::FFI::PJ_LPZT 1.01;
222 sub new { Geo::LibProj::FFI::PJ_COORD->_new($_[1], qw{ lam phi z t }) }
223 package Geo::LibProj::FFI::PJ_OPK 1.01;
224 sub new { Geo::LibProj::FFI::PJ_COORD->_new($_[1], qw{ o p k 0 }) }
225 # Rotations: omega, phi, kappa
226 package Geo::LibProj::FFI::PJ_ENU 1.01;
227 sub new { Geo::LibProj::FFI::PJ_COORD->_new($_[1], qw{ e n u 0 }) }
228 # East, North, Up
229 package Geo::LibProj::FFI::PJ_GEOD 1.01;
230 sub new { Geo::LibProj::FFI::PJ_COORD->_new($_[1], qw{ s a1 a2 0 }) }
231 # Geodesic length, fwd azi, rev azi
232 }
233  
234 # Classic proj.4 pair/triplet types - moved into the PJ_ name space
235 {
236 package Geo::LibProj::FFI::PJ_UV 1.01;
237 sub new { Geo::LibProj::FFI::PJ_COORD->_new($_[1], qw{ u v 0 0 })->uv }
238 package Geo::LibProj::FFI::PJ_XY 1.01;
239 sub new { Geo::LibProj::FFI::PJ_COORD->_new($_[1], qw{ x y 0 0 }) }
240 package Geo::LibProj::FFI::PJ_LP 1.01;
241 sub new { Geo::LibProj::FFI::PJ_COORD->_new($_[1], qw{ lam phi 0 0 }) }
242
243 package Geo::LibProj::FFI::PJ_XYZ 1.01;
244 sub new { Geo::LibProj::FFI::PJ_COORD->_new($_[1], qw{ x y z 0 }) }
245 package Geo::LibProj::FFI::PJ_UVW 1.01;
246 sub new { Geo::LibProj::FFI::PJ_COORD->_new($_[1], qw{ u v w 0 })->uvw }
247 package Geo::LibProj::FFI::PJ_LPZ 1.01;
248 sub new { Geo::LibProj::FFI::PJ_COORD->_new($_[1], qw{ lam phi z 0 }) }
249 }
250  
251  
252 # Data type for generic geodetic 3D data plus epoch information
253 # Avoid preprocessor renaming and implicit type-punning: Use a union to make it explicit
254 {
255 # FFI::C::Union can't be passed by value due to limitations within
256 # FFI::Platypus. Workaround: Use a Record with some additional Perl
257 # glue. The performance may not be perfect, but seems satisfactory.
258
259 package Geo::LibProj::FFI::PJ_COORD 1.01;
260 use FFI::Platypus::Record;
261 record_layout_1(qw{ double[4] v });
262 # First and foremost, it really is "just 4 numbers in a vector"
263
264 # union members:
265
266 sub xyzt_x { shift->v(0, @_) }
267 sub xyzt_y { shift->v(1, @_) }
268 sub xyzt_z { shift->v(2, @_) }
269 sub xyzt_t { shift->v(3, @_) }
270
271 sub uvwt_u { shift->v(0, @_) }
272 sub uvwt_v { shift->v(1, @_) }
273 sub uvwt_w { shift->v(2, @_) }
274 sub uvwt_t { shift->v(3, @_) }
275
276 sub lpzt_lam { shift->v(0, @_) }
277 sub lpzt_phi { shift->v(1, @_) }
278 sub lpzt_z { shift->v(2, @_) }
279 sub lpzt_t { shift->v(3, @_) }
280
281 sub geod_s { shift->v(0, @_) }
282 sub geod_a1 { shift->v(1, @_) }
283 sub geod_a2 { shift->v(2, @_) }
284
285 sub opk_o { shift->v(0, @_) }
286 sub opk_p { shift->v(1, @_) }
287 sub opk_k { shift->v(2, @_) }
288
289 sub enu_e { shift->v(0, @_) }
290 sub enu_n { shift->v(1, @_) }
291 sub enu_u { shift->v(2, @_) }
292
293 sub xyz_x { shift->v(0, @_) }
294 sub xyz_y { shift->v(1, @_) }
295 sub xyz_z { shift->v(2, @_) }
296
297 sub uvw_u { shift->v(0, @_) }
298 sub uvw_v { shift->v(1, @_) }
299 sub uvw_w { shift->v(2, @_) }
300
301 sub lpz_lam { shift->v(0, @_) }
302 sub lpz_phi { shift->v(1, @_) }
303 sub lpz_z { shift->v(2, @_) }
304
305 sub xy_x { shift->v(0, @_) }
306 sub xy_y { shift->v(1, @_) }
307
308 sub uv_u { shift->v(0, @_) }
309 sub uv_v { shift->v(1, @_) }
310
311 sub lp_lam { shift->v(0, @_) }
312 sub lp_phi { shift->v(1, @_) }
313
314 # legacy support:
315 sub _new {
316 my ($class, $values, @params) = @_;
317 warnings::warnif_at_level( 'deprecated', 1, sprintf 'Creating %s values with new() is deprecated; use proj_coords() instead', caller =~ s/^.*://r );
318 $values //= {};
319 @params = map { $values->{$_} // 0 } @params;
320 return $class->new({ 'v' => \@params });
321 }
322 sub _set {
323 my ($self, $values, @params) = @_;
324 warnings::warnif_at_level( 'deprecated', 2, 'Setting PJ_COORD union members is deprecated; use proj_coords() instead' );
325 if (ref $values eq 'HASH') {
326 @params = map { $values->{$_} } @params;
327 }
328 else {
329 @params = map { eval "\$values->$_" } grep !/^0$/, @params; ## no critic (ProhibitStringyEval)
330 }
331 $self->v(\@params);
332 }
333 *warnings::warnif_at_level = sub { warnings::warnif(shift, pop) } if $^V lt v5.27;
334
335 # union members:
336 sub xyzt { $_[1] ? $_[0]->_set($_[1], qw{ x y z t }) : shift }
337 sub uvwt { $_[1] ? $_[0]->_set($_[1], qw{ u v w t }) : Geo::LibProj::FFI::PJ_UVWT->_new(shift) }
338 sub lpzt { $_[1] ? $_[0]->_set($_[1], qw{ lam phi z t }) : shift }
339 sub geod { $_[1] ? $_[0]->_set($_[1], qw{ s a1 a2 0 }) : shift }
340 sub opk { $_[1] ? $_[0]->_set($_[1], qw{ o p k 0 }) : shift }
341 sub enu { $_[1] ? $_[0]->_set($_[1], qw{ e n u 0 }) : shift }
342 sub xyz { $_[1] ? $_[0]->_set($_[1], qw{ x y z 0 }) : shift }
343 sub uvw { $_[1] ? $_[0]->_set($_[1], qw{ u v w 0 }) : Geo::LibProj::FFI::PJ_UVWT->_new(shift) }
344 sub lpz { $_[1] ? $_[0]->_set($_[1], qw{ lam phi z 0 }) : shift }
345 sub xy { $_[1] ? $_[0]->_set($_[1], qw{ x y 0 0 }) : shift }
346 sub uv { $_[1] ? $_[0]->_set($_[1], qw{ u v 0 0 }) : Geo::LibProj::FFI::PJ_UVWT->_new(shift) }
347 sub lp { $_[1] ? $_[0]->_set($_[1], qw{ lam phi 0 0 }) : shift }
348
349 # struct members:
350 # PJ_UV* need their own package due to name collisions.
351 # The other types are implemented by the PJ_COORD package.
352
353 sub x { shift->v(0, @_) }
354 sub lam { shift->v(0, @_) }
355 sub o { shift->v(0, @_) }
356 sub e { shift->v(0, @_) }
357 sub s { shift->v(0, @_) }
358
359 sub y { shift->v(1, @_) }
360 sub phi { shift->v(1, @_) }
361 sub p { shift->v(1, @_) }
362 sub n { shift->v(1, @_) }
363 sub a1 { shift->v(1, @_) }
364
365 sub z { shift->v(2, @_) }
366 sub k { shift->v(2, @_) }
367 sub u { shift->v(2, @_) }
368 sub a2 { shift->v(2, @_) }
369
370 sub t { shift->v(3, @_) }
371
372 package Geo::LibProj::FFI::PJ_UVWT;
373 sub _new { bless \$_[1], $_[0] }
374 sub u { ${shift()}->v( 0, @_ ) }
375 sub v { ${shift()}->v( 1, @_ ) }
376 sub w { ${shift()}->v( 2, @_ ) }
377 sub t { ${shift()}->v( 3, @_ ) }
378
379 }
380 $ffi->type('record(Geo::LibProj::FFI::PJ_COORD)' => 'PJ_COORD');
381  
382  
383 {
384 package Geo::LibProj::FFI::PJ_INFO 1.01;
385 use FFI::Platypus::Record;
386 record_layout_1(
387 int => 'major', # Major release number
388 int => 'minor', # Minor release number
389 int => 'patch', # Patch level
390 string => 'release', # Release info. Version + date
391 string => 'version', # Full version number
392 string => 'searchpath', # Paths where init and grid files are
393 # looked for. Paths are separated by
394 # semi-colons on Windows, and colons
395 # on non-Windows platforms.
396 opaque => 'paths',
397 size_t => 'path_count',
398 );
399 }
400 $ffi->type('record(Geo::LibProj::FFI::PJ_INFO)' => 'PJ_INFO');
401  
402 {
403 package Geo::LibProj::FFI::PJ_PROJ_INFO 1.01;
404 use FFI::Platypus::Record;
405 record_layout_1(
406 string => 'id', # Name of the projection in question
407 string => 'description', # Description of the projection
408 string => 'definition', # Projection definition
409 int => 'has_inverse', # 1 if an inverse mapping exists, 0 otherwise
410 double => 'accuracy', # Expected accuracy of the transformation. -1 if unknown.
411 );
412 }
413 $ffi->type('record(Geo::LibProj::FFI::PJ_PROJ_INFO)' => 'PJ_PROJ_INFO');
414  
415 {
416 package Geo::LibProj::FFI::PJ_GRID_INFO 1.01;
417 use FFI::Platypus::Record;
418 record_layout_1(
419 'string(32)' => 'gridname_NUL', # name of grid
420 'string(260)' => 'filename_NUL', # full path to grid
421 'string(8)' => 'format_NUL', # file format of grid
422 double => 'left', double => 'lower', # Coordinates of lower left corner
423 double => 'right', double => 'upper', # Coordinates of upper right corner
424 int => 'n_lon', int => 'n_lat', # Grid size
425 double => 'cs_lon', double => 'cs_lat', # Cell size of grid
426 );
427 sub gridname { my $s = shift->gridname_NUL; $s =~ s/\0+$//; $s }
428 sub filename { my $s = shift->filename_NUL; $s =~ s/\0+$//; $s }
429 sub format { my $s = shift->format_NUL; $s =~ s/\0+$//; $s }
430 sub lowerleft { Geo::LibProj::FFI::PJ_COORD->new({ v => [$_[0]->left, $_[0]->lower] }) }
431 sub upperright { Geo::LibProj::FFI::PJ_COORD->new({ v => [$_[0]->right, $_[0]->upper] }) }
432 }
433 $ffi->type('record(Geo::LibProj::FFI::PJ_GRID_INFO)' => 'PJ_GRID_INFO');
434  
435 {
436 package Geo::LibProj::FFI::PJ_INIT_INFO 1.01;
437 use FFI::Platypus::Record;
438 record_layout_1(
439 'string(32)' => 'name_NUL', # name of init file
440 'string(260)' => 'filename_NUL', # full path to the init file.
441 'string(32)' => 'version_NUL', # version of the init file
442 'string(32)' => 'origin_NUL', # origin of the file, e.g. EPSG
443 'string(16)' => 'lastupdate_NUL', # Date of last update in YYYY-MM-DD format
444 );
445 sub name { my $s = shift->name_NUL; $s =~ s/\0+$//; $s }
446 sub filename { my $s = shift->filename_NUL; $s =~ s/\0+$//; $s }
447 sub version { my $s = shift->version_NUL; $s =~ s/\0+$//; $s }
448 sub origin { my $s = shift->origin_NUL; $s =~ s/\0+$//; $s }
449 sub lastupdate { my $s = shift->lastupdate_NUL; $s =~ s/\0+$//; $s }
450 }
451 $ffi->type('record(Geo::LibProj::FFI::PJ_INIT_INFO)' => 'PJ_INIT_INFO');
452  
453 FFI::C->enum('PJ_LOG_LEVEL', [
454 [PJ_LOG_NONE => 0],
455 [PJ_LOG_ERROR => 1],
456 [PJ_LOG_DEBUG => 2],
457 [PJ_LOG_TRACE => 3],
458 [PJ_LOG_TELL => 4],
459 [PJ_LOG_DEBUG_MAJOR => 2], # for proj_api.h compatibility
460 [PJ_LOG_DEBUG_MINOR => 3], # for proj_api.h compatibility
461 ], {rev => 'int'});
462  
463 # The context type - properly namespaced synonym for pj_ctx
464 $ffi->type('opaque' => 'PJ_CONTEXT');
465  
466 # A P I
467  
468 # The objects returned by the functions defined in this section have minimal
469 # interaction with the functions of the
470 # iso19111_functions section, and vice versa. See its introduction
471 # paragraph for more details.
472  
473 # Functionality for handling thread contexts
474 use constant PJ_DEFAULT_CTX => 0;
475 $ffi->attach( proj_context_create => [] => 'PJ_CONTEXT');
476 $ffi->attach( proj_context_destroy => ['PJ_CONTEXT'] => 'void');
477  
478 $ffi->attach( proj_context_use_proj4_init_rules => [qw( PJ_CONTEXT int )] => 'void' );
479  
480 # Manage the transformation definition object PJ
481 $ffi->attach( proj_create => [qw( PJ_CONTEXT string )] => 'PJ' );
482 $ffi->attach( proj_create_argv => [qw( PJ_CONTEXT int string_array )] => 'PJ');
483 $ffi->attach( proj_create_crs_to_crs => [qw( PJ_CONTEXT string string PJ_AREA )] => 'PJ');
484 $ffi->attach( proj_create_crs_to_crs_from_pj => [qw( PJ_CONTEXT PJ PJ PJ_AREA string_array )] => 'PJ', sub{
485 $_[0]->( @_[1..4], $_[5] || [] ); # StringArray won't accept NULL
486 });
487 $ffi->attach( proj_normalize_for_visualization => ['PJ_CONTEXT', 'PJ'] => 'PJ');
488 $ffi->attach( proj_destroy => ['PJ'] => 'void');
489  
490  
491 $ffi->attach( proj_area_create => [] => 'PJ_AREA');
492 $ffi->attach( proj_area_set_bbox => [qw( PJ_AREA double double double double )] => 'void');
493 $ffi->attach( proj_area_destroy => [qw( PJ_AREA )] => 'void');
494  
495 # Apply transformation to observation - in forward or inverse direction
496 FFI::C->enum('PJ_DIRECTION', [
497 [PJ_FWD => 1], # Forward
498 [PJ_IDENT => 0], # Do nothing
499 [PJ_INV => -1], # Inverse
500 ]);
501  
502  
503 $ffi->attach( proj_trans => ['PJ', 'PJ_DIRECTION', 'PJ_COORD'] => 'PJ_COORD');
504  
505 # non-standard method (now discouraged; originally used by Perl cs2cs)
506 # (expects and returns a single point as array ref)
507 $ffi->attach( [proj_trans => '_trans'] => ['PJ', 'PJ_DIRECTION', 'PJ_COORD'] => 'PJ_COORD', sub {
508 my ($sub, $pj, $dir, $coord) = @_;
509 $sub->( $pj, $dir, proj_coord($coord->[0] // 0, $coord->[1] // 0, $coord->[2] // 0, $coord->[3] // 0) )->v;
510 });
511  
512  
513 # Initializers
514 $ffi->attach( proj_coord => [qw( double double double double )] => 'PJ_COORD');
515  
516 # Geodesic distance between two points with angular 2D coordinates
517 $ffi->attach( proj_lp_dist => [qw( PJ PJ_COORD PJ_COORD )] => 'double');
518  
519 # The geodesic distance AND the vertical offset
520 $ffi->attach( proj_lpz_dist => [qw( PJ PJ_COORD PJ_COORD )] => 'double');
521  
522 # Euclidean distance between two points with linear 2D coordinates
523 $ffi->attach( proj_xy_dist => [qw( PJ_COORD PJ_COORD )] => 'double');
524  
525 # Euclidean distance between two points with linear 3D coordinates
526 $ffi->attach( proj_xyz_dist => [qw( PJ_COORD PJ_COORD )] => 'double');
527  
528 # Geodesic distance (in meter) + fwd and rev azimuth between two points on the ellipsoid
529 $ffi->attach( proj_geod => [qw( PJ PJ_COORD PJ_COORD )] => 'PJ_COORD');
530  
531 # Set or read error level
532 $ffi->attach( proj_context_errno => ['PJ_CONTEXT'] => 'int');
533 $ffi->attach( proj_errno => ['PJ_CONTEXT'] => 'int');
534 $ffi->attach( proj_errno_set => ['PJ_CONTEXT', 'int'] => 'int');
535 $ffi->attach( proj_errno_reset => ['PJ_CONTEXT'] => 'int');
536 $ffi->attach( proj_errno_restore => ['PJ_CONTEXT', 'int'] => 'int');
537 $ffi->attach( proj_errno_string => ['int'] => 'string'); # deprecated. use proj_context_errno_string()
538 eval { $ffi->attach( proj_context_errno_string => ['PJ_CONTEXT', 'int'] => 'string'); 1 }
539 or do { *proj_context_errno_string = sub { proj_errno_string($_[1]); } };
540  
541 $ffi->attach( proj_log_level => ['PJ_CONTEXT', 'PJ_LOG_LEVEL'] => 'PJ_LOG_LEVEL');
542 $ffi->attach( proj_log_func => ['PJ_CONTEXT', 'opaque', '(opaque,int,string)->void'] => 'void', sub {
543 my ($sub, $ctx, $app_data, $logf) = @_;
544 my $closure = $ffi->closure( $app_data ? sub {
545 my (undef, $level, $msg) = @_;
546 $logf->($app_data, $level, $msg);
547 } : $logf );
548 $closure->sticky;
549 $sub->($ctx, 0, $closure);
550 });
551  
552 # Info functions - get information about various PROJ.4 entities
553 $ffi->attach( proj_info => [] => 'PJ_INFO');
554 $ffi->attach( proj_pj_info => ['PJ'] => 'PJ_PROJ_INFO');
555 $ffi->attach( proj_grid_info => ['string'] => 'PJ_GRID_INFO');
556 $ffi->attach( proj_init_info => ['string'] => 'PJ_INIT_INFO');
557  
558 # List functions:
559 # Get lists of operations, ellipsoids, units and prime meridians.
560 $ffi->attach( proj_list_operations => [] => 'PJ_OPERATIONS');
561 $ffi->attach( proj_list_ellps => [] => 'PJ_ELLPS');
562 $ffi->attach( proj_list_units => [] => 'PJ_UNITS');
563 $ffi->attach( proj_list_angular_units => [] => 'PJ_UNITS');
564 $ffi->attach( proj_list_prime_meridians => [] => 'PJ_PRIME_MERIDIANS');
565  
566 $ffi->attach( proj_cleanup => [] => 'void');
567  
568 1;
569  
570 __END__
↑ Summary