From 32c067fad847a663cfb13f08f36b44c93e37bf51 Mon Sep 17 00:00:00 2001 From: Francesco Paolo Lovergine Date: Thu, 14 Sep 2023 20:25:55 +0200 Subject: [PATCH 01/12] Changes for use of double[] instead of pointers for some funcs --- lib/Geo/GDAL/FFI.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Geo/GDAL/FFI.pm b/lib/Geo/GDAL/FFI.pm index 1a6ea0f..52549d8 100644 --- a/lib/Geo/GDAL/FFI.pm +++ b/lib/Geo/GDAL/FFI.pm @@ -536,9 +536,9 @@ $ffi->attach('GDALInitGCPs' => [qw/int opaque/] => 'void'); $ffi->attach('GDALDeinitGCPs' => [qw/int opaque/] => 'void'); $ffi->attach('GDALDuplicateGCPs' => [qw/int opaque/] => 'opaque'); $ffi->attach('GDALGCPsToGeoTransform' => [qw/int opaque double* int/] => 'int'); -$ffi->attach('GDALInvGeoTransform' => [qw/double* double*/] => 'int'); -$ffi->attach('GDALApplyGeoTransform' => [qw/double* double double double* double*/] => 'void'); -$ffi->attach('GDALComposeGeoTransforms' => [qw/double* double* double*/] => 'void'); +$ffi->attach('GDALInvGeoTransform' => [qw/double[] double[]/] => 'int'); +$ffi->attach('GDALApplyGeoTransform' => [qw/double[6] double double double* double*/] => 'void'); +$ffi->attach('GDALComposeGeoTransforms' => [qw/double[6] double[6] double[6]/] => 'void'); $ffi->attach('GDALGetMetadataDomainList' => [qw/opaque/] => 'opaque'); $ffi->attach('GDALGetMetadata' => [qw/opaque string/] => 'opaque'); $ffi->attach('GDALSetMetadata' => [qw/opaque opaque string/] => 'int'); @@ -1509,11 +1509,11 @@ $ffi->attach('OCTGetSourceCS' => [qw/opaque/] => 'opaque'); $ffi->attach('OCTGetTargetCS' => [qw/opaque/] => 'opaque'); $ffi->attach('OCTGetInverse' => [qw/opaque/] => 'opaque'); $ffi->attach('OCTDestroyCoordinateTransformation' => [qw/opaque/] => 'void'); -$ffi->attach('OCTTransform' => [qw/opaque int double* double* double*/] => 'int'); -$ffi->attach('OCTTransformEx' => [qw/opaque int double* double* double* int*/] => 'int'); -$ffi->attach('OCTTransform4D' => [qw/opaque int double* double* double* double* int*/] => 'int'); -$ffi->attach('OCTTransform4DWithErrorCodes' => [qw/opaque int double* double* double* double* int*/] => 'int'); -$ffi->attach('OCTTransformBounds' => [qw/opaque double double double double double* double* double* double* int/] => 'int'); +$ffi->attach('OCTTransform' => [qw/opaque int double[] double[] double[]/] => 'int'); +$ffi->attach('OCTTransformEx' => [qw/opaque int double[] double[] double[] int[]/] => 'int'); +$ffi->attach('OCTTransform4D' => [qw/opaque int double[] double[] double[] double[] int[]/] => 'int'); +$ffi->attach('OCTTransform4DWithErrorCodes' => [qw/opaque int double[] double[] double[] double[] int[]/] => 'int'); +$ffi->attach('OCTTransformBounds' => [qw/opaque double double double double double[] double[] double[] double[] int/] => 'int'); # from apps/gdal_utils.h $ffi->attach('GDALInfoOptionsNew' => [qw/opaque opaque/] => 'opaque'); $ffi->attach('GDALInfoOptionsFree' => [qw/opaque/] => 'void'); From bd3fa0bfb30a195516a8ab19c913c5f573790938 Mon Sep 17 00:00:00 2001 From: Francesco Paolo Lovergine Date: Thu, 21 Sep 2023 11:32:43 +0200 Subject: [PATCH 02/12] Removed use of now discouraged FFI::Platypus::Declare module. --- Changes | 6 +++--- Makefile.PL | 1 - lib/Geo/GDAL/FFI/VSI/File.pm | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index 6385bf2..93bf026 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,7 @@ Revision history for Perl extension Geo::GDAL::FFI -0.11 - - +0.11 unreleased + - Removed use of to FFI::Platypus::Declare, now discouraged. 0.10 July 10, 2023 - Add dependency to FFI::Platypus::Declare @@ -55,4 +55,4 @@ Revision history for Perl extension Geo::GDAL::FFI 0.01 Apr 6, 2018 - Included all basic functionality but lots of docs and methods to do. - \ No newline at end of file + diff --git a/Makefile.PL b/Makefile.PL index c57258c..7297ea1 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -66,7 +66,6 @@ use Config; PREREQ_PM => { PkgConfig => 0.23026, FFI::Platypus => 0, - FFI::Platypus::Declare => 0, PDL => 0, Sort::Versions => 0, Alien::gdal => 0, diff --git a/lib/Geo/GDAL/FFI/VSI/File.pm b/lib/Geo/GDAL/FFI/VSI/File.pm index 3095f16..cd06f79 100644 --- a/lib/Geo/GDAL/FFI/VSI/File.pm +++ b/lib/Geo/GDAL/FFI/VSI/File.pm @@ -5,7 +5,6 @@ use warnings; use Encode qw(decode encode); use Carp; use FFI::Platypus::Buffer; -use FFI::Platypus::Declare; our $VERSION = 0.1100; @@ -45,7 +44,8 @@ sub Read { sub Write { my ($self, $buf) = @_; my $len = do {use bytes; length($buf)}; - my $address = cast 'string' => 'opaque', $buf; + my $ffi = FFI::Platypus->new(); + my $address = $ffi->cast 'string' => 'opaque', $buf; return Geo::GDAL::FFI::VSIFWriteL($address, 1, $len, $self->{handle}); } From 236eacddbd2dc48985dc524d499f116a91df827b Mon Sep 17 00:00:00 2001 From: Francesco Paolo Lovergine <53651+fpl@users.noreply.github.com> Date: Fri, 22 Sep 2023 09:27:28 +0200 Subject: [PATCH 03/12] Fixing missing () in File.pm --- lib/Geo/GDAL/FFI/VSI/File.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Geo/GDAL/FFI/VSI/File.pm b/lib/Geo/GDAL/FFI/VSI/File.pm index cd06f79..9075e48 100644 --- a/lib/Geo/GDAL/FFI/VSI/File.pm +++ b/lib/Geo/GDAL/FFI/VSI/File.pm @@ -45,7 +45,7 @@ sub Write { my ($self, $buf) = @_; my $len = do {use bytes; length($buf)}; my $ffi = FFI::Platypus->new(); - my $address = $ffi->cast 'string' => 'opaque', $buf; + my $address = $ffi->cast('string' => 'opaque', $buf); return Geo::GDAL::FFI::VSIFWriteL($address, 1, $len, $self->{handle}); } From 8d51e54947fb13ffff3f9cc1c1d825a39d6b810f Mon Sep 17 00:00:00 2001 From: Francesco Paolo Lovergine Date: Thu, 21 Sep 2023 11:52:26 +0200 Subject: [PATCH 04/12] Fixed typo in Geometry.pm (closes: #54) --- lib/Geo/GDAL/FFI/Geometry.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Geo/GDAL/FFI/Geometry.pm b/lib/Geo/GDAL/FFI/Geometry.pm index ed857c6..771b4ac 100644 --- a/lib/Geo/GDAL/FFI/Geometry.pm +++ b/lib/Geo/GDAL/FFI/Geometry.pm @@ -181,7 +181,7 @@ sub GetGeometry { sub AddGeometry { my ($self, $g) = @_; confess "Can't modify an immutable object." if $Geo::GDAL::FFI::immutable{$$self}; - my $e = Geo::GDAL::FFI::OGR_G_OGR_G_AddGeometry($$self, $$g); + my $e = Geo::GDAL::FFI::OGR_G_AddGeometry($$self, $$g); return unless $e; confess(Geo::GDAL::FFI::error_msg()); } From e7c15142eb21b219ce96c0aa570e59eef29d5381 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Tue, 24 Oct 2023 20:24:40 +1100 Subject: [PATCH 05/12] Add Layer::GetFeatureCount method --- lib/Geo/GDAL/FFI/Layer.pm | 5 +++++ t/layer.t | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Geo/GDAL/FFI/Layer.pm b/lib/Geo/GDAL/FFI/Layer.pm index 8c907d9..52d8534 100644 --- a/lib/Geo/GDAL/FFI/Layer.pm +++ b/lib/Geo/GDAL/FFI/Layer.pm @@ -86,6 +86,11 @@ sub GetFeature { return bless \$f, 'Geo::GDAL::FFI::Feature'; } +sub GetFeatureCount { + my ($self, $force) = @_; + Geo::GDAL::FFI::OGR_L_GetFeatureCount($$self, !!$force); +} + sub SetFeature { my ($self, $f) = @_; Geo::GDAL::FFI::OGR_L_SetFeature($$self, $$f); diff --git a/t/layer.t b/t/layer.t index 7dbd284..001d1f5 100644 --- a/t/layer.t +++ b/t/layer.t @@ -34,6 +34,13 @@ $f->SetGeomField([WKT => 'POLYGON ((2 1, 2 2, 4 2, 4 1, 2 1))']); $method->CreateFeature($f); +{ + my $feature_count = $layer->GetFeatureCount; + is $feature_count, 1, 'Got correct feature count'; + $feature_count = $layer->GetFeatureCount (1); + is $feature_count, 1, 'Got correct feature count with force arg=true'; +} + my $progress; my $result; @@ -136,7 +143,7 @@ is_deeply $layer->GetExtent(1), $exp_extent, 'Got correct layer extent when forc { #local $TODO = 'sql DISTINCT not yet working, despite following GDAL doc example'; is_deeply (\@items, ['one','ten'], 'got correct distinct items'); - } + } my $result = eval { $ds->ExecuteSQL (qq{CREATE SPATIAL INDEX ON "$layer_name"}); From 5154e27d5fdf749885dae941169c8c708b627be8 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 25 Oct 2023 08:34:10 +1100 Subject: [PATCH 06/12] Tests: clear data set variable before re-using Might help with CI failures. --- t/00.t | 1 + 1 file changed, 1 insertion(+) diff --git a/t/00.t b/t/00.t index b795db5..52edf92 100644 --- a/t/00.t +++ b/t/00.t @@ -296,6 +296,7 @@ if(1){ my $d = $l->GetDefn(); my $f = Geo::GDAL::FFI::Feature->new($d); $l->CreateFeature($f); + undef $ds; $ds = Open('test.shp'); $l = $ds->GetLayer; $d = $l->GetDefn(); From 52bfcc40625668c2e881f79548c6b1b5014053e4 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 25 Oct 2023 09:12:40 +1100 Subject: [PATCH 07/12] Tests: Close newly written dataset before reading Might help with CI failures. --- t/00.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/00.t b/t/00.t index 52edf92..edcef29 100644 --- a/t/00.t +++ b/t/00.t @@ -296,7 +296,7 @@ if(1){ my $d = $l->GetDefn(); my $f = Geo::GDAL::FFI::Feature->new($d); $l->CreateFeature($f); - undef $ds; + Geo::GDAL::FFI::GDALClose($$ds); $ds = Open('test.shp'); $l = $ds->GetLayer; $d = $l->GetDefn(); From 720a03474d8f3864f917e8a96e75078e1eab6744 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 25 Oct 2023 15:59:24 +1100 Subject: [PATCH 08/12] Tests: undef a layer to ensure a dataset var is closed properly Updates #62 --- t/00.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/00.t b/t/00.t index edcef29..56e3612 100644 --- a/t/00.t +++ b/t/00.t @@ -296,7 +296,7 @@ if(1){ my $d = $l->GetDefn(); my $f = Geo::GDAL::FFI::Feature->new($d); $l->CreateFeature($f); - Geo::GDAL::FFI::GDALClose($$ds); + undef $l; # otherwise $ds is not flushed due to parent ref $ds = Open('test.shp'); $l = $ds->GetLayer; $d = $l->GetDefn(); From cafd2cc631a7e28adb6ee6bf0552bf0774a3da11 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 27 Oct 2023 13:07:34 +1100 Subject: [PATCH 09/12] POD: add GetFeatureCount --- lib/Geo/GDAL/FFI/Layer.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Geo/GDAL/FFI/Layer.pm b/lib/Geo/GDAL/FFI/Layer.pm index 52d8534..80873ed 100644 --- a/lib/Geo/GDAL/FFI/Layer.pm +++ b/lib/Geo/GDAL/FFI/Layer.pm @@ -211,6 +211,10 @@ Returns the FeatureDefn object for this layer. =head2 DeleteFeature $layer->DeleteFeature($fid); + +=head2 GetFeatureCount + + my $count = $layer->GetFeatureCount(); =head2 GetExtent $layer->GetExtent(); From 1b965cee70c6e06ff11e95931bf3226773b8d074 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Fri, 27 Oct 2023 13:15:44 +1100 Subject: [PATCH 10/12] Add note about dataset object destruction with layers Updates #62 --- lib/Geo/GDAL/FFI/Layer.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Geo/GDAL/FFI/Layer.pm b/lib/Geo/GDAL/FFI/Layer.pm index 80873ed..aa32613 100644 --- a/lib/Geo/GDAL/FFI/Layer.pm +++ b/lib/Geo/GDAL/FFI/Layer.pm @@ -180,6 +180,13 @@ A set of (vector) features having a same schema (the same Defn object). Obtain a layer object by the CreateLayer or GetLayer method of a vector dataset object. +Note that the system stores a reference to the parent dataset for +each layer object to ensure layer objects remain viable. +If you are relying on a dataset object's destruction to +flush its dataset cache and then close it then you need to ensure +all associated child layers are also destroyed. Failure to do so could +lead to corrupt data when reading in newly written files. + =head1 METHODS =head2 GetDefn From 890d5e4b93994a914d251287fc7551251c6e3ee6 Mon Sep 17 00:00:00 2001 From: Ari Jolma Date: Sun, 12 Nov 2023 18:21:56 +0200 Subject: [PATCH 11/12] VSIStdoutSetRedirection: return what the write method returns or 1 as that indicates success for GDAL --- lib/Geo/GDAL/FFI.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Geo/GDAL/FFI.pm b/lib/Geo/GDAL/FFI.pm index 52549d8..871ab25 100644 --- a/lib/Geo/GDAL/FFI.pm +++ b/lib/Geo/GDAL/FFI.pm @@ -1725,7 +1725,8 @@ sub SetWriter { $self->{close} = $c; $self->{writer} = $self->{ffi}->closure(sub { my ($buf, $size, $count, $stream) = @_; - $w->(buffer_to_scalar($buf, $size*$count)); + my $retval = $w->(buffer_to_scalar($buf, $size*$count)) // 1; + return $retval; }); VSIStdoutSetRedirection($self->{writer}, 0); } From 714a08fdec09b21c24463bdc9da234ea37ba2fea Mon Sep 17 00:00:00 2001 From: Bas Couwenberg Date: Sun, 12 Nov 2023 20:57:51 +0100 Subject: [PATCH 12/12] Fix spelling errors. * succesfully -> successfully --- lib/Geo/GDAL/FFI/VSI/File.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Geo/GDAL/FFI/VSI/File.pm b/lib/Geo/GDAL/FFI/VSI/File.pm index 9075e48..7b92c58 100644 --- a/lib/Geo/GDAL/FFI/VSI/File.pm +++ b/lib/Geo/GDAL/FFI/VSI/File.pm @@ -94,7 +94,7 @@ string. $len is optional and by default 1. =head2 Write($buf) Write the Perl string $buf into the file. Returns the number of -succesfully written bytes. +successfully written bytes. =head1 LICENSE