FFI/FeatureDefn.pm

filter: Statementstmt 12.7% 13 / 102 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 18.1% 4 / 22 Podpod 47.0% 8 / 17 totaltotal 12.3% 25 / 202 CC 31 SCAR 37.8
CC
31
Cov
8%
new
156.0
GetSchema
20.0
GetFieldDefn
20.0
CRAP 44.0
« FFI/Dataset.pm ↑ Summary FFI/FieldDefn.pm »
1 package Geo::GDAL::FFI::FeatureDefn;
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
7 13 our $VERSION = '0.15';
8
9 sub new {
10 0 ▶ my ($class, $args) = @_;
Subroutine new: not called CC=12 SCAR=50.5
Pod documented
11 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
12 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
13 0 my $self = bless \Geo::GDAL::FFI::OGR_FD_Create($name), $class;
14 0 ▶ if ($args->{Fields}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"Fields"}) 0 0 0
15 0 for my $field (@{$args->{Fields}}) {
16 0 $self->AddField(Geo::GDAL::FFI::FieldDefn->new($field));
17 }
18 }
19 0 ▶ if ($args->{GeometryFields}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'GeometryFields'}) { } 0 0 0
20 0 my $first = 1;
21 0 for my $field (@{$args->{GeometryFields}}) {
22 0 ▶ if ($first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first) { } 0 0 0
23 0 my $d = bless \Geo::GDAL::FFI::OGR_FD_GetGeomFieldDefn($$self, 0),
24 'Geo::GDAL::FFI::GeomFieldDefn';
25 0 ▶ $d->SetName($field->{Name}) if defined $field->{Name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $field->{"Name"} 0 0 0
26 0 $self->SetGeomType($field->{Type});
27 0 ▶ $d->SetSpatialRef($field->{SpatialReference}) if $field->{SpatialReference};
Branch: 1 branch
BranchTrueFalseTotal
if $field->{"SpatialReference"} 0 0 0
28 0 ▶ $d->SetNullable(0) if $field->{NotNullable};
Branch: 1 branch
BranchTrueFalseTotal
if $field->{"NotNullable"} 0 0 0
29 0 $first = 0;
30 } else {
31 0 $self->AddGeomField(Geo::GDAL::FFI::GeomFieldDefn->new($field));
32 }
33 }
34 } else {
35 0 $self->SetGeomType($args->{GeometryType});
36 }
37 0 ▶ $self->SetStyleIgnored if $args->{StyleIgnored};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"StyleIgnored"} 0 0 0
38 0 return $self;
39 }
40
41 sub DESTROY {
42 0 ▶ my $self = shift;
Subroutine DESTROY: not called CC=1 SCAR=6.9
43 #Geo::GDAL::FFI::OGR_FD_Release($$self);
44 }
45
46 sub GetSchema {
47 0 ▶ my $self = shift;
Subroutine GetSchema: not called CC=4 SCAR=30.0
Pod documented
48 0 my $schema = {Name => $self->GetName};
49 0 ▶ for (my $i = 0; $i < Geo::GDAL::FFI::OGR_FD_GetFieldCount($$self); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < Geo::GDAL::FFI::OGR_FD_GetFieldCount($$self)) 0 0 0
50 0 push @{$schema->{Fields}}, $self->GetFieldDefn($i)->GetSchema;
51 }
52 0 ▶ for (my $i = 0; $i < Geo::GDAL::FFI::OGR_FD_GetGeomFieldCount($$self); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < Geo::GDAL::FFI::OGR_FD_GetGeomFieldCount($$self)) 0 0 0
53 0 push @{$schema->{GeometryFields}}, $self->GetGeomFieldDefn($i)->GetSchema;
54 }
55 0 ▶ $schema->{StyleIgnored} = 1 if $self->IsStyleIgnored;
Branch: 1 branch
BranchTrueFalseTotal
if $self->IsStyleIgnored 0 0 0
56 0 return $schema;
57 }
58
59 sub GetName {
60 0 ▶ my ($self) = @_;
Subroutine GetName: not called CC=1 SCAR=6.9
Pod undocumented
61 0 return Geo::GDAL::FFI::OGR_FD_GetName($$self);
62 }
63
64 sub GetFieldDefn {
65 0 ▶ my ($self, $fname) = @_;
Subroutine GetFieldDefn: not called CC=4 SCAR=30.0
Pod documented
66 0 ▶ my $i = $fname // 0;
Condition0%0/2
$fname // 0
l!l
00
MC/DC0%0/1
$fname // 0
$fname
Truth table0%0/2
A
A= $fname
Aresult
11
00
67 0 ▶ $i = Geo::GDAL::FFI::OGR_FD_GetFieldIndex($$self, $i) unless Geo::GDAL::FFI::isint($i);
Branch: 1 branch
BranchTrueFalseTotal
unless Geo::GDAL::FFI::isint($i) 0 0 0
68 0 my $d = Geo::GDAL::FFI::OGR_FD_GetFieldDefn($$self, $i);
69 0 ▶ confess "No such field: $fname." unless $d;
Branch: 1 branch
BranchTrueFalseTotal
unless $d 0 0 0
70 0 ++$Geo::GDAL::FFI::immutable{$d};
71 0 return bless \$d, 'Geo::GDAL::FFI::FieldDefn';
72 }
73
74 sub GetFieldDefns {
75 0 ▶ my $self = shift;
Subroutine GetFieldDefns: not called CC=2 SCAR=17.9
Pod documented
76 0 my @retval;
77 0 for my $i (0..Geo::GDAL::FFI::OGR_FD_GetFieldCount($$self)-1) {
78 0 push @retval, $self->GetFieldDefn($i);
79 }
80 0 return @retval;
81 }
82
83 sub GetGeomFieldDefn {
84 0 ▶ my ($self, $fname) = @_;
Subroutine GetGeomFieldDefn: not called CC=4 SCAR=30.0
Pod documented
85 0 ▶ my $i = $fname // 0;
Condition0%0/2
$fname // 0
l!l
00
MC/DC0%0/1
$fname // 0
$fname
Truth table0%0/2
A
A= $fname
Aresult
11
00
86 0 ▶ $i = Geo::GDAL::FFI::OGR_FD_GetGeomFieldIndex($$self, $i) unless Geo::GDAL::FFI::isint($i);
Branch: 1 branch
BranchTrueFalseTotal
unless Geo::GDAL::FFI::isint($i) 0 0 0
87 0 my $d = Geo::GDAL::FFI::OGR_FD_GetGeomFieldDefn($$self, $i);
88 0 ▶ confess "No such field: $fname." unless $d;
Branch: 1 branch
BranchTrueFalseTotal
unless $d 0 0 0
89 0 ++$Geo::GDAL::FFI::immutable{$d};
90 0 return bless \$d, 'Geo::GDAL::FFI::GeomFieldDefn';
91 }
92
93 sub GetGeomFieldDefns {
94 0 ▶ my $self = shift;
Subroutine GetGeomFieldDefns: not called CC=2 SCAR=17.9
Pod documented
95 0 my @retval;
96 0 for my $i (0..Geo::GDAL::FFI::OGR_FD_GetGeomFieldCount($$self)-1) {
97 0 push @retval, $self->GetGeomFieldDefn($i);
98 }
99 0 return @retval;
100 }
101
102 sub AddFieldDefn {
103 0 ▶ my ($self, $d) = @_;
Subroutine AddFieldDefn: not called CC=1 SCAR=6.9
Pod undocumented
104 0 Geo::GDAL::FFI::OGR_FD_AddFieldDefn($$self, $$d);
105 }
106
107 sub AddGeomFieldDefn {
108 0 ▶ my ($self, $d) = @_;
Subroutine AddGeomFieldDefn: not called CC=1 SCAR=6.9
Pod undocumented
109 0 Geo::GDAL::FFI::OGR_FD_AddGeomFieldDefn($$self, $$d);
110 }
111
112 sub DeleteFieldDefn {
113 0 ▶ my ($self, $i) = @_;
Subroutine DeleteFieldDefn: not called CC=3 SCAR=24.8
Pod undocumented
114 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
115 0 ▶ $i = $self->GetFieldIndex($i) unless Geo::GDAL::FFI::isint($i);
Branch: 1 branch
BranchTrueFalseTotal
unless Geo::GDAL::FFI::isint($i) 0 0 0
116 0 Geo::GDAL::FFI::OGR_FD_DeleteFieldDefn($$self, $i);
117 }
118
119 sub DeleteGeomFieldDefn {
120 0 ▶ my ($self, $i) = @_;
Subroutine DeleteGeomFieldDefn: not called CC=3 SCAR=24.8
Pod undocumented
121 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
122 0 ▶ $i = $self->GetGeomFieldIndex($i) unless Geo::GDAL::FFI::isint($i);
Branch: 1 branch
BranchTrueFalseTotal
unless Geo::GDAL::FFI::isint($i) 0 0 0
123 0 Geo::GDAL::FFI::OGR_FD_DeleteGeomFieldDefn($$self, $i);
124 }
125
126 sub GetGeomType {
127 0 ▶ my ($self) = @_;
Subroutine GetGeomType: not called CC=1 SCAR=6.9
Pod undocumented
128 0 return $Geo::GDAL::FFI::geometry_types_reverse{Geo::GDAL::FFI::OGR_FD_GetGeomType($$self)};
129 }
130
131 sub SetGeomType {
132 0 ▶ my ($self, $type) = @_;
Subroutine SetGeomType: not called CC=3 SCAR=24.8
Pod undocumented
133 0 ▶ $type //= 'Unknown';
Condition0%0/2
$type //= "Unknown"
l!l
00
MC/DC0%0/1
$type //= "Unknown"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
134 0 my $tmp = $Geo::GDAL::FFI::geometry_types{$type};
135 0 ▶ confess "Unknown geometry type: $type." unless defined $tmp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tmp 0 0 0
136 0 Geo::GDAL::FFI::OGR_FD_SetGeomType($$self, $tmp);
137 }
138
139 sub IsGeometryIgnored {
140 0 ▶ my ($self) = @_;
Subroutine IsGeometryIgnored: not called CC=1 SCAR=6.9
Pod documented
141 0 Geo::GDAL::FFI::OGR_FD_IsGeometryIgnored($$self);
142 }
143
144 sub SetGeometryIgnored {
145 0 ▶ my ($self, $i) = @_;
Subroutine SetGeometryIgnored: not called CC=2 SCAR=17.9
Pod documented
146 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
147 0 Geo::GDAL::FFI::OGR_FD_SetGeometryIgnored($$self, $i);
148 }
149
150 sub IsStyleIgnored {
151 0 ▶ my ($self) = @_;
Subroutine IsStyleIgnored: not called CC=1 SCAR=6.9
Pod undocumented
152 0 Geo::GDAL::FFI::OGR_FD_IsStyleIgnored($$self);
153 }
154
155 sub SetStyleIgnored {
156 0 ▶ my ($self, $i) = @_;
Subroutine SetStyleIgnored: not called CC=2 SCAR=17.9
Pod undocumented
157 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
158 0 Geo::GDAL::FFI::OGR_FD_SetStyleIgnored($$self, $i);
159 }
160
161 13 1;
162
163 =pod
164
165 =encoding UTF-8
166
167 =head1 NAME
168
169 Geo::GDAL::FFI::FeatureDefn - A GDAL feature schema
170
171 =head1 SYNOPSIS
172
173 =head1 DESCRIPTION
174
175 =head1 METHODS
176
177 =head2 new
178
179 $defn = Geo::GDAL::FFI::FeatureDefn->new({Fields => [...], GeometryType => 'Point'});
180
181 Create a new FeatureDefn object.
182
183 The named arguments (optional) are the following.
184
185 =over 4
186
187 =item C<Name>
188
189 Optional; the name for this feature class; default is the empty
190 string.
191
192 =item C<Fields>
193
194 Optional, a reference to an array of FieldDefn objects or schemas.
195
196 =item C<GeometryFields>
197
198 Optional, a reference to an array of GeomFieldDefn objects or schemas.
199
200 =item C<GeometryType>
201
202 Optional, the type for the first geometry field; default is
203 Unknown. Note that this argument is ignored if GeometryFields is
204 given.
205
206 =item C<StyleIgnored>
207
208 =back
209
210 =head2 GetSchema
211
212 Returns the definition as a perl data structure.
213
214 =head2 GetFieldDefn
215
216 my $field_defn = $defn->GetFieldDefn($name);
217
218 Get the specified non spatial field object. If the argument is
219 explicitly an integer and not a string, it is taken as the field
220 index.
221
222 =head2 GetFieldDefns
223
224 my @field_defns = $defn->GetFieldDefns;
225
226 =head2 GetGeomFieldDefn
227
228 my $geom_field_defn = $defn->GetGeomFieldDefn($name);
229
230 Get the specified spatial field object. If the argument is explicitly
231 an integer and not a string, it is taken as the field index.
232
233 =head2 GetGeomFieldDefns
234
235 my @geom_field_defns = $defn->GetGeomFieldDefns;
236
237 =head2 SetGeometryIgnored
238
239 $defn->SetGeometryIgnored($arg);
240
241 Ignore the first geometry field when reading features from a layer. To
242 not ignore the first geometry field call this method with defined but
243 false (0) argument.
244
245 =head2 IsGeometryIgnored
246
247 my $is = $defn->IsGeometryIgnored;
248
249 Is the first geometry field ignored when reading features from a
250 layer.
251
252 =head1 LICENSE
253
254 This software is released under the Artistic License. See
255 L<perlartistic>.
256
257 =head1 AUTHOR
258
259 Ari Jolma - Ari.Jolma at gmail.com
260
261 =head1 SEE ALSO
262
263 L<Geo::GDAL::FFI>
264
265 L<Alien::gdal>, L<FFI::Platypus>, L<http://www.gdal.org>
266
267 =cut
268
269 __END__;
« FFI/Dataset.pm ↑ Summary FFI/FieldDefn.pm »