[Qgis-developer] vector writer : how to append new data to existing shapefile ?

Michaël Douchin michael.douchin at laposte.net
Wed Dec 12 11:43:51 EST 2007


Sorry martin, I made a mistake in my previous question: it is "new 
points" and not "new lines" I want to add
Let me explain my problem with more precision..

I scan a directory containing csv files. Each file contains several 
data. One of the data is "date".
I would like to write a single shapefile for each date encountered 
during my processing..
That is why I would like to know how to open an existing shapefile (with 
data on it)  in writing mode, and then append the new data from the csv 
file.

Example :
A shapefile called 071212.shp exists.
My script open a csv file with the date "071212" --> I want to add the 
data of this csv file to 071212.shp
If I use :
writer = QgsVectorFileWriter("071212.shp"), "CP1250", fields, 
QGis.WKBPoint, None)
it doesn't do anything.

In an short way "Is it possible to open a shapefile in write mode and 
then append some new data at the end" ?

Thanks a lot
Michael



Martin Dobias a écrit :
> On Dec 12, 2007 4:48 PM, Michaël Douchin <michael.douchin at laposte.net> wrote:
>   
>> Hi all,
>> After a re-reading of Martin's page :
>> http://wiki.qgis.org/qgiswiki/PythonBindings#head-1a654755a57432eb139ca1344f35379e404ec10b
>> I haven't find how to add new lines to an existing shapefile with the
>> python bindings and the command :
>>
>> writer = QgsVectorFileWriter("my_shapes.shp", "CP1250", fields, QGis.WKBPoint, None)
>>
>> Is it possible yet ?
>>     
>
> Hi,
>
> yes, it is. The only changes you have to do:
> - use QGis.WKBPolyline instead of QGis.WKBPoint when creating the
> vector file writer
> - assign geometry with type polyline to the features, e.g.:
> fet.setGeometry(QgsGeometry.fromPolyline( [ QgsPoint(10,10),
> QgsPoint(20,20) ] ))
>
> Regards
> Martin
>
>
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20071212/5b428ca5/attachment.html


More information about the Qgis-developer mailing list