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