File Coverage

blib/lib/Geo/GDAL/FFI/SpatialReference.pm
Criterion Covered Total %
statement 30 46 65.2
branch 6 14 42.8
condition n/a
subroutine 7 9 77.7
pod 3 4 75.0
total 46 73 63.0


line stmt bran cond sub pod time code
1             package Geo::GDAL::FFI::SpatialReference;
2 5     5   65 use v5.10;
  5         19  
3 5     5   26 use strict;
  5         10  
  5         107  
4 5     5   24 use warnings;
  5         10  
  5         147  
5 5     5   38 use Carp;
  5         25  
  5         2592  
6              
7             our $VERSION = 0.0700;
8              
9             sub new {
10 3     3 1 67 my ($class, $arg, @arg) = @_;
11 3         7 my $sr;
12 3 50       17 if (not defined $arg) {
    50          
13 0         0 $sr = Geo::GDAL::FFI::OSRNewSpatialReference();
14             } elsif (not @arg) {
15 0         0 $sr = Geo::GDAL::FFI::OSRNewSpatialReference($arg);
16             } else {
17 3         56 $sr = Geo::GDAL::FFI::OSRNewSpatialReference();
18 3         19 my $gdal = Geo::GDAL::FFI->get_instance;
19 3         15 $arg = $gdal->get_importer($arg);
20 3 50       15100 if ($arg->($sr, @arg) != 0) {
21 0         0 Geo::GDAL::FFI::OSRDestroySpatialReference($sr);
22 0         0 $sr = 0;
23             }
24             }
25 3 50       45 return bless \$sr, $class if $sr;
26 0         0 confess Geo::GDAL::FFI::error_msg();
27             }
28              
29             sub DESTROY {
30 3     3   658 my $self = shift;
31             # OSRGetReferenceCount method not yet implemented
32 3         25 my $refcount = (Geo::GDAL::FFI::OSRReference ($$self)-1);
33 3         17 Geo::GDAL::FFI::OSRDereference ($$self); # immediately decrement
34 3 50       21 if ($refcount == 0) {
35             #warn "Calling DESTROY method for $$self\n";
36 0         0 Geo::GDAL::FFI::OSRDestroySpatialReference($$self);
37             }
38             }
39              
40             sub Export {
41 1     1 1 7 my $self = shift;
42 1         3 my $format = shift;
43 1         6 my $gdal = Geo::GDAL::FFI->get_instance;
44 1         6 my $exporter = $gdal->get_exporter($format);
45 1         3 my $x;
46 1 50       16 if ($exporter->($$self, \$x, @_) != 0) {
47 0         0 confess Geo::GDAL::FFI::error_msg();
48             }
49 1         105 return $x;
50             }
51              
52             sub Set {
53 0     0 1   my $self = shift;
54 0           my $set = shift;
55 0           my $gdal = Geo::GDAL::FFI->get_instance;
56 0           my $setter = $gdal->get_setter($set);
57 0 0         if ($setter->($$self, @_) != 0) {
58 0           confess Geo::GDAL::FFI::error_msg();
59             }
60             }
61              
62             sub Clone {
63 0     0 0   my $self = shift;
64 0           my $s = Geo::GDAL::FFI::OSRClone($$self);
65 0           return bless \$s, 'Geo::GDAL::FFI::SpatialReference';
66             }
67              
68             1;
69              
70             =pod
71              
72             =encoding UTF-8
73              
74             =head1 NAME
75              
76             Geo::GDAL::FFI::SpatialReference - A spatial reference system in GDAL
77              
78             =head1 SYNOPSIS
79              
80             =head1 DESCRIPTION
81              
82             =head1 METHODS
83              
84             =head2 new
85              
86             Create a new SpatialReference object.
87              
88             my $sr = Geo::GDAL::FFI::SpatialReference->new('WKT here...');
89              
90             If only one argument is given, it is taken as the well known text
91             (WKT) associated with the spatial reference system (SRS).
92              
93             my $sr = Geo::GDAL::FFI::SpatialReference->new(EPSG => 3067);
94              
95             If there are more than one argument, the first argument is taken as a
96             format and the rest of the arguments are taken as arguments to the
97             format. The list of formats known to GDAL (at the time of this
98             writing) is EPSG, EPSGA, Wkt, Proj4, ESRI, PCI, USGS, XML, Dict,
99             Panorama, Ozi, MICoordSys, ERM, Url.
100              
101             =head2 Export
102              
103             $sr->Export($format, @args);
104              
105             Export a SpatialReference object to a format. The list of formats
106             known to GDAL (at the time of this writing) is Wkt, PrettyWkt, Proj4,
107             PCI, USGS, XML, Panorama, MICoordSys, ERM.
108              
109             =head2 Set
110              
111             $sr->Set($proj, @args);
112              
113             Set projection parameters in a SpatialReference object. The list of
114             projection parameters known to GDAL (at the time of this writing) is
115             Axes, ACEA, AE, Bonne, CEA, CS, EC, Eckert, EckertIV, EckertVI,
116             Equirectangular, Equirectangular2, GS, GH, IGH, GEOS,
117             GaussSchreiberTMercator, Gnomonic, HOM, HOMAC, HOM2PNO, IWMPolyconic,
118             Krovak, LAEA, LCC, LCC1SP, LCCB, MC, Mercator, Mercator2SP, Mollweide,
119             NZMG, OS, Orthographic, Polyconic, PS, Robinson, Sinusoidal,
120             Stereographic, SOC, TM, TMVariant, TMG, TMSO, TPED, VDG, Wagner, QSC,
121             SCH.
122              
123             =head1 LICENSE
124              
125             This software is released under the Artistic License. See
126             L.
127              
128             =head1 AUTHOR
129              
130             Ari Jolma - Ari.Jolma at gmail.com
131              
132             =head1 SEE ALSO
133              
134             L
135              
136             L, L, L
137              
138             =cut
139              
140             __END__;