Alien-Proj4
view release on metacpan or search on metacpan
lib/Alien/Proj4.pm view on Meta::CPAN
package Alien::Proj4;
use strict;
use warnings;
use parent qw( Alien::Base );
our $VERSION = '2.019113';
# most of the following are for compat with PDLA Makefiles
# and should not be used by other code
sub installed {1}
sub import {
# do nothing
return;
}
sub default_lib {
return;
}
sub default_inc {
return;
}
sub libflags {
my ($class) = @_;
my $flags = join ' ', $class->libs;
return $flags;
}
sub incflags {
my ($class) = @_;
my $flags = $class->cflags;
return $flags;
}
# dup of code currently in PDLA::GIS::Proj
sub load_projection_descriptions {
my ($class) = @_;
my $incflags = $class->cflags;
my $libflags = $class->libs;
require Inline;
Inline->bind(C => <<'EOF', inc => $incflags, libs => $libflags) unless defined &list_projections;
#include "projects.h"
HV *list_projections() {
struct PJ_LIST *lp;
SV* scalar_val;
HV *hv = newHV();
for (lp = pj_get_list_ref() ; lp->id ; ++lp) {
scalar_val = newSVpv( *lp->descr, 0 );
hv_store( hv, lp->id, strlen( lp->id ), scalar_val, 0 );
}
return hv;
}
EOF
list_projections();
}
# dup of code currently in PDLA::GIS::Proj
sub load_projection_information {
my ($class) = @_;
my $descriptions = $class->load_projection_descriptions();
my $info = {};
foreach my $projection ( keys %$descriptions ) {
my $description = $descriptions->{$projection};
my @lines = split( /\n/, $description );
chomp @lines;
# skip conversion entries if they appear
next if !defined $lines[1];
my $hash = {};
$hash->{CODE} = $projection;
# Full name of this projection:
$hash->{NAME} = $lines[0];
# The second line is usually a list of projection types this one is:
my $temp = $lines[1];
$temp =~ s/no inv\.*,*//;
$temp =~ s/or//;
my @temp_types = split(/[,&\s]/, $temp );
my @types = grep( /.+/, @temp_types );
$hash->{CATEGORIES} = \@types;
# If there's more than 2 lines, then it usually is a listing of parameters:
# General parameters for all projections:
$hash->{PARAMS}->{GENERAL} =
[ qw( x_0 y_0 lon_0 units init no_defs geoc over ) ];
# Earth Figure Parameters:
$hash->{PARAMS}->{EARTH} =
[ qw( ellps b f rf e es R R_A R_V R_a R_g R_h R_lat_g ) ];
# Projection Specific Parameters:
my @proj_params = ();
if( $#lines >= 2 ) {
foreach my $i ( 2 .. $#lines ) {
my $text = $lines[$i];
my @temp2 = split( /\s+/, $text );
my @params = grep( /.+/, @temp2 );
foreach my $param (@params) {
$param =~ s/=//;
$param =~ s/[,\[\]]//sg;
next if $param =~ /^and|or|Special|for|Madagascar|fixed|Earth|For|CH1903$/;
push(@proj_params, $param);
}
}
}
( run in 0.373 second using v1.01-cache-2.11-cpan-119454b85a5 )