File Coverage

blib/lib/Geo/GDAL/FFI/SpatialReference.pm
Criterion Covered Total %
statement 23 46 50.0
branch 5 14 35.7
condition n/a
subroutine 6 9 66.6
pod 3 4 75.0
total 37 73 50.6


line stmt bran cond sub pod time code
1             package Geo::GDAL::FFI::SpatialReference;
2 5     5   64 use v5.10;
  5         48  
3 5     5   27 use strict;
  5         12  
  5         125  
4 5     5   26 use warnings;
  5         10  
  5         117  
5 5     5   23 use Carp;
  5         8  
  5         2580  
6              
7             our $VERSION = 0.0900;
8              
9             sub new {
10 1     1 1 18 my ($class, $arg, @arg) = @_;
11 1         3 my $sr;
12 1 50       9 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 1         30 $sr = Geo::GDAL::FFI::OSRNewSpatialReference();
18 1         9 my $gdal = Geo::GDAL::FFI->get_instance;
19 1         6 $arg = $gdal->get_importer($arg);
20 1 50       18917 if ($arg->($sr, @arg) != 0) {
21 0         0 Geo::GDAL::FFI::OSRDestroySpatialReference($sr);
22 0         0 $sr = 0;
23             }
24             }
25 1 50       15 return bless \$sr, $class if $sr;
26 0         0 confess Geo::GDAL::FFI::error_msg();
27             }
28              
29             sub DESTROY {
30 1     1   6 my $self = shift;
31             # OSRGetReferenceCount method not yet implemented
32 1         8 my $refcount = (Geo::GDAL::FFI::OSRReference ($$self)-1);
33 1         6 Geo::GDAL::FFI::OSRDereference ($$self); # immediately decrement
34 1 50       8 if ($refcount == 0) {
35             #warn "Calling DESTROY method for $$self\n";
36 0           Geo::GDAL::FFI::OSRDestroySpatialReference($$self);
37             }
38             }
39              
40             sub Export {
41 0     0 1   my $self = shift;
42 0           my $format = shift;
43 0           my $gdal = Geo::GDAL::FFI->get_instance;
44 0           my $exporter = $gdal->get_exporter($format);
45 0           my $x;
46 0 0         if ($exporter->($$self, \$x, @_) != 0) {
47 0           confess Geo::GDAL::FFI::error_msg();
48             }
49 0           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__;