Skip to content

Commit

Permalink
switch GIS::Proj from Proj.4 to 6
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Dec 12, 2021
1 parent d3ed25b commit dfc7dc2
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
uses: PDLPorters/devops/github-actions/install-dep-eumm-blead@master

- name: Install PDL dependencies
uses: PDLPorters/devops/github-actions/install-dep-pdl-dep@master
uses: PDLPorters/devops/github-actions/install-dep-pdl-dep@proj6

- name: 'ci-dist: target-install-dist-perl-deps'
uses: PDLPorters/devops/github-actions/ci-dist@master
Expand Down
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- remove PDL.{dim_checks,get,put_offs} from Core
- rename PDL.children_changesoon to changesoon
- GIS::Proj inplace funcs set output bad if any input bad
- switched GIS::Proj to PROJ 6 API

2.063 2021-11-19
- PDL::Core::seed - thanks @zmughal
Expand Down
8 changes: 4 additions & 4 deletions Libtmp/GIS/Proj/Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ use ExtUtils::MakeMaker;
my $package_name = "PDL::GIS::Proj";
my $lib_name = "Proj";

eval { require Alien::Proj4 };
eval { require Alien::proj };
if ($@) {
write_dummy_make("Will skip build of $package_name on this system - no Alien::Proj4");
write_dummy_make("Will skip build of $package_name on this system - no Alien::proj");
return;
}

my $incflags = Alien::Proj4->cflags;
my $incflags = Alien::proj->cflags;

my $ppfile = "Proj.pd";
my $package = [$ppfile, 'Proj', $package_name];
my %hash = pdlpp_stdargs_int($package);
$hash{VERSION_FROM} = $ppfile;
#$hash{TYPEMAPS} = [&PDL_TYPEMAP()];
$hash{LIBS} = [ Alien::Proj4->libs ];
$hash{LIBS} = [ Alien::proj->libs ];
$hash{INC} = PDL_INCLUDE() . " $incflags";

undef &MY::postamble; # suppress warning
Expand Down
56 changes: 18 additions & 38 deletions Libtmp/GIS/Proj/Proj.pd
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use strict;
use vars qw( $VERSION );
$VERSION = "1.32";

# when switch to Alien::Proj4 as separate module
# use Alien::Proj4;
pp_addpm({At=>'Top'},<<'EODOC');
=head1 NAME
Expand Down Expand Up @@ -53,10 +51,13 @@ EODOC
# Header files:
#
pp_addhdr(<<'EOHDR');
#include "projects.h"
#include "proj_api.h"
#include "proj.h"
#include <string.h>
/* from proj_api.h */
#define RAD_TO_DEG 57.295779513082321
#define DEG_TO_RAD .017453292519943296
EOHDR

pp_addpm(<<'EOPM');
Expand All @@ -81,40 +82,35 @@ EOPM
pp_add_exported('', ' get_proj_info ');

my $code_head = <<'EOF';
projUV in, out;
projPJ proj;
const double d2r = DEG_TO_RAD, r2d = RAD_TO_DEG;
/* Init the projection */
proj = pj_init_plus( $COMP(params) );
PJ_COORD in, out;
PJ *proj = proj_create( NULL, $COMP(params) ); /* Init the projection */
if( proj == NULL )
{
$CROAK("%s: Projection initialization failed: %s\n", func, pj_strerrno(pj_errno));
}
$CROAK("%s: Projection initialization failed: %s\n", func, proj_errno_string(proj_errno(proj)));
/* Loop over the values converting as we go */
threadloop %{
EOF
my $code_foot = <<'EOF';
%}
pj_free(proj);
proj_destroy(proj);
EOF

