Geo::LibProj::FFI - Foreign function interface to PROJ coordinate transformation software
version 0.04
use Geo::LibProj::FFI qw(:all); use Syntax::Keyword::Defer; my $ctx = proj_context_create() or die "Cannot create threading context"; defer { proj_context_destroy($ctx); } my $pj = proj_create_crs_to_crs($ctx, "EPSG:25833", "EPSG:2198", undef) or die "Cannot create proj"; defer { proj_destroy($pj); } ($easting, $northing) = ( 500_000, 6094_800 ); $a = proj_coord( $easting, $northing, 0, 'Inf' ); $b = proj_trans( $pj, PJ_FWD, $a ); printf "Target: easting %.2f, northing %.2f\n", $b->enu->e, $b->enu->n;
See also the example script eg/pj_obs_api_mini_demo.pl in this distribution.
This module is a foreign function interface to the PROJ coordinate transformation library. Please see the PROJ library's C function reference for further documentation. You should be able to use those C functions as if they were Perl.
This module is functional, but incomplete.
Geo::LibProj::FFI currently offers the following functions.
Import all functions and constants by using the tag :all.
:all
proj_context_create
proj_context_destroy
proj_context_use_proj4_init_rules
proj_create
proj_create_argv
proj_create_crs_to_crs
proj_create_crs_to_crs_from_pj
proj_normalize_for_visualization
proj_destroy
proj_area_create
proj_area_set_bbox
proj_area_destroy
proj_trans
proj_context_errno
proj_errno
proj_errno_set
proj_errno_reset
proj_errno_restore
proj_errno_string
proj_context_errno_string
proj_log_level
proj_log_func
proj_info
proj_pj_info
proj_grid_info
proj_init_info
proj_list_operations
proj_list_ellps
proj_list_units
proj_list_angular_units
proj_list_prime_meridians
proj_lp_dist
proj_lpz_dist
proj_xy_dist
proj_xyz_dist
proj_geod
proj_coord
proj_cleanup
The PROJ library uses numerous composite data types. When working with Geo::LibProj::FFI, members of C struct and union types may be accessed for reading by calling methods on these composites. For example, to output the X coordinate of a PJ_COORD value, you could simply do print $coord->xyz->x();. Please see the PROJ data type reference for further documentation.
struct
union
PJ_COORD
print $coord->xyz->x();
As of version 0.04 of this module, the interface for modifying values of composite types from Perl is still evolving. Therefore, values of C struct and union types are best treated as immutable by Perl users. For the same reason, it is not recommended to try and create new values of such types using Perl constructors; instead, users should use PROJ functions to create such values wherever possible.
That said, it is already now fully possible to modify such values and to construct them using new(); it's just not yet recommended to do so. Consider this code example to create and modify a PJ_COORD value:
new()
# discouraged: # (not guaranteed to work in future versions) $coord = Geo::LibProj::FFI::PJ_COORD->new({ xy => { x => 12, y => 34 } }); $coord->xyz->z( 100 ); # recommended: $coord = proj_coord( 12, 34, 0, 0 ); $vector = $coord->v; $vector->[2] = 100; $coord = proj_coord( @$vector );
PROJ makes heavy use of C union pass-by-value, which is unsupported by FFI::Platypus. In earlier versions of this module, the workaround for working with PJ_COORD values was quite slow. This performance issue has been addressed as of version 0.03.
Some implementation details of the glue this module provides may change in future, for example to better match the API or to increase performance. Should you decide to use this module in production, it would be wise to watch the GitHub project for changes, at least until the version has reached 1.00.
This module is designed to be used with PROJ version 8. PROJ versions as far back as 6.2.0 should work as well; please report any issues.
Geo::LibProj::cs2cs
Geo::Proj4
PROJ C API Reference: Data types, Functions
The API this module gives access to is the proj.h API, which is available under the terms of the Expat MIT license.
proj.h
Copyright (c) 2016, 2017, Thomas Knudsen / SDFE Copyright (c) 2018, Even Rouault
The API designers didn't write this Perl module, and the module author didn't design the API.
Arne Johannessen <ajnn@cpan.org>
This software is Copyright (c) 2021 by Arne Johannessen.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Geo::LibProj::FFI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Geo::LibProj::FFI
CPAN shell
perl -MCPAN -e shell install Geo::LibProj::FFI
For more information on module installation, please visit the detailed CPAN module installation guide.