[Gdal-dev] Geo::GDAL how to close a file?

Ari Jolma ari.jolma at tkk.fi
Fri Mar 23 17:15:42 EDT 2007


Stephen Woodbridge kirjoitti:
> Another question is How should I close a file opened like:
>
> $dataset = Geo::GDAL::Open('filename');
>
> Anything I need to do to dispose of objects I have accessed?

They're disposed of automatically as Perl disposes them. Only if you 
create a new dataset you need to be more careful in flushing and closing 
the opened datasets or data sources (in OGR) or layers.

There are some more examples like the one below in the docs (written in 
doxygen and visible at http://map.hut.fi/doc/Geo-GDAL/html/pages.html)

Cheers,

Ari

>
> Here is a little example of doing something like gdalinfo:
>
> #!/usr/bin/perl -w
> use strict;
> use Geo::GDAL;
>
> my $f = shift @ARGV || die "gdal-test file\n";
>
> my $dataset = Geo::GDAL::Open($f);
>
> print "RasterXSize=".$dataset->{RasterXSize}."\n";
> print "RasterYSize=".$dataset->{RasterYSize}."\n";
> print "RasterCount=".$dataset->{RasterCount}."\n";
> print "GetProjection=".$dataset->GetProjection."\n";
> my $driver = $dataset->GetDriver;
> print "driver->ShortName=".$driver->{ShortName}."\n";
> for my $i (1..$dataset->{RasterCount}) {
>     my $band = $dataset->GetRasterBand($i);
>     print "  band[$i]->XSize=".$band->{XSize}."\n";
>     print "  band[$i]->YSize=".$band->{YSize}."\n";
>     print "  band[$i]->DataType=".$band->{DataType}."\n";
>     print " 
> GetRasterColorInterpretation=".$band->GetRasterColorInterpretation."\n";
>     print "  GetNoDataValue=".$band->GetNoDataValue."\n";
>     print "  GetMinimum=".$band->GetMinimum."\n";
>     print "  GetMaximum=".$band->GetMaximum."\n";
>     print "  GetOffset=".$band->GetOffset."\n";
>     print "  GetScale=".$band->GetScale."\n";
>     print "  GetOverviewCount=".$band->GetOverviewCount."\n";
>     print "  Checksum=".$band->Checksum."\n";
>     print " 
> ComputeRasterMinMax=".join(",",@{$band->ComputeRasterMinMax})."\n";
> }
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev


-- 
Prof. Ari Jolma
Geoinformaatio- ja paikannustekniikka
Geoinformation and positioning technology
Teknillinen Korkeakoulu / Helsinki University of Technology
POBox 1200, 02015 TKK, Finland
Email: ari.jolma at tkk.fi URL: http://www.tkk.fi/~jolma




More information about the Gdal-dev mailing list