sub wrap_code {
my ($name, $ins, $outs, $is_fwd) = @_;
my $setup = <<EOF;
in.u = \$$ins->[0]() @{[$is_fwd ? ' * d2r' : '']};
in.v = \$$ins->[1]() @{[$is_fwd ? ' * d2r' : '']};
out = pj_@{[$is_fwd ? 'fwd' : 'inv']}(in, proj);
if (out.u == HUGE_VAL)
in.uv.u = \$$ins->[0]() @{[$is_fwd ? ' * DEG_TO_RAD' : '']};
in.uv.v = \$$ins->[1]() @{[$is_fwd ? ' * DEG_TO_RAD' : '']};
out = proj_trans(proj, PJ_@{[$is_fwd ? 'FWD' : 'INV']}, in);
if (out.uv.u == HUGE_VAL)
{
EOF
my $save = <<EOF;
}
\$$outs->[0]() = out.u@{[$is_fwd ? '' : ' * r2d']};
\$$outs->[1]() = out.v@{[$is_fwd ? '' : ' * r2d']};
\$$outs->[0]() = out.uv.u@{[$is_fwd ? '' : ' * RAD_TO_DEG']};
\$$outs->[1]() = out.uv.v@{[$is_fwd ? '' : ' * RAD_TO_DEG']};
EOF
my $body = $setup.<<EOF.$save;
\$CROAK("%s: Projection conversion failed at (%f, %f): %s\\n",
func, @{[ join ',', map '$'.$_.'()', @$ins ]}, pj_strerrno(pj_errno));
func, @{[ join ',', map '$'.$_.'()', @$ins ]}, proj_errno_string(proj_errno(proj)));
EOF
my $code = join '', qq{char* func = "$name()";},
$code_head,
Expand Down Expand Up @@ -212,21 +208,15 @@ pp_def( 'inv_trans_inplace',
# Utility functions for getting projection description information (in a general case).
#
# when switch to Alien::Proj4 as separate module, replace with:
# pp_addpm(<<'ENDPM' );
# sub load_projection_descriptions {
# return Alien::Proj4->load_projection_descriptions;
# }
# ENDPM
pp_addxs('', <<'ENDXS' );
HV*
load_projection_descriptions()
CODE:
struct PJ_LIST *lp;
const PJ_OPERATIONS *lp;
SV* scalar_val;
RETVAL = newHV();
for (lp = pj_get_list_ref() ; lp->id ; ++lp)
for (lp = proj_list_operations() ; lp->id ; ++lp)
{
scalar_val = newSVpv( *lp->descr, 0 );
hv_store( RETVAL, lp->id, strlen( lp->id ), scalar_val, 0 );
Expand All @@ -237,16 +227,6 @@ load_projection_descriptions()
ENDXS
pp_add_exported('', ' load_projection_descriptions ');
#
# Perl code to finish loading the projetion information by parsing the descriptions:
#
# when switch to Alien::Proj4 as separate module, replace with:
# pp_addpm(<<'ENDPM' );
# sub load_projection_information {
# return Alien::Proj4->load_projection_information;
# }
# ENDPM
pp_addpm( <<'ENDPM' );
my %SKIP = map +($_=>1), qw(
Expand Down
15 changes: 2 additions & 13 deletions Libtmp/GIS/Proj/t/gis_proj.t
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,12 @@ ok(1);
# TEST 14:
# Get projection descriptions:
my $projections = load_projection_descriptions();
#use Data::Dumper;
#my $dd = Data::Dumper->new( [$projections], ['projections'] );
#$dd->Indent(1);
#print STDERR $dd->Dump();
ok(1);
#diag explain $projections;

# TEST 15:
# Get full projection information:
my $info = load_projection_information();
#use Data::Dumper;
#foreach ( sort keys %$info )
#{
# my $dd2 = Data::Dumper->new( [ $info->{$_} ], [ $_ ] );
# $dd2->Indent(1);
# print STDERR $dd2->Dump() . "\n";
#}
ok(1);
#diag explain $info;

done_testing;

Expand Down
8 changes: 4 additions & 4 deletions Libtmp/Transform/Proj4/Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ use ExtUtils::MakeMaker;
my $package_name = "PDL::Transform::Proj4";
my $lib_name = "Proj4";

eval { require Alien::Proj4 };
eval { require Alien::proj };
if ($@) {
write_dummy_make("Will skip build of $package_name on this system - no Alien::Proj4");
write_dummy_make("Will skip build of $package_name on this system - no Alien::proj");
return;
}

my $incflags = Alien::Proj4->cflags;
my $incflags = Alien::proj->cflags;

my $ppfile = "Proj4.pd";
my $package = [$ppfile, 'Proj4', $package_name];
my %hash = pdlpp_stdargs_int($package);
$hash{VERSION_FROM} = $ppfile;
#$hash{TYPEMAPS} = [&PDL_TYPEMAP()];
$hash{LIBS} = [ Alien::Proj4->libs ];
$hash{LIBS} = [ Alien::proj->libs ];
$hash{INC} = PDL_INCLUDE() . " $incflags";
$hash{realclean} = { FILES => '' } unless $hash{realclean};
$hash{realclean}{FILES} .= ' _Inline';
Expand Down
6 changes: 4 additions & 2 deletions Libtmp/Transform/Proj4/Proj4.pd
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,10 @@ ENDPM
push( @export_funcs, 't_proj' );

# Add in the auto-generated projection classes:
require Alien::Proj4;
my $projections = Alien::Proj4->load_projection_information();
my $projections = eval {
require PDL::GIS::Proj;
PDL::GIS::Proj::load_projection_information();
} || {};

foreach my $name ( sort keys %$projections )
{
Expand Down
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ the work planned for the future PDL-2.x releases.
* PDL::GSL::XXX
- need more complete libgsl bindings
- Alien::GSL
* PDL::GIS::Proj
- duplicate code with Alien::Proj4 needs de-dup-ing
* PDL::Graphics::TriD
- Alien::OpenGL, GLU, GLEW, GLUT, GLUI...
- test with pixel buffer context(?)
Expand Down

0 comments on commit dfc7dc2

Please sign in to comment.