| 1 | package Geo::GDAL::FFI::Layer; | ||||||||||||||
| 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 | |||||||||||||||
| 8 | 13 | our $VERSION = '0.15'; | |||||||||||||
| 9 | |||||||||||||||
| 10 | sub DESTROY { | ||||||||||||||
| 11 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||
| 12 | 0 | Geo::GDAL::FFI::OGR_L_SyncToDisk($$self); | |||||||||||||
| 13 | #say STDERR "delete parent $parent{$$self}"; | ||||||||||||||
| 14 | 0 | Geo::GDAL::FFI::_deregister_parent_ref ($$self); | |||||||||||||
| 15 | #say STDERR "destroy $self"; | ||||||||||||||
| 16 | } | ||||||||||||||
| 17 | |||||||||||||||
| 18 | sub GetParentDataset { | ||||||||||||||
| 19 | 0 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
GetParentDataset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 20 | 0 | return Geo::GDAL::FFI::_get_parent_ref ($$self); | |||||||||||||
| 21 | } | ||||||||||||||
| 22 | |||||||||||||||
| 23 | sub GetDefn { | ||||||||||||||
| 24 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
GetDefn: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 25 | 0 | my $d = Geo::GDAL::FFI::OGR_L_GetLayerDefn($$self); | |||||||||||||
| 26 | 0 | return bless \$d, 'Geo::GDAL::FFI::FeatureDefn'; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | sub CreateField { | ||||||||||||||
| 30 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
CreateField: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 31 | 0 | my $def = shift; | |||||||||||||
| 32 | 0 | ▶ | unless (ref $def) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 33 | # name => type calling syntax | ||||||||||||||
| 34 | 0 | my $name = $def; | |||||||||||||
| 35 | 0 | my $type = shift; | |||||||||||||
| 36 | 0 | $def = Geo::GDAL::FFI::FieldDefn->new({Name => $name, Type => $type}) | |||||||||||||
| 37 | 0 | } elsif (ref $def eq 'HASH') { | |||||||||||||
| 38 | 0 | $def = Geo::GDAL::FFI::FieldDefn->new($def) | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | 0 | ▶ | my $approx_ok = shift // 1; | ||||||||||||
|
Condition0%0/2
shift() // 1
MC/DC0%0/1
shift() // 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||
| 41 | 0 | my $e = Geo::GDAL::FFI::OGR_L_CreateField($$self, $$def, $approx_ok); | |||||||||||||
| 42 | 0 | ▶ | return unless $e; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | 0 | confess Geo::GDAL::FFI::error_msg({OGRError => $e}); | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | sub CreateGeomField { | ||||||||||||||
| 47 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
CreateGeomField: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 48 | 0 | my $def = shift; | |||||||||||||
| 49 | 0 | ▶ | unless (ref $def) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 50 | # name => type calling syntax | ||||||||||||||
| 51 | 0 | my $name = $def; | |||||||||||||
| 52 | 0 | my $type = shift; | |||||||||||||
| 53 | 0 | $def = Geo::GDAL::FFI::GeomFieldDefn->new({Name => $name, Type => $type}); | |||||||||||||
| 54 | 0 | } elsif (ref $def eq 'HASH') { | |||||||||||||
| 55 | 0 | $def = Geo::GDAL::FFI::GeomFieldDefn->new($def) | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | 0 | ▶ | my $approx_ok = shift // 1; | ||||||||||||
|
Condition0%0/2
shift() // 1
MC/DC0%0/1
shift() // 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||
| 58 | 0 | my $e = Geo::GDAL::FFI::OGR_L_CreateGeomField($$self, $$def, $approx_ok); | |||||||||||||
| 59 | 0 | ▶ | return unless $e; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | 0 | confess Geo::GDAL::FFI::error_msg({OGRError => $e}); | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | |||||||||||||||
| 63 | sub GetSpatialRef { | ||||||||||||||
| 64 | 0 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
GetSpatialRef: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 65 | 0 | my $sr = Geo::GDAL::FFI::OGR_L_GetSpatialRef($$self); | |||||||||||||
| 66 | 0 | ▶ | return unless $sr; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | 0 | return bless \$sr, 'Geo::GDAL::FFI::SpatialReference'; | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | sub ResetReading { | ||||||||||||||
| 71 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
ResetReading: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 72 | 0 | Geo::GDAL::FFI::OGR_L_ResetReading($$self); | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | sub GetNextFeature { | ||||||||||||||
| 76 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
GetNextFeature: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 77 | 0 | my $f = Geo::GDAL::FFI::OGR_L_GetNextFeature($$self); | |||||||||||||
| 78 | 0 | ▶ | return unless $f; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 79 | 0 | return bless \$f, 'Geo::GDAL::FFI::Feature'; | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | |||||||||||||||
| 82 | sub GetFeature { | ||||||||||||||
| 83 | 0 | ▶ | my ($self, $fid) = @_; | ||||||||||||
|
Subroutine
GetFeature: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 84 | 0 | my $f = Geo::GDAL::FFI::OGR_L_GetFeature($$self, $fid); | |||||||||||||
| 85 | 0 | ▶ | confess unless $f; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 86 | 0 | return bless \$f, 'Geo::GDAL::FFI::Feature'; | |||||||||||||
| 87 | } | ||||||||||||||
| 88 | |||||||||||||||
| 89 | sub GetFeatureCount { | ||||||||||||||
| 90 | 0 | ▶ | my ($self, $force) = @_; | ||||||||||||
|
Subroutine
GetFeatureCount: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 91 | 0 | Geo::GDAL::FFI::OGR_L_GetFeatureCount($$self, !!$force); | |||||||||||||
| 92 | } | ||||||||||||||
| 93 | |||||||||||||||
| 94 | sub SetFeature { | ||||||||||||||
| 95 | 0 | ▶ | my ($self, $f) = @_; | ||||||||||||
|
Subroutine
SetFeature: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 96 | 0 | Geo::GDAL::FFI::OGR_L_SetFeature($$self, $$f); | |||||||||||||
| 97 | } | ||||||||||||||
| 98 | |||||||||||||||
| 99 | sub CreateFeature { | ||||||||||||||
| 100 | 0 | ▶ | my ($self, $f) = @_; | ||||||||||||
|
Subroutine
CreateFeature: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 101 | 0 | my $e = Geo::GDAL::FFI::OGR_L_CreateFeature($$self, $$f); | |||||||||||||
| 102 | 0 | ▶ | return $f unless $e; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | sub DeleteFeature { | ||||||||||||||
| 106 | 0 | ▶ | my ($self, $fid) = @_; | ||||||||||||
|
Subroutine
DeleteFeature: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 107 | 0 | my $e = Geo::GDAL::FFI::OGR_L_DeleteFeature($$self, $fid); | |||||||||||||
| 108 | 0 | ▶ | return unless $e; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 109 | 0 | confess Geo::GDAL::FFI::error_msg({OGRError => $e}); | |||||||||||||
| 110 | } | ||||||||||||||
| 111 | |||||||||||||||
| 112 | 13 | __PACKAGE__->_make_overlay_methods(); | |||||||||||||
| 113 | |||||||||||||||
| 114 | sub _make_overlay_methods { | ||||||||||||||
| 115 | 13 | ▶ | my ($pkg) = @_; | ||||||||||||
|
Subroutine
_make_overlay_methods: called CC=2 SCAR=13.3
| |||||||||||||||
| 116 | 13 | my @methods = (qw / | |||||||||||||
| 117 | Intersection Union SymDifference | ||||||||||||||
| 118 | Identity Update Clip Erase | ||||||||||||||
| 119 | /); | ||||||||||||||
| 120 | |||||||||||||||
| 121 | 13 | ▶ | no strict 'refs'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 122 | 13 | foreach my $method_name (@methods) { | |||||||||||||
| 123 | 91 | *{$pkg . '::' . $method_name} = | |||||||||||||
| 124 | sub { | ||||||||||||||
| 125 | 0 | ▶ | my ($self, $method, $args) = @_; | ||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||
| 126 | 0 | ▶ | confess "Method layer missing." unless $method; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 127 | 0 | ▶ | $args //= {}; | ||||||||||||
|
Condition0%0/2
$args //= {}
MC/DC0%0/1
$args //= {}
$args
Truth table0%0/2
A
A= $args
| |||||||||||||||
| 128 | 0 | my $result = $args->{Result}; | |||||||||||||
| 129 | 0 | ▶ | unless ($result) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 130 | 0 | my $schema = { | |||||||||||||
| 131 | GeometryType => 'Unknown' | ||||||||||||||
| 132 | }; | ||||||||||||||
| 133 | 0 | state $mem_driver = Geo::GDAL::FFI::get_memory_driver(); | |||||||||||||
| 134 | 0 | $result = Geo::GDAL::FFI::GetDriver($mem_driver)->Create->CreateLayer($schema); | |||||||||||||
| 135 | } | ||||||||||||||
| 136 | 0 | my $o = 0; | |||||||||||||
| 137 | 0 | for my $key (keys %{$args->{Options}}) { | |||||||||||||
| 138 | 0 | $o = Geo::GDAL::FFI::CSLAddString($o, "$key=$args->{Options}{$key}"); | |||||||||||||
| 139 | } | ||||||||||||||
| 140 | 0 | my $p = 0; | |||||||||||||
| 141 | 0 | ▶ | $p = FFI::Platypus->new->closure($args->{Progress}) if $args->{Progress}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 142 | 0 | my $e = &{'Geo::GDAL::FFI::OGR_L_'.$method_name} ($$self, $$method, $$result, $o, $p, $args->{ProgressData}); | |||||||||||||
| 143 | 0 | Geo::GDAL::FFI::CSLDestroy($o); | |||||||||||||
| 144 | 0 | ▶ | return $result unless $e; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 145 | 0 | confess Geo::GDAL::FFI::error_msg({OGRError => $e}); | |||||||||||||
| 146 | 91 | }; | |||||||||||||
| 147 | } | ||||||||||||||
| 148 | |||||||||||||||
| 149 | 13 | return; | |||||||||||||
| 150 | } | ||||||||||||||
| 151 | |||||||||||||||
| 152 | sub GetExtent { | ||||||||||||||
| 153 | 0 | ▶ | my ($self, $force) = @_; | ||||||||||||
|
Subroutine
GetExtent: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 154 | 0 | my $extent = [0,0,0,0]; | |||||||||||||
| 155 | 0 | ▶ | $force = $force ? \1 : \0; # ensure $force is a ref | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 156 | 0 | my $e = Geo::GDAL::FFI::OGR_L_GetExtent ($$self, $extent, $force); | |||||||||||||
| 157 | 0 | ▶ | return $extent unless $e; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 158 | 0 | confess Geo::GDAL::FFI::error_msg({OGRError => $e}); | |||||||||||||
| 159 | } | ||||||||||||||
| 160 | |||||||||||||||
| 161 | sub GetName { | ||||||||||||||
| 162 | 0 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
GetName: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 163 | 0 | return $self->GetDefn->GetName; | |||||||||||||
| 164 | } | ||||||||||||||
| 165 | |||||||||||||||
| 166 | 13 | 1; | |||||||||||||
| 167 | |||||||||||||||
| 168 | =pod | ||||||||||||||
| 169 | |||||||||||||||
| 170 | =encoding UTF-8 | ||||||||||||||
| 171 | |||||||||||||||
| 172 | =head1 NAME | ||||||||||||||
| 173 | |||||||||||||||
| 174 | Geo::GDAL::FFI::Layer - A collection of vector features in GDAL | ||||||||||||||
| 175 | |||||||||||||||
| 176 | =head1 SYNOPSIS | ||||||||||||||
| 177 | |||||||||||||||
| 178 | =head1 DESCRIPTION | ||||||||||||||
| 179 | |||||||||||||||
| 180 | A set of (vector) features having a same schema (the same Defn | ||||||||||||||
| 181 | object). Obtain a layer object by the CreateLayer or GetLayer method | ||||||||||||||
| 182 | of a vector dataset object. | ||||||||||||||
| 183 | |||||||||||||||
| 184 | Note that the system stores a reference to the parent dataset for | ||||||||||||||
| 185 | each layer object to ensure layer objects remain viable. | ||||||||||||||
| 186 | If you are relying on a dataset object's destruction to | ||||||||||||||
| 187 | flush its dataset cache and then close it then you need to ensure | ||||||||||||||
| 188 | all associated child layers are also destroyed. Failure to do so could | ||||||||||||||
| 189 | lead to corrupt data when reading in newly written files. | ||||||||||||||
| 190 | |||||||||||||||
| 191 | =head1 METHODS | ||||||||||||||
| 192 | |||||||||||||||
| 193 | =head2 GetDefn | ||||||||||||||
| 194 | |||||||||||||||
| 195 | my $defn = $layer->GetDefn; | ||||||||||||||
| 196 | |||||||||||||||
| 197 | Returns the FeatureDefn object for this layer. | ||||||||||||||
| 198 | |||||||||||||||
| 199 | =head2 ResetReading | ||||||||||||||
| 200 | |||||||||||||||
| 201 | $layer->ResetReading; | ||||||||||||||
| 202 | |||||||||||||||
| 203 | =head2 GetNextFeature | ||||||||||||||
| 204 | |||||||||||||||
| 205 | my $feature = $layer->GetNextFeature; | ||||||||||||||
| 206 | |||||||||||||||
| 207 | =head2 GetFeature | ||||||||||||||
| 208 | |||||||||||||||
| 209 | my $feature = $layer->GetFeature($fid); | ||||||||||||||
| 210 | |||||||||||||||
| 211 | =head2 SetFeature | ||||||||||||||
| 212 | |||||||||||||||
| 213 | $layer->SetFeature($feature); | ||||||||||||||
| 214 | |||||||||||||||
| 215 | =head2 CreateFeature | ||||||||||||||
| 216 | |||||||||||||||
| 217 | $layer->CreateFeature($feature); | ||||||||||||||
| 218 | |||||||||||||||
| 219 | =head2 DeleteFeature | ||||||||||||||
| 220 | |||||||||||||||
| 221 | $layer->DeleteFeature($fid); | ||||||||||||||
| 222 | |||||||||||||||
| 223 | =head2 GetFeatureCount | ||||||||||||||
| 224 | |||||||||||||||
| 225 | my $count = $layer->GetFeatureCount(); | ||||||||||||||
| 226 | |||||||||||||||
| 227 | =head2 GetExtent | ||||||||||||||
| 228 | $layer->GetExtent(); | ||||||||||||||
| 229 | $layer->GetExtent(1); | ||||||||||||||
| 230 | |||||||||||||||
| 231 | Returns an array ref with [minx, miny, maxx, maxy]. | ||||||||||||||
| 232 | Argument is a boolean to force calculation even | ||||||||||||||
| 233 | if it is expensive. | ||||||||||||||
| 234 | |||||||||||||||
| 235 | =head2 Intersection, Union, SymDifference, Identity, Update, Clip, Erase | ||||||||||||||
| 236 | |||||||||||||||
| 237 | $result = $layer-><Method>($method, $args); | ||||||||||||||
| 238 | |||||||||||||||
| 239 | Runs the <method> algorithm between layer and method layer. Named | ||||||||||||||
| 240 | arguments are the following. | ||||||||||||||
| 241 | |||||||||||||||
| 242 | =over 4 | ||||||||||||||
| 243 | |||||||||||||||
| 244 | =item C<Result> | ||||||||||||||
| 245 | |||||||||||||||
| 246 | Optional, allows the user to define the result layer. | ||||||||||||||
| 247 | |||||||||||||||
| 248 | =item C<Options> | ||||||||||||||
| 249 | |||||||||||||||
| 250 | Optional, allows the user to define the options (see GDAL docs). | ||||||||||||||
| 251 | |||||||||||||||
| 252 | =item C<Progress> | ||||||||||||||
| 253 | |||||||||||||||
| 254 | Optional, the progress indicator callback. | ||||||||||||||
| 255 | |||||||||||||||
| 256 | =item C<ProgressData> | ||||||||||||||
| 257 | |||||||||||||||
| 258 | Optional, data for the progress callback. | ||||||||||||||
| 259 | |||||||||||||||
| 260 | =back | ||||||||||||||
| 261 | |||||||||||||||
| 262 | =head1 LICENSE | ||||||||||||||
| 263 | |||||||||||||||
| 264 | This software is released under the Artistic License. See | ||||||||||||||
| 265 | L<perlartistic>. | ||||||||||||||
| 266 | |||||||||||||||
| 267 | =head1 AUTHOR | ||||||||||||||
| 268 | |||||||||||||||
| 269 | Ari Jolma - Ari.Jolma at gmail.com | ||||||||||||||
| 270 | |||||||||||||||
| 271 | =head1 SEE ALSO | ||||||||||||||
| 272 | |||||||||||||||
| 273 | L<Geo::GDAL::FFI> | ||||||||||||||
| 274 | |||||||||||||||
| 275 | L<Alien::gdal>, L<FFI::Platypus>, L<http://www.gdal.org> | ||||||||||||||
| 276 | |||||||||||||||
| 277 | =cut | ||||||||||||||
| 278 | |||||||||||||||
| 279 | __END__; | ||||||||||||||