[gdal-dev] CopyLayer oddity using GML driver

Ari Jolma ari.jolma at gmail.com
Mon Nov 21 05:20:33 EST 2011


Hi,

I'm making a new GML layer from an existing layer. For some reason the 
CopyLayer method leaves adjusted fields out but CreateField, 
CreateFeature sequence does not. I guess they should be identical?

i.e.

my $datasource = Geo::OGR::Open('Pg:...');
my $l = $datasource->ExecuteSQL('...');
my $gml = Geo::OGR::Driver('GML')->Create('/vsistdout/');
$gml->CopyLayer($l, 'a');

leaves fields like "a b" out, while

my $datasource = Geo::OGR::Open('Pg:...');
my $l = $datasource->ExecuteSQL('...');
my $gml = Geo::OGR::Driver('GML')->Create('/vsistdout/');
my $l2 = $gml->CreateLayer('test');

my $d = $l->GetLayerDefn;
for (0..$d->GetFieldCount-1) {
     my $f = $d->GetFieldDefn($_);
     $l2->CreateField($f);
}

$l->ResetReading;
while (my $f = $l->GetNextFeature) {
     $l2->CreateFeature($f);
}

works ok (and prints out warnings about the field name adjustments)

I tried to look into what the CopyLayer method generic driver does 
differently but could not tell.

Any ideas?

Ari



More information about the gdal-dev mailing list