File Coverage

blib/lib/Geo/GDAL/FFI/GeomFieldDefn.pm
Criterion Covered Total %
statement 52 65 80.0
branch 10 28 35.7
condition 10 14 71.4
subroutine 14 17 82.3
pod 2 12 16.6
total 88 136 64.7


line stmt bran cond sub pod time code
1             package Geo::GDAL::FFI::GeomFieldDefn;
2 5     5   63 use v5.10;
  5         16  
3 5     5   26 use strict;
  5         9  
  5         97  
4 5     5   21 use warnings;
  5         10  
  5         179  
5 5     5   29 use Carp;
  5         9  
  5         4424  
6              
7             our $VERSION = 0.0900;
8              
9             sub new {
10 4     4 0 18 my ($class, $args) = @_;
11 4   50     14 $args //= {};
12 4   50     11 my $name = $args->{Name} // 'Unnamed';
13 4   100     17 my $type = $args->{Type} // 'Point';
14 4         12 my $tmp = $Geo::GDAL::FFI::geometry_types{$type};
15 4 50       11 confess "Unknown geometry type: $type." unless defined $tmp;
16 4         39 my $self = bless \Geo::GDAL::FFI::OGR_GFld_Create($name, $tmp), $class;
17 4 50       14 $self->SetSpatialRef($args->{SpatialReference}) if $args->{SpatialReference};
18 4 50       13 $self->SetNullable(0) if $args->{NotNullable};
19 4         21 return $self;
20             }
21              
22             sub DESTROY {
23 11     11   330 my $self = shift;
24 11 100       33 if ($Geo::GDAL::FFI::immutable{$$self}) {
25 7         10 $Geo::GDAL::FFI::immutable{$$self}--;
26 7 50       46 delete $Geo::GDAL::FFI::immutable{$$self} if $Geo::GDAL::FFI::immutable{$$self} == 0;
27             } else {
28 4         33 Geo::GDAL::FFI::OGR_GFld_Destroy($$self);
29             }
30             }
31              
32             sub GetSchema {
33 0     0 0 0 my $self = shift;
34 0         0 my $schema = {
35             Name => $self->GetName,
36             Type => $self->GetType
37             };
38 0 0       0 if (my $sr = $self->GetSpatialRef) {
39 0         0 $schema->{SpatialReference} = $sr->Export('Wkt');
40             }
41 0 0       0 $schema->{NotNullable} = 1 unless $self->IsNullable;
42 0         0 return $schema;
43             }
44              
45             sub SetName {
46 1     1 0 4 my ($self, $name) = @_;
47 1 50       6 confess "Can't modify an immutable object." if $Geo::GDAL::FFI::immutable{$$self};
48 1   50     4 $name //= '';
49 1         12 Geo::GDAL::FFI::OGR_GFld_SetName($$self, $name);
50             }
51              
52             sub GetName {
53 2     2 0 14 my ($self) = @_;
54 2         27 return Geo::GDAL::FFI::OGR_GFld_GetNameRef($$self);
55             }
56              
57             sub SetType {
58 1     1 0 7 my ($self, $type) = @_;
59 1 50       6 confess "Can't modify an immutable object." if $Geo::GDAL::FFI::immutable{$$self};
60 1   50     5 $type //= 'Point';
61 1         5 my $tmp = $Geo::GDAL::FFI::geometry_types{$type};
62 1 50       3 confess "Unknown geometry type: $type." unless defined $tmp;
63 1         4 $type = $tmp;
64 1         8 Geo::GDAL::FFI::OGR_GFld_SetType($$self, $type);
65             }
66              
67             sub GetType {
68 2     2 0 7 my ($self) = @_;
69 2         23 return $Geo::GDAL::FFI::geometry_types_reverse{Geo::GDAL::FFI::OGR_GFld_GetType($$self)};
70             }
71              
72             sub SetSpatialRef {
73 0     0 0 0 my ($self, $sr) = @_;
74 0 0       0 confess "Can't modify an immutable object." if $Geo::GDAL::FFI::immutable{$$self};
75 0 0       0 $sr = Geo::GDAL::FFI::SpatialReference->new($sr) unless ref $sr;
76 0         0 Geo::GDAL::FFI::OGR_GFld_SetSpatialRef($$self, $$sr);
77             }
78              
79             sub GetSpatialRef {
80 0     0 0 0 my ($self) = @_;
81 0         0 my $sr = Geo::GDAL::FFI::OGR_GFld_GetSpatialRef($$self);
82 0 0       0 return bless \$sr, 'Geo::GDAL::FFI::SpatialReference' if $sr;
83             }
84              
85             sub SetIgnored {
86 2     2 1 10 my ($self, $ignored) = @_;
87             #confess "Can't modify an immutable object." if $Geo::GDAL::FFI::immutable{$$self};
88 2   100     10 $ignored //= 1;
89 2         15 Geo::GDAL::FFI::OGR_GFld_SetIgnored($$self, $ignored);
90             }
91              
92             sub IsIgnored {
93 2     2 1 7 my ($self) = @_;
94 2         14 return Geo::GDAL::FFI::OGR_GFld_IsIgnored($$self);
95             }
96              
97             sub SetNullable {
98 2     2 0 6 my ($self, $nullable) = @_;
99 2 50       9 confess "Can't modify an immutable object." if $Geo::GDAL::FFI::immutable{$$self};
100 2   100     10 $nullable //= 0;
101 2         17 Geo::GDAL::FFI::OGR_GFld_SetNullable($$self, $nullable);
102             }
103              
104             sub IsNullable {
105 2     2 0 6 my ($self) = @_;
106 2         14 return Geo::GDAL::FFI::OGR_GFld_IsNullable($$self);
107             }
108              
109             1;
110              
111             =pod
112              
113             =encoding UTF-8
114              
115             =head1 NAME
116              
117             Geo::GDAL::FFI::GeomFieldDefn - A spatial field in a GDAL feature schema
118              
119             =head1 SYNOPSIS
120              
121             =head1 DESCRIPTION
122              
123             There should not usually be any reason to directly access this method
124             except for the ignore methods. This object is created/read from/to the
125             Perl data structure in the CreateLayer method of a dataset, or in the
126             constructor or schema method of FeatureDefn.
127              
128             The schema of a GeomFieldDefn is (Name, Type, SpatialReference,
129             NotNullable).
130              
131             =head1 METHODS
132              
133             =head2 SetIgnored
134              
135             $defn->SetIgnored($arg);
136              
137             Ignore this field when reading features from a layer. To not ignore
138             this field call this method with defined but false (0) argument.
139              
140             =head2 IsIgnored
141              
142             Is this field ignored when reading features from a layer.
143              
144             =head1 LICENSE
145              
146             This software is released under the Artistic License. See
147             L.
148              
149             =head1 AUTHOR
150              
151             Ari Jolma - Ari.Jolma at gmail.com
152              
153             =head1 SEE ALSO
154              
155             L
156              
157             L, L, L
158              
159             =cut
160              
161             __END__;