FFI/Dataset.pm

filter: Statementstmt 8.8% 25 / 282 Branchbran 0.0% 0 / 100 Conditioncond 0.0% 0 / 71 MC/DCmcdc 0.0% 0 / 40 Subroutinesub 16.6% 7 / 42 Podpod 66.6% 22 / 33 totaltotal 9.5% 54 / 568 CC 90 SCAR 39.8
CC
90
Cov
6%
CreateLayer
240.0
Warp
72.0
VectorTranslate
56.0
CRAP 53.6
« FFI/Band.pm ↑ Summary FFI/FeatureDefn.pm »
1 package Geo::GDAL::FFI::Dataset;
2 13 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use base 'Geo::GDAL::FFI::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use Scalar::Util qw /blessed looks_like_number/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 13 our $VERSION = '0.15';
10
11 sub DESTROY {
12 0 ▶ my $self = shift;
Subroutine DESTROY: not called CC=1 SCAR=6.9
13 0 $self->FlushCache;
14 #say STDERR "DESTROY $self";
15 0 Geo::GDAL::FFI::GDALClose($$self);
16 }
17
18 sub GetName {
19 0 ▶ my $self = shift;
Subroutine GetName: not called CC=1 SCAR=6.9
Pod undocumented
20 0 return $self->GetDescription;
21 }
22
23 sub FlushCache {
24 0 ▶ my $self = shift;
Subroutine FlushCache: not called CC=1 SCAR=6.9
Pod undocumented
25 0 Geo::GDAL::FFI::GDALFlushCache($$self);
26 }
27
28 sub GetDriver {
29 0 ▶ my $self = shift;
Subroutine GetDriver: not called CC=1 SCAR=6.9
Pod documented
30 0 my $dr = Geo::GDAL::FFI::GDALGetDatasetDriver($$self);
31 0 return bless \$dr, 'Geo::GDAL::FFI::Driver';
32 }
33
34 sub GetWidth {
35 0 ▶ my $self = shift;
Subroutine GetWidth: not called CC=1 SCAR=6.9
Pod documented
36 0 return Geo::GDAL::FFI::GDALGetRasterXSize($$self);
37 }
38
39 sub GetHeight {
40 0 ▶ my $self = shift;
Subroutine GetHeight: not called CC=1 SCAR=6.9
Pod documented
41 0 return Geo::GDAL::FFI::GDALGetRasterYSize($$self);
42 }
43
44 sub GetSize {
45 0 ▶ my $self = shift;
Subroutine GetSize: not called CC=1 SCAR=6.9
Pod documented
46 return (
47 0 Geo::GDAL::FFI::GDALGetRasterXSize($$self),
48 Geo::GDAL::FFI::GDALGetRasterYSize($$self)
49 );
50 }
51
52 sub GetProjectionString {
53 0 ▶ my ($self) = @_;
Subroutine GetProjectionString: not called CC=1 SCAR=6.9
Pod undocumented
54 0 return Geo::GDAL::FFI::GDALGetProjectionRef($$self);
55 }
56
57 sub SetProjectionString {
58 0 ▶ my ($self, $proj) = @_;
Subroutine SetProjectionString: not called CC=2 SCAR=17.9
Pod undocumented
59 0 my $e = Geo::GDAL::FFI::GDALSetProjection($$self, $proj);
60 0 ▶ if ($e != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e != 0) 0 0 0
61 0 confess Geo::GDAL::FFI::error_msg();
62 }
63 }
64
65 sub GetGeoTransform {
66 0 ▶ my ($self) = @_;
Subroutine GetGeoTransform: not called CC=2 SCAR=17.9
Pod undocumented
67 0 my $t = [0,0,0,0,0,0];
68 0 Geo::GDAL::FFI::GDALGetGeoTransform($$self, $t);
69 0 ▶ return wantarray ? @$t : $t;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
70 }
71
72 sub SetGeoTransform {
73 0 ▶ my $self = shift;
Subroutine SetGeoTransform: not called CC=2 SCAR=17.9
Pod undocumented
74 0 ▶ my $t = @_ > 1 ? [@_] : shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 0 0
75 0 Geo::GDAL::FFI::GDALSetGeoTransform($$self, $t);
76 }
77
78 sub GetBand {
79 0 ▶ my ($self, $i) = @_;
Subroutine GetBand: not called CC=2 SCAR=17.9
Pod documented
80 0 ▶ $i //= 1;
Condition0%0/2
$i //= 1
l!l
00
MC/DC0%0/1
$i //= 1
$i
Truth table0%0/2
A
A= $i
Aresult
11
00
81 0 my $b = Geo::GDAL::FFI::GDALGetRasterBand($$self, $i);
82 0 Geo::GDAL::FFI::_register_parent_ref ($b, $self);
83 0 return bless \$b, 'Geo::GDAL::FFI::Band';
84 }
85
86 sub GetBands {
87 0 ▶ my $self = shift;
Subroutine GetBands: not called CC=2 SCAR=17.9
Pod documented
88 0 my @bands;
89 0 for my $i (1..Geo::GDAL::FFI::GDALGetRasterCount($$self)) {
90 0 push @bands, $self->GetBand($i);
91 }
92 0 return @bands;
93 }
94
95 sub GetLayerCount {
96 0 ▶ my ($self) = @_;
Subroutine GetLayerCount: not called CC=1 SCAR=6.9
Pod documented
97 0 return Geo::GDAL::FFI::GDALDatasetGetLayerCount($$self);
98 }
99
100 sub GetLayerNames {
101 0 ▶ my ($self) = @_;
Subroutine GetLayerNames: not called CC=3 SCAR=24.8
Pod documented
102
103 0 my @layernames;
104 0 for my $i (0 .. $self->GetLayerCount - 1) {
105 0 push @layernames, $self->GetLayerByIndex($i)->GetName;
106 }
107 0 ▶ return wantarray ? @layernames : \@layernames;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
108 }
109
110 sub GetLayerByName {
111 0 ▶ my ($self, $name) = @_;
Subroutine GetLayerByName: not called CC=5 SCAR=34.0
Pod documented
112 0 ▶ confess "Name arg is undefined" if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
113 0 my $layer = Geo::GDAL::FFI::GDALDatasetGetLayerByName($$self, $name);
114 0 ▶ if (!$layer) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($layer) 0 0 0
115 0 ▶ my $msg = Geo::GDAL::FFI::error_msg()
Condition0%0/2
Geo::GDAL::FFI::error_msg() // "Could not access layer $name in data set."
l!l
00
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "Could not access layer $name in data set."
Geo::GDAL::FFI::error_msg()
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
Aresult
11
00
116 // "Could not access layer $name in data set.";
117 0 ▶ confess $msg if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 0 0
118 }
119 0 Geo::GDAL::FFI::_register_parent_ref ($layer, $self);
120 0 return bless \$layer, 'Geo::GDAL::FFI::Layer';
121 }
122
123 sub GetLayerByIndex {
124 0 ▶ my ($self, $index) = @_;
Subroutine GetLayerByIndex: not called CC=6 SCAR=37.4
Pod documented
125 0 ▶ $index //= 0;
Condition0%0/2
$index //= 0
l!l
00
MC/DC0%0/1
$index //= 0
$index
Truth table0%0/2
A
A= $index
Aresult
11
00
126 0 ▶ croak "Index $index is not numeric" if !looks_like_number $index;
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($index) 0 0 0
127 0 my $layer = Geo::GDAL::FFI::GDALDatasetGetLayer($$self, int $index);
128 0 ▶ if (!$layer) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($layer) 0 0 0
129 0 ▶ my $msg = Geo::GDAL::FFI::error_msg()
Condition0%0/2
Geo::GDAL::FFI::error_msg() // "Could not access layer $index in data set."
l!l
00
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "Could not access layer $index in data set."
Geo::GDAL::FFI::error_msg()
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
Aresult
11
00
130 // "Could not access layer $index in data set.";
131 0 ▶ confess $msg if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 0 0
132 }
133 0 Geo::GDAL::FFI::_register_parent_ref ($layer, $self);
134 0 return bless \$layer, 'Geo::GDAL::FFI::Layer';
135 }
136
137
138 sub GetLayer {
139 0 ▶ my ($self, $i) = @_;
Subroutine GetLayer: not called CC=6 SCAR=37.4
Pod documented
140 0 ▶ $i //= 0;
Condition0%0/2
$i //= 0
l!l
00
MC/DC0%0/1
$i //= 0
$i
Truth table0%0/2
A
A= $i
Aresult
11
00
141 0 ▶ my $l = Geo::GDAL::FFI::isint($i)
Branch: 1 branch
BranchTrueFalseTotal
Geo::GDAL::FFI::isint($i) ? : 0 0 0
142 ? Geo::GDAL::FFI::GDALDatasetGetLayer($$self, $i)
143 : Geo::GDAL::FFI::GDALDatasetGetLayerByName($$self, $i);
144 0 ▶ unless ($l) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($l) 0 0 0
145 0 ▶ my $msg = Geo::GDAL::FFI::error_msg()
Condition0%0/2
Geo::GDAL::FFI::error_msg() // "Could not access layer $i in data set."
l!l
00
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "Could not access layer $i in data set."
Geo::GDAL::FFI::error_msg()
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
Aresult
11
00
146 // "Could not access layer $i in data set.";
147 0 ▶ confess $msg if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 0 0
148 }
149 0 Geo::GDAL::FFI::_register_parent_ref ($l, $self);
150 0 return bless \$l, 'Geo::GDAL::FFI::Layer';
151 }
152
153 sub CreateLayer {
154 0 ▶ my ($self, $args) = @_;
Subroutine CreateLayer: not called CC=15 SCAR=54.8
Pod documented
155 0 ▶ $args //= {};
Condition0%0/2
$args //= {}
l!l
00
MC/DC0%0/1
$args //= {}
$args
Truth table0%0/2
A
A= $args
Aresult
11
00
156 0 ▶ my $name = $args->{Name} // '';
Condition0%0/2
$args->{"Name"} // ""
l!l
00
MC/DC0%0/1
$args->{"Name"} // ""
$args->{"Name"}
Truth table0%0/2
A
A= $args->{"Name"}
Aresult
11
00
157 0 my ($gt, $sr);
158 0 ▶ if ($args->{GeometryFields}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'GeometryFields'}) { } 0 0 0
159 0 $gt = $Geo::GDAL::FFI::geometry_types{None};
160 } else {
161 0 ▶ $gt = $args->{GeometryType} // 'Unknown';
Condition0%0/2
$args->{"GeometryType"} // "Unknown"
l!l
00
MC/DC0%0/1
$args->{"GeometryType"} // "Unknown"
$args->{"GeometryType"}
Truth table0%0/2
A
A= $args->{"GeometryType"}
Aresult
11
00
162 0 $gt = $Geo::GDAL::FFI::geometry_types{$gt};
163 0 ▶ confess "Unknown geometry type: '$args->{GeometryType}'." unless defined $gt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gt 0 0 0
164 0 ▶ $sr = Geo::GDAL::FFI::OSRClone(${$args->{SpatialReference}}) if $args->{SpatialReference};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"SpatialReference"} 0 0 0
165 }
166 0 my $o = 0;
167 0 ▶ if ($args->{Options}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"Options"}) 0 0 0
168 0 for my $key (keys %{$args->{Options}}) {
169 0 $o = Geo::GDAL::FFI::CSLAddString($o, "$key=$args->{Options}->{$key}");
170 }
171 }
172 0 my $l = Geo::GDAL::FFI::GDALDatasetCreateLayer($$self, $name, $sr, $gt, $o);
173 0 Geo::GDAL::FFI::CSLDestroy($o);
174 0 ▶ Geo::GDAL::FFI::OSRRelease($sr) if $sr;
Branch: 1 branch
BranchTrueFalseTotal
if $sr 0 0 0
175 0 my $msg = Geo::GDAL::FFI::error_msg();
176 0 ▶ confess $msg if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 0 0
177 0 Geo::GDAL::FFI::_register_parent_ref ($l, $self);
178 0 my $layer = bless \$l, 'Geo::GDAL::FFI::Layer';
179 0 ▶ if ($args->{Fields}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"Fields"}) 0 0 0
180 0 for my $f (@{$args->{Fields}}) {
181 0 $layer->CreateField($f);
182 }
183 }
184 0 ▶ if ($args->{GeometryFields}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"GeometryFields"}) 0 0 0
185 0 for my $f (@{$args->{GeometryFields}}) {
186 0 $layer->CreateGeomField($f);
187 }
188 }
189 0 return $layer;
190 }
191
192 sub CopyLayer {
193 0 ▶ my ($self, $layer, $name, $options) = @_;
Subroutine CopyLayer: not called CC=6 SCAR=37.4
Pod documented
194 0 ▶ $name //= '';
Condition0%0/2
$name //= ""
l!l
00
MC/DC0%0/1
$name //= ""
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
195 0 my $o = 0;
196 0 for my $key (keys %$options) {
197 0 $o = Geo::GDAL::FFI::CSLAddString($o, "$key=$options->{$key}");
198 }
199 0 my $l = Geo::GDAL::FFI::GDALDatasetCopyLayer($$self, $$layer, $name, $o);
200 0 Geo::GDAL::FFI::CSLDestroy($o);
201 0 ▶ unless ($l) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($l) 0 0 0
202 0 ▶ my $msg = Geo::GDAL::FFI::error_msg() // "GDALDatasetCopyLayer failed.";
Condition0%0/2
Geo::GDAL::FFI::error_msg() // "GDALDatasetCopyLayer failed."
l!l
00
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "GDALDatasetCopyLayer failed."
Geo::GDAL::FFI::error_msg()
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
Aresult
11
00
203 0 ▶ confess $msg if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 0 0
204 }
205 0 Geo::GDAL::FFI::_register_parent_ref ($l, $self);
206 0 return bless \$l, 'Geo::GDAL::FFI::Layer';
207 }
208
209
210 sub ExecuteSQL {
211 0 ▶ my ($self, $sql, $filter, $dialect) = @_;
Subroutine ExecuteSQL: not called CC=3 SCAR=24.8
Pod documented
212
213 0 my $lyr = Geo::GDAL::FFI::GDALDatasetExecuteSQL(
214 $$self, $sql, $$filter, $dialect
215 );
216
217 0 ▶ if ($lyr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lyr) 0 0 0
218 0 ▶ if (defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) { } 0 0 0
219 0 Geo::GDAL::FFI::_register_parent_ref ($lyr, $self);
220 0 return bless \$lyr, 'Geo::GDAL::FFI::Layer::ResultSet';
221 }
222 else {
223 0 Geo::GDAL::FFI::GDALDatasetReleaseResultSet ($lyr, $$self);
224 }
225 }
226
227 # This is perhaps unnecessary, but ensures
228 # internal details do not leak if spatial
229 # index is built in non-void context.
230 0 return undef;
231 }
232
233
234 ## utilities
235
236 sub new_options {
237 0 ▶ my ($constructor, $options) = @_;
Subroutine new_options: not called CC=4 SCAR=30.0
Pod undocumented
238 0 ▶ $options //= [];
Condition0%0/2
$options //= []
l!l
00
MC/DC0%0/1
$options //= []
$options
Truth table0%0/2
A
A= $options
Aresult
11
00
239 0 ▶ confess "The options must be a reference to an array." unless ref $options;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $options 0 0 0
240 0 my $csl = 0;
241 0 for my $s (@$options) {
242 0 $csl = Geo::GDAL::FFI::CSLAddString($csl, $s);
243 }
244 0 $options = $constructor->($csl, 0);
245 0 Geo::GDAL::FFI::CSLDestroy($csl);
246 0 return $options;
247 }
248
249 sub GetInfo {
250 0 ▶ my ($self, $options) = @_;
Subroutine GetInfo: not called CC=1 SCAR=6.9
Pod undocumented
251 0 $options = new_options(\&Geo::GDAL::FFI::GDALInfoOptionsNew, $options);
252 0 my $info = Geo::GDAL::FFI::GDALInfo($$self, $options);
253 0 Geo::GDAL::FFI::GDALInfoOptionsFree($options);
254 0 return $info;
255 }
256 13 *Info = *GetInfo;
257
258 sub set_progress {
259 0 ▶ my ($options, $args, $setter) = @_;
Subroutine set_progress: not called CC=2 SCAR=17.9
Pod undocumented
260 0 ▶ return unless $args->{Progress};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"Progress"} 0 0 0
261 0 my $ffi = FFI::Platypus->new;
262 0 $setter->($options, $ffi->closure($args->{Progress}), $args->{ProgressData});
263 }
264
265 sub Translate {
266 0 ▶ my ($self, $path, $options, $progress, $data) = @_;
Subroutine Translate: not called CC=4 SCAR=30.0
Pod documented
267 0 $options = new_options(\&Geo::GDAL::FFI::GDALTranslateOptionsNew, $options);
268 0 my $args = {Progress => $progress, ProgressData => $data};
269 0 set_progress($options, $args, \&Geo::GDAL::FFI::GDALTranslateOptionsSetProgress);
270 0 my $e = 0;
271 0 my $ds = Geo::GDAL::FFI::GDALTranslate($path, $$self, $options, \$e);
272 0 Geo::GDAL::FFI::GDALTranslateOptionsFree($options);
273 0 ▶ return bless \$ds, 'Geo::GDAL::FFI::Dataset' if $ds && ($e == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $ds and $e == 0 0 0 0
Condition0%0/3
$ds and $e == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$ds and $e == 0
$ds $e == 0
Truth table0%0/3
A and B
A= $dsB= $e == 0
ABresult
0X0
100
111
274 0 ▶ my $msg = Geo::GDAL::FFI::error_msg() // 'Translate failed.';
Condition0%0/2
Geo::GDAL::FFI::error_msg() // "Translate failed."
l!l
00
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "Translate failed."
Geo::GDAL::FFI::error_msg()
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
Aresult
11
00
275 0 confess $msg;
276 }
277
278 sub destination {
279 0 ▶ my ($dst) = @_;
Subroutine destination: not called CC=3 SCAR=24.8
Pod undocumented
280 0 ▶ confess "Destination missing." unless $dst;
Branch: 1 branch
BranchTrueFalseTotal
unless $dst 0 0 0
281 0 my $path;
282 0 ▶ if (ref $dst) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dst) { } 0 0 0
283 0 $dst = $$dst;
284 } else {
285 0 $path = $dst;
286 0 undef $dst;
287 }
288 0 return ($path, $dst);
289 }
290
291 sub dataset_input {
292 0 ▶ my ($self, $input) = @_;
Subroutine dataset_input: not called CC=4 SCAR=30.0
Pod undocumented
293 0 ▶ $input //= [];
Condition0%0/2
$input //= []
l!l
00
MC/DC0%0/1
$input //= []
$input
Truth table0%0/2
A
A= $input
Aresult
11
00
294 0 ▶ confess "The input must be a reference to an array of datasets." unless ref ($input) =~ /ARRAY/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref($input) =~ /ARRAY/ 0 0 0
295 0 my @datasets = ($$self);
296 0 for my $ds (@$input) {
297 0 push @datasets, $$ds;
298 }
299 0 return \@datasets;
300 }
301
302 sub Warp {
303 0 ▶ my ($self, $args) = @_;
Subroutine Warp: not called CC=8 SCAR=42.8
Pod documented
304
305 0 my ($path, $dst) = destination($args->{Destination});
306 0 ▶ confess "Destination object should not be passed for non-void context"
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray and builtin::blessed($dst) 0 0 0
Condition0%0/3
defined wantarray and builtin::blessed($dst)
!ll&&!rl&&r
000
MC/DC0%0/2
defined wantarray and builtin::blessed($dst)
defined wantarray builtin::blessed($dst)
Truth table0%0/3
A and B
A= defined wantarrayB= builtin::blessed($dst)
ABresult
0X0
100
111
307 if defined wantarray && blessed $dst;
308
309 0 my $input = $self->dataset_input($args->{Input});
310
311 0 my $options = new_options(\&Geo::GDAL::FFI::GDALWarpAppOptionsNew, $args->{Options});
312 0 set_progress($options, $args, \&Geo::GDAL::FFI::GDALWarpAppOptionsSetProgress);
313
314 0 my $e = 0;
315 0 my $result;
316 0 ▶ if (blessed($dst)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($dst)) { } 0 0 0
317 0 Geo::GDAL::FFI::GDALWarp($path, $dst, scalar @$input, $input, $options, \$e);
318 } else {
319 0 $result = Geo::GDAL::FFI::GDALWarp($path, undef, scalar @$input, $input, $options, \$e);
320 }
321 0 Geo::GDAL::FFI::GDALWarpAppOptionsFree($options);
322 0 ▶ if (defined $result) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result) 0 0 0
323 0 ▶ confess Geo::GDAL::FFI::error_msg() // 'Warp failed.' if !$result || $e != 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $result or $e != 0 0 0 0
Condition0%0/5
not $result or $e != 0
l!l&&r!l&&!r
000
Geo::GDAL::FFI::error_msg() // "Warp failed."
l!l
00
MC/DC0%0/2
not $result or $e != 0
not $result $e != 0
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "Warp failed."
Geo::GDAL::FFI::error_msg()
Truth table0%0/3
not(A) or B
A= not $resultB= $e != 0
ABresult
1X1
011
000
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
Aresult
11
00
324 0 return bless \$result, 'Geo::GDAL::FFI::Dataset';
325 }
326 }
327
328 sub VectorTranslate {
329 0 ▶ my ($self, $args) = @_;
Subroutine VectorTranslate: not called CC=7 SCAR=40.3
Pod documented
330 0 my ($path, $dst) = destination($args->{Destination});
331 0 ▶ confess "Destination object should not be passed for non-void context"
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray and builtin::blessed($dst) 0 0 0
Condition0%0/3
defined wantarray and builtin::blessed($dst)
!ll&&!rl&&r
000
MC/DC0%0/2
defined wantarray and builtin::blessed($dst)
defined wantarray builtin::blessed($dst)
Truth table0%0/3
A and B
A= defined wantarrayB= builtin::blessed($dst)
ABresult
0X0
100
111
332 if defined wantarray && blessed $dst;
333
334 0 my $input = $self->dataset_input($args->{Input});
335
336 0 my $options = new_options(\&Geo::GDAL::FFI::GDALVectorTranslateOptionsNew, $args->{Options});
337 0 set_progress($options, $args, \&Geo::GDAL::FFI::GDALVectorTranslateOptionsSetProgress);
338
339 0 my $e = 0;
340 0 my $result;
341 0 ▶ if (blessed($dst)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($dst)) { } 0 0 0
342 0 Geo::GDAL::FFI::GDALVectorTranslate(undef, $$dst, scalar @$input, $input, $options, \$e);
343 }
344 else {
345 0 my $result = Geo::GDAL::FFI::GDALVectorTranslate($path, undef, scalar @$input, $input, $options, \$e);
346 }
347 0 Geo::GDAL::FFI::GDALVectorTranslateOptionsFree($options);
348 0 ▶ confess Geo::GDAL::FFI::error_msg() // 'VectorTranslate failed.' if $e != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $e != 0 0 0 0
Condition0%0/2
Geo::GDAL::FFI::error_msg() // "VectorTranslate failed."
l!l
00
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "VectorTranslate failed."
Geo::GDAL::FFI::error_msg()
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
Aresult
11
00
349 0 ▶ if (defined $result) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result) 0 0 0
350 0 return bless \$result, 'Geo::GDAL::FFI::Dataset';
351 }
352 }
353
354 sub DEMProcessing {
355 0 ▶ my ($self, $path, $args) = @_;
Subroutine DEMProcessing: not called CC=5 SCAR=34.0
Pod documented
356 0 ▶ my $processing = $args->{Processing} // 'hillshade';
Condition0%0/2
$args->{"Processing"} // "hillshade"
l!l
00
MC/DC0%0/1
$args->{"Processing"} // "hillshade"
$args->{"Processing"}
Truth table0%0/2
A
A= $args->{"Processing"}
Aresult
11
00
357 0 my $colorfile = $args->{ColorFilename};
358 0 my $options = new_options(\&Geo::GDAL::FFI::GDALDEMProcessingOptionsNew, $args->{Options});
359 0 set_progress($options, $args, \&Geo::GDAL::FFI::GDALDEMProcessingOptionsSetProgress);
360 0 my $e = 0;
361 0 my $result = Geo::GDAL::FFI::GDALDEMProcessing($path, $$self, $processing, $colorfile, $options, \$e);
362 0 Geo::GDAL::FFI::GDALDEMProcessingOptionsFree($options);
363 0 ▶ confess Geo::GDAL::FFI::error_msg() // 'DEMProcessing failed.' if !$result || $e != 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $result or $e != 0 0 0 0
Condition0%0/5
not $result or $e != 0
l!l&&r!l&&!r
000
Geo::GDAL::FFI::error_msg() // "DEMProcessing failed."
l!l
00
MC/DC0%0/2
not $result or $e != 0
not $result $e != 0
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "DEMProcessing failed."
Geo::GDAL::FFI::error_msg()
Truth table0%0/3
not(A) or B
A= not $resultB= $e != 0
ABresult
1X1
011
000
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
Aresult
11
00
364 0 return bless \$result, 'Geo::GDAL::FFI::Dataset';
365 }
366
367 sub NearBlack {
368 0 ▶ my ($self, $args) = @_;
Subroutine NearBlack: not called CC=7 SCAR=40.3
Pod documented
369
370 0 my ($path, $dst) = destination($args->{Destination});
371 0 ▶ confess "Destination object should not be passed for non-void context"
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray and builtin::blessed($dst) 0 0 0
Condition0%0/3
defined wantarray and builtin::blessed($dst)
!ll&&!rl&&r
000
MC/DC0%0/2
defined wantarray and builtin::blessed($dst)
defined wantarray builtin::blessed($dst)
Truth table0%0/3
A and B
A= defined wantarrayB= builtin::blessed($dst)
ABresult
0X0
100
111
372 if defined wantarray && blessed $dst;
373
374 0 my $input = $self->dataset_input($args->{Input});
375
376 0 my $options = new_options(\&Geo::GDAL::FFI::GDALNearblackOptionsNew, $args->{Options});
377 0 set_progress($options, $args, \&Geo::GDAL::FFI::GDALNearblackOptionsSetProgress);
378
379 0 my $e = 0;
380 0 my $result;
381 0 ▶ if (blessed($dst)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($dst)) { } 0 0 0
382 0 Geo::GDAL::FFI::GDALNearblack($path, $$dst, $$self, $options, \$e);
383 } else {
384 0 $result = Geo::GDAL::FFI::GDALNearblack($path, undef, $$self, $options, \$e);
385 }
386 0 Geo::GDAL::FFI::GDALNearblackOptionsFree($options);
387
388 0 ▶ confess Geo::GDAL::FFI::error_msg() // 'NearBlack failed.' if $e != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $e != 0 0 0 0
Condition0%0/2
Geo::GDAL::FFI::error_msg() // "NearBlack failed."
l!l
00
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "NearBlack failed."
Geo::GDAL::FFI::error_msg()
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
Aresult
11
00
389 0 ▶ if (defined $result) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result) 0 0 0
390 0 return bless \$result, 'Geo::GDAL::FFI::Dataset';
391 }
392
393 }
394
395 sub Grid {
396 0 ▶ my ($self, $path, $options, $progress, $data) = @_;
Subroutine Grid: not called CC=4 SCAR=30.0
Pod documented
397 0 $options = new_options(\&Geo::GDAL::FFI::GDALGridOptionsNew, $options);
398 0 my $args = {Progress => $progress, ProgressData => $data};
399 0 set_progress($options, $args, \&Geo::GDAL::FFI::GDALGridOptionsSetProgress);
400 0 my $e = 0;
401 0 my $result = Geo::GDAL::FFI::GDALGrid($path, $$self, $options, \$e);
402 0 Geo::GDAL::FFI::GDALGridOptionsFree($options);
403 0 ▶ confess Geo::GDAL::FFI::error_msg() // 'Grid failed.' if !$result || $e != 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $result or $e != 0 0 0 0
Condition0%0/5
not $result or $e != 0
l!l&&r!l&&!r
000
Geo::GDAL::FFI::error_msg() // "Grid failed."
l!l
00
MC/DC0%0/2
not $result or $e != 0
not $result $e != 0
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "Grid failed."
Geo::GDAL::FFI::error_msg()
Truth table0%0/3
not(A) or B
A= not $resultB= $e != 0
ABresult
1X1
011
000
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
Aresult
11
00
404 0 return bless \$result, 'Geo::GDAL::FFI::Dataset';
405 }
406
407 sub Rasterize {
408 0 ▶ my ($self, $args) = @_;
Subroutine Rasterize: not called CC=7 SCAR=40.3
Pod documented
409
410 0 my $dst = $args->{Destination};
411 0 ▶ confess "Destination argument should not be passed for non-void context"
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray and builtin::blessed($dst) 0 0 0
Condition0%0/3
defined wantarray and builtin::blessed($dst)
!ll&&!rl&&r
000
MC/DC0%0/2
defined wantarray and builtin::blessed($dst)
defined wantarray builtin::blessed($dst)
Truth table0%0/3
A and B
A= defined wantarrayB= builtin::blessed($dst)
ABresult
0X0
100
111
412 if defined wantarray && blessed $dst;
413
414 0 my $options = new_options(\&Geo::GDAL::FFI::GDALRasterizeOptionsNew, $args->{Options});
415 0 set_progress($options, $args, \&Geo::GDAL::FFI::GDALRasterizeOptionsSetProgress);
416
417 0 my $e = 0;
418 0 my $result;
419 0 ▶ if (blessed($dst)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($dst)) { } 0 0 0
420 0 Geo::GDAL::FFI::GDALRasterize(undef, $$dst, $$self, $options, \$e);
421 } else {
422 0 $result = Geo::GDAL::FFI::GDALRasterize($dst, undef, $$self, $options, \$e);
423 }
424 0 Geo::GDAL::FFI::GDALRasterizeOptionsFree($options);
425
426 0 ▶ confess Geo::GDAL::FFI::error_msg() // 'Rasterize failed.' if $e != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $e != 0 0 0 0
Condition0%0/2
Geo::GDAL::FFI::error_msg() // "Rasterize failed."
l!l
00
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "Rasterize failed."
Geo::GDAL::FFI::error_msg()
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
Aresult
11
00
427 0 ▶ if (defined $result) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result) 0 0 0
428 0 return bless \$result, 'Geo::GDAL::FFI::Dataset';
429 }
430 }
431
432 sub BuildVRT {
433 0 ▶ my ($self, $path, $args) = @_;
Subroutine BuildVRT: not called CC=4 SCAR=30.0
Pod documented
434 0 my $input = $self->dataset_input($args->{Input});
435 0 my $options = new_options(\&Geo::GDAL::FFI::GDALBuildVRTOptionsNew, $args->{Options});
436 0 set_progress($options, $args, \&Geo::GDAL::FFI::GDALBuildVRTOptionsSetProgress);
437 0 my $e = 0;
438 0 my $result = Geo::GDAL::FFI::GDALBuildVRT($path, scalar @$input, $input, 0, $options, \$e);
439 0 Geo::GDAL::FFI::GDALBuildVRTOptionsFree($options);
440 0 ▶ confess Geo::GDAL::FFI::error_msg() // 'BuildVRT failed.' if !$result || $e != 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $result or $e != 0 0 0 0
Condition0%0/5
not $result or $e != 0
l!l&&r!l&&!r
000
Geo::GDAL::FFI::error_msg() // "BuildVRT failed."
l!l
00
MC/DC0%0/2
not $result or $e != 0
not $result $e != 0
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "BuildVRT failed."
Geo::GDAL::FFI::error_msg()
Truth table0%0/3
not(A) or B
A= not $resultB= $e != 0
ABresult
1X1
011
000
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
Aresult
11
00
441 0 return bless \$result, 'Geo::GDAL::FFI::Dataset';
442 }
443
444 13 1;
445
446 {
447 # dummy class for result sets from ExecuteSQL
448 # allows specialised destroy method
449 13 package Geo::GDAL::FFI::Layer::ResultSet;
450 13 ▶ use base qw /Geo::GDAL::FFI::Layer/;
Subroutine BEGIN: called CC=1 SCAR=0.0
451
452 sub DESTROY {
453 0 ▶ my ($self) = @_;
Subroutine DESTROY: not called CC=1 SCAR=6.9
454 0 my $parent = Geo::GDAL::FFI::_get_parent_ref ($$self);
455 0 Geo::GDAL::FFI::GDALDatasetReleaseResultSet ($$parent, $$self);
456 0 Geo::GDAL::FFI::_deregister_parent_ref ($$self);
457 }
458
459 13 1;
460 }
461
462
463
464 =pod
465
466 =encoding UTF-8
467
468 =head1 NAME
469
470 Geo::GDAL::FFI::Dataset - A GDAL dataset
471
472 =head1 SYNOPSIS
473
474 =head1 DESCRIPTION
475
476 A collection of raster bands or vector layers. Obtain a dataset object
477 by opening it with the Open method of Geo::GDAL::FFI object or by
478 creating it with the Create method of a Driver object.
479
480 =head1 METHODS
481
482 =head2 GetDriver
483
484 my $driver = $dataset->GetDriver;
485
486 =head2 GetWidth
487
488 my $w = $dataset->GetWidth;
489
490 =head2 GetHeight
491
492 my $h = $dataset->GetHeight;
493
494 =head2 GetSize
495
496 my @size = $dataset->GetSize;
497
498 Returns the size (width, height) of the bands of this raster dataset.
499
500 =head2 GetBand
501
502 my $band = $dataset->GetBand($i);
503
504 Get the ith (by default the first) band of a raster dataset.
505
506 =head2 GetBands
507
508 my @bands = $dataset->GetBands;
509
510 Returns a list of Band objects representing the bands of this raster
511 dataset.
512
513 =head2 CreateLayer
514
515 my $layer = $dataset->CreateLayer({Name => 'layer', ...});
516
517 Create a new vector layer into this vector dataset.
518
519 Named arguments are the following.
520
521 =over 4
522
523 =item C<Name>
524
525 Optional, string, default is ''.
526
527 =item C<GeometryType>
528
529 Optional, default is 'Unknown', the type of the first geometry field;
530 note: if type is 'None', the layer schema does not initially contain
531 any geometry fields.
532
533 =item C<SpatialReference>
534
535 Optional, a SpatialReference object, the spatial reference for the
536 first geometry field.
537
538 =item C<Options>
539
540 Optional, driver specific options in an anonymous hash.
541
542 =item C<Fields>
543
544 Optional, a reference to an array of Field objects or schemas, the
545 fields to create into the layer.
546
547 =item C<GeometryFields>
548
549 Optional, a reference to an array of GeometryField objects or schemas,
550 the geometry fields to create into the layer; note that if this
551 argument is defined then the arguments GeometryType and
552 SpatialReference are ignored.
553
554 =back
555
556 =head2 GetLayerCount
557
558 my $count = $dataset->GetLayerCount();
559
560
561 =head2 GetLayer
562
563 my $layer = $dataset->GetLayer($name);
564
565 If $name is strictly an integer, then returns the (name-1)th layer in
566 the dataset, otherwise returns the layer whose name is $name. Without
567 arguments returns the first layer.
568
569 If there is any risk of ambiguity, e.g. the fourth layer is called "2",
570 then L</GetLayerByName> or L</GetLayerByIndex> can be used.
571
572 =head2 GetLayerByName
573
574 my $layer = $dataset->GetLayerByName($name);
575
576 Returns the layer whose name is C<$name>. Without arguments returns the first layer.
577
578 =head2 GetLayerByIndex
579
580 my $layer = $dataset->GetLayerByIndex($i);
581
582 Returns the ith layer in the dataset. Without arguments returns the first layer.
583 Throws an exception on non-numeric input and integerises any non-integer numbers.
584
585 =head2 GetLayerNames
586
587 my @array = $dataset->GetLayerNames();
588 my $aref = $dataset->GetLayerNames();
589
590 Returns an array of the layer names, in index order.
591 Returns an array ref in scalar context.
592
593
594 =head2 CopyLayer
595
596 my $copy = $dataset->CopyLayer($layer, $name, {DST_SRSWKT => 'WKT of a SRS', ...});
597
598 Copies the given layer into this dataset using the name $name and
599 returns the new layer. The options hash is mostly driver specific.
600
601 =head2 ExecuteSQL
602 $dataset->ExecuteSQL ($sql, $filter, $dialect);
603
604 # build a spatial index
605 $dataset->ExecuteSQL (qq{CREATE SPATIAL INDEX ON "$some_layer_name"});
606
607 # filter a data set using the SQLite dialect and a second geometry
608 my $filtered = $dataset->ExecuteSQL (
609 qq{SELECT "$fld1", "$fld2" FROM "$some_layer_name"},
610 $some_geometry,
611 'SQLite',
612 );
613
614 =head2 Info
615
616 my $info = $dataset->Info($options);
617 my $info = $dataset->Info(['-json', '-stats']);
618
619 This is the same as gdalinfo utility. $options is a reference to an
620 array. Valid options are as per the L<gdalinfo|https://www.gdal.org/gdalinfo.html> utility.
621
622 =head2 Translate
623
624 my $target = $source->Translate($path, $options, $progress, $progress_data);
625
626 Convert a raster dataset into another raster dataset. This is the same
627 as the L<gdal_translate|https://www.gdal.org/gdal_translate.html> utility. $name is the name of the target
628 dataset. $options is a reference to an array of switches.
629
630 =head2 Warp
631
632 my $result = $dataset->Warp($args);
633
634 $args is a hashref, keys may be Destination, Input, Options, Progress,
635 ProgressData.
636
637 Valid options are as per the L<gdalwarp|https://www.gdal.org/gdalwarp.html> utility.
638
639 =head2 VectorTranslate
640
641 my $result = $dataset->VectorTranslate($args);
642
643 $args is a hashref, keys may be Destination, Input, Options, Progress,
644 ProgressData.
645
646 Valid options are as per the L<ogr2ogr|https://www.gdal.org/ogr2ogr.html> utility.
647
648 =head2 DEMProcessing
649
650 my $result = $dataset->DEMProcessing($path, $args);
651
652 $args is a hashref, keys may be Processing, ColorFilename, Options,
653 Progress, ProgressData.
654
655 See also L<gdaldem|https://www.gdal.org/gdaldem.html>.
656
657 =head2 NearBlack
658
659 my $result = $dataset->NearBlack($args);
660
661 $args is a hashref, keys may be Destination, Options, Progress,
662 ProgressData.
663
664 Valid options are as per the L<nearblack|https://www.gdal.org/nearblack.html> utility.
665
666 =head2 Grid
667
668 my $result = $dataset->Grid($path, $options, $progress, $progress_data);
669
670 Valid options are as per the L<gdal_grid|https://www.gdal.org/gdal_grid.html> utility.
671
672 =head2 Rasterize
673
674 my $result = $dataset->Rasterize($args);
675 my $result = $dataset->Rasterize({Options => [-b => 1, -at]});
676
677 $args is a hashref, keys may be Destination, Options, Progress,
678 ProgressData.
679
680 Valid options are as per the L<gdal_rasterize|https://www.gdal.org/gdal_rasterize.html> utility.
681
682 =head2 BuildVRT
683
684 my $result = $dataset->BuildVRT($path, $args);
685
686 $args is a hashref, keys may be Input, Options, Progress,
687 ProgressData.
688
689 =head1 LICENSE
690
691 This software is released under the Artistic License. See
692 L<perlartistic>.
693
694 =head1 AUTHOR
695
696 Ari Jolma - Ari.Jolma at gmail.com
697
698 =head1 SEE ALSO
699
700 L<Geo::GDAL::FFI>
701
702 L<Alien::gdal>, L<FFI::Platypus>, L<http://www.gdal.org>
703
704 =cut
705
706 __END__;
« FFI/Band.pm ↑ Summary FFI/FeatureDefn.pm »