Even, thank you for your verbose and helpful answer!
Am 09.02.2011 20:24, schrieb Even Rouault:
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()
Are these informations somewhere documented? I had a look at the docs here [1],[2], but didn't find anything related. What about iterating over layers in a datasource, or fields in a feature? Are there similar concerns?
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)
Ah, Ok, so the link/object relation between the layer and the feature is lost, once the feature is fetched? Since most things are done by reference in Python, this was not obvious to me. Thanks for pointing this out!
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.
Yes, I know. And I had a deep look at the ogr2ogr.py script before writing to the list, but frankly this is too much for me. It looks more like a c/c++ script than anything else to me - no functions, no classes, nothing from the python zen ... I really got lost in the middle of the script :-) but that's just a cause of my insufficient programming skills.
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
I will make a new version and post it here on the list, so everyone can have a look and maybe learn something from it
Frank [1] http://www.gdal.org/ogr/ogr_formats.html [2] http://www.gdal.org/ogr/classOGRLayer.html -- Frank BRONIEWSKI METRICO s.à r.l. géomètres technologies d'information géographique rue des Romains 36 L-5433 NIEDERDONVEN tél.: +352 26 74 94 - 28 fax.: +352 26 74 94 99 http://www.metrico.lu _______________________________________________ gdal-dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/gdal-dev
