On 11/21/2011 08:57 PM, Even Rouault wrote:
Le lundi 21 novembre 2011 11:20:33, Ari Jolma a écrit :
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
I guess it is because the GML driver transforms "a b" into "a_b" to make it a
valid XML name. But the implementation of CopyLayer() uses SetFrom(), which
cannot guess that "a b" values from source feature should be mapped to "a_b"
of target feature.
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)
Works ok perhaps, but it is potentially risky. You should not use
$l2-CreateFeature($f) with $f being a feature that has the feature definition
of $l and not $l2. That could crash in some situations... You're lucky here
that it works for you because you have the same number of fields and same type.
Hm, after some thinking I think the best approach is to construct the
original SQL to assign XML-valid column names. The same change
can/should be done in for the WFS DescribeFeature response. The the
CopyLayer method should work ok (seems so after initial tests).
Cheers,
Ari
_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev