[gdal-dev] OGR SetField() doesn't work

Nicolas Simon nicolas.simon at spw.wallonie.be
Thu Nov 19 04:45:24 EST 2009


Arnaud,
 
    You should use Layer.SetFeature(feat) to trigger the update in your shape file.
 
    Nicolas
 

-----Message d'origine-----
De : gdal-dev-bounces at lists.osgeo.org [mailto:gdal-dev-bounces at lists.osgeo.org]De la part de Arnaud Vandecasteele
Envoyé : jeudi 19 novembre 2009 10:21
À : gdal-dev at lists.osgeo.org
Objet : [gdal-dev] OGR SetField() doesn't work


Hi all,


I'm trying to set a value on an existing field and existing Shapefile with python-ogr but it doesn't seems to work.
Here is my works :

-------------------------
import ogr
import math
import os

layerNameF = os.path.join("myShape.shp")   
driver = ogr.GetDriverByName("ESRI Shapefile")                    

Layer = driver.Open(layerNameF, True).GetLayer(0)

for i in range(Layer.GetFeatureCount()) :
    feat = Layer.GetFeature(i)            
    u = feat.GetFieldAsDouble('u10m')
    v = feat.GetFieldAsDouble('v10m') 
    vitesse = math.sqrt((u**2)+(v**2))                      
    feat.SetField('wspeed',vitesse) 
    print type(feat.GetFieldAsDouble('wspeed'))
    print feat.GetFieldAsDouble('wspeed')
    feat.Destroy() 

-------------------------

the print feat.GetFieldAsDouble('wspeed') show me the good values. But when I open It again with Qgis or python the value is still 0.0.

Do you know what I'm doing wrong?

Thanks for any help


Regards

Arnaud



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20091119/c6641768/attachment-0001.html


More information about the gdal-dev mailing list