[gdal-dev] [python-ogr] Transform datasource problems

Even Rouault even.rouault at mines-paris.org
Wed Feb 9 14:24:34 EST 2011


Several points :

1) The implementation of Layer.GetFeature() is only efficient for just a few 
drivers (shapefile). Other drivers will need to sequentially read from the first 
feature ... So use GetNextFeature()

2) The real bug is that you don't rewrite the feature to its layer. So you 
need to add a target_layer.SetFeature(target_feature)

3) But what you are doing is really what ogr2ogr.py does, although your 
approach will be less efficient as you first copy the layer and then rewrite each 
of its feature.

For best performance, you should rather :
a) create a target layer from scratch
b) copy the feature definition from the source layer to the target layer
c) iterate over the source features, for each source feature, create a target 
feature (Feature.SetFrom(other_feature)). reproject the geometry, assign it to 
the target feature, and Layer.CreateFeature(target_feature)

Basically a stripped version of ogr2ogr.py


More information about the gdal-dev mailing list