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

Ari Jolma ari.jolma at tkk.fi
Wed Apr 5 14:01:52 EDT 2006


wqual kirjoitti:
>  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!

I have a dialog box in my Gtk2::Ex::Geo modules: 
http://map.hut.fi/PerlForGeoinformatics/OGROpen.png

The code behind the dialog box opens a datasource (for example a 
directory or database), lists the layers, and, when asked, gives the 
schema. The code for this dialog box is here 
http://cvs.sourceforge.net/viewcvs.py/libral/Gtk2-Ex-Geo/lib/Gtk2/Ex/Geo/OGRDialog.pm.in?rev=1.4&view=auto

The code for getting the attribute field names is this (from sub 
fill_property_and_schema_tvs):

my $schema = $layer->GetLayerDefn();
	
    my $n = $schema->GetFieldCount();
    my %data;
    for my $i (0..$n-1) {
	my $c = $schema->GetFieldDefn($i);
	$data{$c->GetName} = $c->GetFieldTypeName($c->GetType);
    }


There is also a dialog box for the attribute table: 
http://map.hut.fi/PerlForGeoinformatics/features_dialog.png

The code for this dialog box is in the same file as above, see sub 
browse_features and a few subs below it. There are examples of using 
GetFeature.

Ari

>
>  Best regards, Wolfgang
>

-- 
Prof. Ari Jolma
Kartografia ja Geoinformatiikka / Cartography and Geoinformatics
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