<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi,<br>
<br>
Just to tell what Martin adviced works well. <br>
Careful : the <br>
provider.addFeatures( [feature] ) <br>
doesn't work with only one feature, but needs a list of features.<br>
<br>
Below is a bit of my code to <br>
* create a new shape file if it doesn't exists and add the features<br>
* open an existing shapefile to add some features to it<br>
<br>
************<br>
       if not os.path.exists( "myshape.shp") ): # si le shapefile
n'existe pas<br>
          #we create the new shapefile<br>
          writer = QgsVectorFileWriter("myshape.shp"), "CP1250",
fields, QGis.WKBPoint, None)<br>
          existe=0<br>
          if writer.hasError() != QgsVectorFileWriter.NoError:<br>
            print "Error when creating shapefile: ", writer.hasError()<br>
          <br>
        else: #when the shapefile exists<br>
          #on ouvre le fichier shape existant<br>
          mylayer = QgsVectorLayer("myshape.shp"), "ma_couche", "ogr")<br>
          myprovider = mylayer.getDataProvider()<br>
          existe=1<br>
        list_fet=[]<br>
        for i in range(0,len(donnees)): #donnees is the list[[]]
containing the data from the csv file<br>
              fet = QgsFeature()<br>
              fet.setGeometry(QgsGeometry.fromPoint(
xform.transform(QgsPoint(longitude, latitude)) )  )<br>
              fet.addAttribute(0, QVariant(local_date) ) #date<br>
              fet.addAttribute(1, QVariant(local_heure) ) #heure locale<br>
             # .......<br>
<br>
              if existe == 0:<br>
                writer.addFeature(fet)  # directly add each feature
inside the loop<br>
              if existe == 1:<br>
                list_fet.append(fet)  # we add the feature in the list
of feature "list_fet" <br>
<br>
        if existe == 1:<br>
          myprovider.addFeatures(list_fet)       #here we add all the
features from list_fet to the shapefile<br>
<br>
*************<br>
<br>
Michael<br>
<br>
Martin Dobias a écrit :
<blockquote
 cite="mid:e8e7199c0712120855wc993569p1cba19e34f7d3cb8@mail.gmail.com"
 type="cite">
  <pre wrap="">On Dec 12, 2007 5:43 PM, Michaël Douchin <a class="moz-txt-link-rfc2396E" href="mailto:michael.douchin@laposte.net"><michael.douchin@laposte.net></a> wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap=""> In an short way "Is it possible to open a shapefile in write mode and then
append some new data at the end" ?
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Yes, that's possible too :-)
You can open your shapefile as a vector layer and then use its
provider to add some features:
layer = QgsVectorLayer(...)
provider = layer.getDataProvider()
provider.addFeatures( [ feature ] )
And that's it. I didn't try it now but should work as expected.
addFeatures() expects list of features, but of course you can add them
one by one.
Martin
  </pre>
</blockquote>
</body>
</html>