diff --git a/lib/Geo/GDAL/FFI.pm b/lib/Geo/GDAL/FFI.pm index 55bb80e..871ab25 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'); diff --git a/t/00.t b/t/00.t index 56e3612..4f57c03 100644 --- a/t/00.t +++ b/t/00.t @@ -210,6 +210,11 @@ if(1){ is($p, $ogc_wkt, "Set/get projection string"); my $transform = [10,2,0,20,0,3]; $ds->SetGeoTransform($transform); + my $inv = [0,0,0,0,0,0]; + ok(Geo::GDAL::FFI::GDALInvGeoTransform($transform, $inv) && "@$inv" eq "-5 0.5 0 -6.66666666666667 0 0.333333333333333", "Invert geotransform"); + my ($x, $y); + Geo::GDAL::FFI::GDALApplyGeoTransform($transform,5,5,\$x,\$y); + ok($x == 20 && $y == 35, "Applied geotransform to pixel coords"); my $t = $ds->GetGeoTransform; is_deeply($t, $transform, "Set/get geotransform"); diff --git a/t/transform.t b/t/transform.t new file mode 100644 index 0000000..3e726e5 --- /dev/null +++ b/t/transform.t @@ -0,0 +1,55 @@ +use v5.10; +use strict; +use warnings; +use Carp; +use Geo::GDAL::FFI; +use Test::More; + +# test about SRS transformations API by using a simple extent (4 points) in UTM33 -> WGS84 + +if(1) { + my $source_srs = Geo::GDAL::FFI::SpatialReference->new( EPSG => 4326 ); + my $target_srs = Geo::GDAL::FFI::SpatialReference->new( EPSG => 32633 ); + my $ct = Geo::GDAL::FFI::OCTNewCoordinateTransformation($$source_srs, $$target_srs); + + my @extent = (16.509888, 41.006911, 17.084248, 41.370581); + + my @ul = ($extent[0], $extent[1]); + my @lr = ($extent[2], $extent[3]); + my @ur = ($lr[0],$ul[1]); + my @ll = ($ul[0],$lr[1]); + my $result = "3358768.81711923 3391240.32068776 3348976.84626544 3401215.87353221 2019470.50927319 2094945.30821076 2088830.64307375 2025411.23009774"; + + my @x = ($ul[0], $lr[0], $ur[0], $ll[0]); + my @y = ($ul[1], $lr[1], $ur[1], $ll[1]); + my $z = undef; + ok(Geo::GDAL::FFI::OCTTransform($ct, 4, \@x, \@y, \@$z), "Coordinate transformation 3D worked"); + ok(qq/@x @y/ eq $result, "Resulting coordinates"); + + @x = ($ul[0], $lr[0], $ur[0], $ll[0]); + @y = ($ul[1], $lr[1], $ur[1], $ll[1]); + $z = undef; + my @ps = (0,0,0,0); + ok(Geo::GDAL::FFI::OCTTransformEx($ct, 4, \@x, \@y, \@$z, \@ps), "Coordinate transformation 3D with pabSuccess worked"); + ok(qq/@x @y/ eq $result, "Resulting coordinates"); + ok(scalar @ps == 4 && qq/@ps/ eq qq/1 1 1 1/, "Resulting pabSuccess is TRUE x 4" ); + + @x = ($ul[0], $lr[0], $ur[0], $ll[0]); + @y = ($ul[1], $lr[1], $ur[1], $ll[1]); + $z = undef; + my $t = undef; + @ps = (0,0,0,0); + ok(Geo::GDAL::FFI::OCTTransform4D($ct, 4, \@x, \@y, \@$z, \@$t, \@ps), "Coordinate transformation 4D worked"); + ok(qq/@x @y/ eq $result && qq/@ps/ eq qq/1 1 1 1/, "Resulting coordinates"); + + @x = ($ul[0], $lr[0], $ur[0], $ll[0]); + @y = ($ul[1], $lr[1], $ur[1], $ll[1]); + $z = undef; + $t = undef; + @ps = (0,0,0,0); + ok(Geo::GDAL::FFI::OCTTransform4DWithErrorCodes($ct, 4, \@x, \@y, \@$z, \@$t, \@ps), "Coordinate transformation 4D worked"); + ok(qq/@x @y/ eq $result, "Resulting coordinates"); + ok(scalar @ps == 4 && qq/@ps/ eq qq/0 0 0 0/, "Resulting pabSuccess is SUCCESS(i.e. 0) x 4" ); +} + +done_testing();