| 1 | use v5.10scip-perl cpan Geo-GDAL-FFI 0.16 `v5.10`/; |
| 2 | use strictscip-perl cpan Geo-GDAL-FFI 0.16 strict/; |
| 3 | use warningsscip-perl cpan Geo-GDAL-FFI 0.16 warnings/; |
| 4 | use Carpscip-perl cpan Geo-GDAL-FFI 0.16 Carp/; |
| 5 | use Encodescip-perl cpan Geo-GDAL-FFI 0.16 Encode/ qw(decode encode); |
| 6 | use Geo::GDAL::FFIscip-perl cpan Geo-GDAL-FFI 0.16 Geo/GDAL/FFI/ qw/GetDriver/; |
| 7 | use Test::Morescip-perl cpan Geo-GDAL-FFI 0.16 Test/More/; |
| 8 | use Data::Dumperscip-perl cpan Geo-GDAL-FFI 0.16 Data/Dumper/; |
| 9 | use JSONscip-perl cpan Geo-GDAL-FFI 0.16 JSON/; |
| 10 | |
| 11 | my $mem_driver = Geo::GDAL::FFI::get_memory_driver; |
| 12 | |
| 13 | |
| 14 | { |
| 15 | package Outputscip-perl cpan Geo-GDAL-FFI 0.16 Output/; |
| 16 | use strictscip-perl cpan Geo-GDAL-FFI 0.16 strict/; |
| 17 | use warningsscip-perl cpan Geo-GDAL-FFI 0.16 warnings/; |
| 18 | our @outputscip-perl cpan Geo-GDAL-FFI 0.16 Output/`@output`.; |
| 19 | sub newscip-perl cpan Geo-GDAL-FFI 0.16 Output/new(). { |
| 20 | return blessscip-perl cpan Geo-GDAL-FFI 0.16 Output/bless(). {}, 'Output'; |
| 21 | } |
| 22 | sub writescip-perl cpan Geo-GDAL-FFI 0.16 Output/write(). { |
| 23 | my $line = shiftscip-perl cpan Geo-GDAL-FFI 0.16 Output/shift().; |
| 24 | pushscip-perl cpan Geo-GDAL-FFI 0.16 Output/push(). @outputscip-perl cpan Geo-GDAL-FFI 0.16 Output/`@output`., $line; |
| 25 | return 1; |
| 26 | } |
| 27 | sub closescip-perl cpan Geo-GDAL-FFI 0.16 Output/close(). { |
| 28 | return 1; |
| 29 | } |
| 30 | sub outputscip-perl cpan Geo-GDAL-FFI 0.16 Output/output(). { |
| 31 | my $output = joinscip-perl cpan Geo-GDAL-FFI 0.16 Output/join(). '', @outputscip-perl cpan Geo-GDAL-FFI 0.16 Output/`@output`.; |
| 32 | $output =~ s/\n//g; |
| 33 | return $output; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | # test vsistdout redirection |
| 38 | TODO: { |
| 39 | local $TODOscip-perl cpan Geo-GDAL-FFI 0.16 Output/$TODO. = "Fails with GDAL 3.13", 1 if(Geo::GDAL::FFI::GetVersionInfoscip-perl cpan Geo-GDAL-FFI 0.16 Geo/GDAL/FFI/GetVersionInfo().() >= 3130000); |
| 40 | # create a small layer and copy it to vsistdout with redirection |
| 41 | my $ds = GetDriverscip-perl cpan Geo-GDAL-FFI 0.16 Geo/GDAL/FFI/GetDriver().($mem_driver)->Createscip-perl cpan Geo-GDAL-FFI 0.16 Output/Create().; |
| 42 | my $layer = $ds->CreateLayerscip-perl cpan Geo-GDAL-FFI 0.16 Output/CreateLayer().({GeometryType => 'None'}); |
| 43 | $layer->CreateFieldscip-perl cpan Geo-GDAL-FFI 0.16 Output/CreateField().(value => 'Integer'); |
| 44 | $layer->CreateGeomFieldscip-perl cpan Geo-GDAL-FFI 0.16 Output/CreateGeomField().(geom => 'Point'); |
| 45 | for my $i (1..2) { |
| 46 | my $feature = Geo::GDAL::FFI::Feature->newscip-perl cpan Geo-GDAL-FFI 0.16 Geo/GDAL/FFI/Feature/new().($layer->GetDefnscip-perl cpan Geo-GDAL-FFI 0.16 Output/GetDefn().); |
| 47 | $feature->SetFieldscip-perl cpan Geo-GDAL-FFI 0.16 Geo/GDAL/FFI/Feature/SetField().(value => 12); |
| 48 | $feature->SetGeomFieldscip-perl cpan Geo-GDAL-FFI 0.16 Geo/GDAL/FFI/Feature/SetGeomField().(geom => [WKT => "POINT(1 $i)"]); |
| 49 | $layer->CreateFeaturescip-perl cpan Geo-GDAL-FFI 0.16 Output/CreateFeature().($feature); |
| 50 | } |
| 51 | $ds->FlushCachescip-perl cpan Geo-GDAL-FFI 0.16 Output/FlushCache().; |
| 52 | my $output = Output->newscip-perl cpan Geo-GDAL-FFI 0.16 Output/new().; |
| 53 | my $gdal = Geo::GDAL::FFI->get_instancescip-perl cpan Geo-GDAL-FFI 0.16 Geo/GDAL/FFI/get_instance().; |
| 54 | $gdal->SetWriterscip-perl cpan Geo-GDAL-FFI 0.16 Geo/GDAL/FFI/SetWriter().($output); |
| 55 | GetDriverscip-perl cpan Geo-GDAL-FFI 0.16 Geo/GDAL/FFI/GetDriver().('GeoJSON')->Createscip-perl cpan Geo-GDAL-FFI 0.16 Output/Create().('/vsistdout')->CopyLayerscip-perl cpan Geo-GDAL-FFI 0.16 Output/CopyLayer().($layer); |
| 56 | $gdal->CloseWriterscip-perl cpan Geo-GDAL-FFI 0.16 Geo/GDAL/FFI/CloseWriter().; |
| 57 | |
| 58 | my $ret = $outputscip-perl cpan Geo-GDAL-FFI 0.16 Output/output().->output; |
| 59 | $ret = decode_jsonscip-perl cpan Geo-GDAL-FFI 0.16 Output/decode_json(). $ret; |
| 60 | |
| 61 | my $exp = decode_jsonscip-perl cpan Geo-GDAL-FFI 0.16 Output/decode_json(). (get_expected_json_datascip-perl cpan Geo-GDAL-FFI 0.16 Output/get_expected_json_data().()); |
| 62 | |
| 63 | is_deeplyscip-perl cpan Geo-GDAL-FFI 0.16 Output/is_deeply(). ($ret, $exp, |
| 64 | "Redirect vsistdout to write/close methods of a class."); |
| 65 | |
| 66 | } |
| 67 | |
| 68 | |
| 69 | # test Translate |
| 70 | SKIP: { |
| 71 | skipscip-perl cpan Geo-GDAL-FFI 0.16 Output/skip(). "vsimem test fails with GDAL 3.13", 1 if(Geo::GDAL::FFI::GetVersionInfoscip-perl cpan Geo-GDAL-FFI 0.16 Geo/GDAL/FFI/GetVersionInfo().() >= 3130000); |
| 72 | my $ds = GetDriverscip-perl cpan Geo-GDAL-FFI 0.16 Geo/GDAL/FFI/GetDriver().('GTiff')->Createscip-perl cpan Geo-GDAL-FFI 0.16 Output/Create().('/vsimem/test.tiff', 10, 10, 1); |
| 73 | my $translated = $ds->Translatescip-perl cpan Geo-GDAL-FFI 0.16 Output/Translate().('/vsimem/translated.tiff', [-of => 'GTiff']); |
| 74 | okscip-perl cpan Geo-GDAL-FFI 0.16 Output/ok().($translated->GetDriverscip-perl cpan Geo-GDAL-FFI 0.16 Output/GetDriver().->GetNamescip-perl cpan Geo-GDAL-FFI 0.16 Output/GetName(). eq 'GTiff', "Translate"); |
| 75 | } |
| 76 | |
| 77 | done_testingscip-perl cpan Geo-GDAL-FFI 0.16 Output/done_testing().(); |
| 78 | |
| 79 | |
| 80 | sub get_expected_json_datascip-perl cpan Geo-GDAL-FFI 0.16 Output/get_expected_json_data(). { |
| 81 | my $json = <<'EOJSON' |
| 82 | { |
| 83 | "type": "FeatureCollection", |
| 84 | "features": [{ |
| 85 | "type": "Feature", |
| 86 | "id": 0, |
| 87 | "properties": { |
| 88 | "value": 12 |
| 89 | }, |
| 90 | "geometry": { |
| 91 | "type": "Point", |
| 92 | "coordinates": [1.0, 1.0] |
| 93 | } |
| 94 | }, { |
| 95 | "type": "Feature", |
| 96 | "id": 1, |
| 97 | "properties": { |
| 98 | "value": 12 |
| 99 | }, |
| 100 | "geometry": { |
| 101 | "type": "Point", |
| 102 | "coordinates": [1.0, 2.0] |
| 103 | } |
| 104 | } |
| 105 | ] |
| 106 | } |
| 107 | EOJSON |
| 108 | ; |
| 109 | return $json; |
| 110 | } |
| 111 | |
| 112 |