[Gdal-dev] Using geo::GDAL: [solved!]
wqual
wolfgang.qual at gmx.net
Fri Mar 17 06:35:44 EST 2006
Hi Ari,
many thanks very for your advice. I first had to install gdal-Swig-Perl on my
Debian machine [1]
1) get the source package of libgdal:
apt-get -b source libgdal1
2)install gdal-swig-perl
cd gdal-1.3.1/
cd swig/perl/
make generate
make build
3) create debian-package with checkinstall:
checkinstall
Afterwards, I tested your proposed script (with little modifications) - and it
worked!
use gdal;
my $dataset =
gdal::Open('/home/wqual/grassdata/spearfish60/PERMANENT/cellhd/landcover.30m');
my $band = $dataset->GetRasterBand(1);
my $colortable = $band->GetRasterColorTable;
my $i;
my @color;
for $i (0..$colortable->GetCount-1) { # I assume, or then 1..
@color = $colortable->GetColorEntryAsRGB($i);
print "$i @color\n";
}
Result:
wqual at standalone:~/xmltest$ perl script_swig.pl
0 0 0 0 0
1 0 0 0 0
2 0 0 0 0
3 0 0 0 0
4 0 0 0 0
5 0 0 0 0
6 0 0 0 0
7 0 0 0 0
8 0 0 0 0
9 0 0 0 0
10 0 0 0 0
11 0 0 255 255
12 25 20 230 255
13 51 40 204 255
14 76 61 179 255
15 102 81 153 255
[a.s.f.]
Best regards,
Wolfgang
[1] http://map.hut.fi/gdal-perl/
Am Donnerstag 16 März 2006 pH:37:14 nachmittags/abends schrieb Ari Jolma:
> Disclaimers first: My answer may not be useful since I've got no
> experience reading GRASS datasets with GDAL, and I'm going to write
> about the swig-based Perl interface to GDAL.
>
> use gdal;
> $dataset = gdal::Open('grassraster');
> $band = $dataset->GetRasterBand(1);
> $colortable = $band->GetRasterColorTable;
> for $i (0..$colortable->GetCount-1) { # I assume, or then 1..
> @color = $colortable->GetColorEntryAsRGB($i);
> print "$i @color\n";
> }
>
> other general information is a bit more difficult since the swig
> interface does not seem to have methods like $band->GetStatistics etc.
>
> what we have is here (poorly documented, good docs are here:
> http://www.gdal.org/classGDALRasterBand.html)
> http://map.hut.fi/gdal-perl/gdal.pod.html#gdal__band
>
> it looks like you currently have to scan through the raster with
> ReadRaster method to get the categories for example
>
> Ari
>
> wqual kirjoitti:
> > Hi list,
> > I would like to write a small script in perl which should extract some
> > information (like color tables, number of categories) of my GRASS raster
> > file.
> >
> > I installed the module geo::GDAL from [1],
> >
> > my $data =
> > Geo::GDAL::Open("/home/wqual/grassdata/spearfish60/PERMANENT/cellhd/aspec
> >t", GA_ReadOnly);
> > use Data::Dumper;
> > print Dumper($data);
> >
> > But everything I get is:
> >
> > $VAR1 = bless( do{\(my $o = 136387672)}, 'Geo::GDAL::Dataset' );
> >
> > Afterwards, I tried this:
> > my $colors = $data->GetRasterColorTable;
> > use Data::Dumper;
> > print Dumper($colors);
> >
> > But I receive the following error message: "Can't locate object method
> > "GetRasterColorTable" via package "Geo::GDAL::Dataset" at
> > Dateiauslesen.pl line 36.
> >
> > Hmm. I just do not know how to use this module for my purpose. Any ideas?
> >
> >
> > Best regards,
> >
> > Wolfgang
> >
> > [1] http://search.cpan.org/~sderle/Geo-GDAL-0.11/GDAL.pm
> > _______________________________________________
> > Gdal-dev mailing list
> > Gdal-dev at lists.maptools.org
> > http://lists.maptools.org/mailman/listinfo/gdal-dev
More information about the Gdal-dev
mailing list