<!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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not os.path.exists( "myshape.shp") ): # si le shapefile
n'existe pas<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #we create the new shapefile<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; writer = QgsVectorFileWriter("myshape.shp"), "CP1250",
fields, QGis.WKBPoint, None)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; existe=0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if writer.hasError() != QgsVectorFileWriter.NoError:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "Error when creating shapefile: ", writer.hasError()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else: #when the shapefile exists<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #on ouvre le fichier shape existant<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mylayer = QgsVectorLayer("myshape.shp"), "ma_couche", "ogr")<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myprovider = mylayer.getDataProvider()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; existe=1<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list_fet=[]<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for i in range(0,len(donnees)): #donnees is the list[[]]
containing the data from the csv file<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fet = QgsFeature()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fet.setGeometry(QgsGeometry.fromPoint(
xform.transform(QgsPoint(longitude, latitude)) )&nbsp; )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fet.addAttribute(0, QVariant(local_date) ) #date<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fet.addAttribute(1, QVariant(local_heure) ) #heure locale<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; # .......<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if existe == 0:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; writer.addFeature(fet)&nbsp; # directly add each feature
inside the loop<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if existe == 1:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list_fet.append(fet)&nbsp; # we add the feature in the list
of feature "list_fet" <br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if existe == 1:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myprovider.addFeatures(list_fet)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; #here we add all the
features from list_fet to the shapefile<br>
<br>
*************<br>
<br>
Michael<br>
<br>
Martin Dobias a &eacute;crit&nbsp;:
<blockquote
 cite="mid:e8e7199c0712120855wc993569p1cba19e34f7d3cb8@mail.gmail.com"
 type="cite">
  <pre wrap="">On Dec 12, 2007 5:43 PM, Micha&euml;l Douchin <a class="moz-txt-link-rfc2396E" href="mailto:michael.douchin@laposte.net">&lt;michael.douchin@laposte.net&gt;</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>