Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for use of double[] instead of pointers for some funcs (deals with #53) #57

Closed
wants to merge 12 commits into from
Closed
6 changes: 3 additions & 3 deletions Changes
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.


1 change: 0 additions & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 10 additions & 9 deletions lib/Geo/GDAL/FFI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Geo/GDAL/FFI/Geometry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
16 changes: 16 additions & 0 deletions lib/Geo/GDAL/FFI/Layer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -175,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
Expand Down Expand Up @@ -206,6 +218,10 @@ Returns the FeatureDefn object for this layer.
=head2 DeleteFeature

$layer->DeleteFeature($fid);

=head2 GetFeatureCount

my $count = $layer->GetFeatureCount();

=head2 GetExtent
$layer->GetExtent();
Expand Down
6 changes: 3 additions & 3 deletions lib/Geo/GDAL/FFI/VSI/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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});
}

Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions t/00.t
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ if(1){
my $d = $l->GetDefn();
my $f = Geo::GDAL::FFI::Feature->new($d);
$l->CreateFeature($f);
undef $l; # otherwise $ds is not flushed due to parent ref
$ds = Open('test.shp');
$l = $ds->GetLayer;
$d = $l->GetDefn();
Expand Down
9 changes: 8 additions & 1 deletion t/layer.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"});
Expand Down
Loading