[Gdal-dev] Question on using ogr-perl module

wqual wolfgang.qual at gmx.net
Wed Apr 5 10:15:24 EDT 2006


Hi list,
I would like to get the fieldnames of a given attribute table using the 
perl-module ogr. It is possible to obtain the number of layers of my dataset 
(with GetLayerCount, see below), but I do not succeed in using other commands 
like GetLayerDefn, GetFeature (see result below). Is there a simple way to 
get the attribute fieldnames? Any comments/ideas are most welcome!

Best regards,
Wolfgang

What I tried was this:
#!/usr/bin/perl
use strict;
use warnings;
use ogr;

my $update;
my $datasource = 
'/home/wqual/grassdata/spearfish60/PERMANENT/vector/soils/head';
my $dataset = ogr::Open($datasource, $update = 0);
my $n = $dataset->GetLayerCount;
my $layer;
my $feature;
my $schema;
print "$n ***\n\n"; # print out number of layers 
for my $i (0..$dataset->GetLayerCount-1) {
    $layer = $dataset->GetLayerByIndex($i);
    $feature = $layer->GetFeature(1);
    $schema = $layer->GetLayerDefn();
    print "$i: $layer +++\n";
    print "$i: $schema ***\n";
}

The result:
perl -w /home/wqual/xmltest/ogrtest.pl
2 ***

0: ogr::Layer=HASH(0x823f264) +++
0: ogr::FeatureDefn=HASH(0x823f2b8) ***
1: ogr::Layer=HASH(0x823f2dc) +++
1: ogr::FeatureDefn=HASH(0x823f288) ***


Compilation finished at Wed Apr  5 16:05:15



More information about the Gdal-dev mailing list