[gdal-dev] FW: Problem with GDAL perl 1.5 bindings

Ethan Alpert ealpert at digitalglobe.com
Wed Jan 30 19:06:23 EST 2008


 

Prior to 1.5 I'd been using the trunk version from 11/06/2007. Looking
at gdal_wrap.cpp I see that there were two versions checked in 1.3.31
and 1.3.30. One of these checks breaks a piece of code that worked fine
in version 1.3.29

 

The problem relates to clean up when an object is dereferenced in perl.

 

For many releases now if I created and wrote an image I would have to
Call FlushCache *and* undef the variable referencing the GDALdataset
inorder for all the data I wrote to actually end up in the file. This no
longer works. Now I must exit my perl script completely for the all the
data to be completely written.

 

Below is an example of converting to grayscale. This works great if at
the end I'm done. But this is not the case. Later in the script I call
gdal_rasterize and the resulting file ends up not having a geotransform
and is 3x too big. If I exit my app and call gdal_rasterize manually
everything works correctly. This is what led me to believe there's been
a change in the perl binding that relate to cleaning up and finalizing
the file that now doesn't execute on derference but only when the perl
script exits. 

 

On 11/06/2007 my code worked. Today with the stock 1.5 it doesn't. So my
question is there some function to call to force the file to be
completely written? If not is there a way to revert to the prior
functionality. . 

 

                $gtiff_driver = Geo::GDAL::GetDriverByName('GTiff');

                $fil = Geo::GDAL::Open("$tmp_dir/$$.tif");

                $xsize = $fil->{RasterXSize};

                $ysize = $fil->{RasterYSize};

 

                $tot = $xsize;

                $width = $xsize;

                $bandr = $fil->GetRasterBand(1);

                $bandg = $fil->GetRasterBand(2);

                $bandb = $fil->GetRasterBand(3);

                $output_ds= $gtiff_driver->Create("$tmp_dir/$$\_bw.tif",
$fil->{RasterXSize}, $fil->{RasterYSize}, 1,
$Geo::GDAL::Const::GDT_Byte);

                $output_ds->SetGeoTransform($fil->GetGeoTransform);

                $output_ds->SetProjection($fil->GetProjection);

                $b = $output_ds->GetRasterBand(1);

                for($k = 0; $k < $fil->{RasterYSize}; $k++) {

                        $scanliner =
$bandr->ReadRaster(0,$k,$fil->{RasterXSize},1);

                        $scanlineb =
$bandb->ReadRaster(0,$k,$fil->{RasterXSize},1);

                        $scanlineg =
$bandg->ReadRaster(0,$k,$fil->{RasterXSize},1);

                        @datar = unpack("C[$tot]",$scanliner);

                        @datag = unpack("C[$tot]",$scanlineg);

                        @datab = unpack("C[$tot]",$scanlineb);

 

                        @datagrey = ();

                        $min = 300;

                        $max = -1;

                        for ($i = 0; $i < scalar @datar; $i++) {

                                $t = (.3 * $datar[$i] + .59 * $datag[$i]
+  .11 * $datab[$i]) + .000001;

                                push @datagrey, int ($t+.5);

                        }

 

 

                        $ot = pack("c[$tot]", at datagrey);

                        $b->WriteRaster(0,$k,$width,1,$ot);

                }

                $output_ds->FlushCache;

                undef $output_ds;

 

 

later I call:

                system "gdal_rasterize -i -l $$ -b 1 -burn 0
$tmp_dir/$$.shp $tmp_dir/$$\_bw.tif ";

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20080130/3af06015/attachment.html


More information about the gdal-dev mailing list