[Qgis-user] QgsVectorFileWriter

Carson Farmer carson.farmer at gmail.com
Wed Jan 21 06:27:27 PST 2009


Cedric,
> Hi list
>
> in a python plugin im using QgsVectorFileWriter.writeAsShapefile to write a shapefile to the disk.
>
> The first time I use a certain file name/path (e.g /tmp/foo.shp), it works properly. If I try to rerun the script, it fails saying: 
> ERROR 1: /tmp/foo.shp is not a directory.
>
> It looks like it is not possible to replace an existing shapefile that way. Am I correct? Do I have to manage the files myself (i.e. delete them before writing the new file)? Or is there another way to replace an existing shapefile?
>   

Yes you are correct, you cannot overwrite shapfiles like that... but you 
can do the following first:

QgsVectorFileWriter.deleteShapefile( "path/to/the/shapefile/shp" )


Cheers,

Carson

-- 
Carson J. Q. Farmer
ISSP Doctoral Fellow
National Centre for Geocomputation (NCG),
Email: Carson.Farmer at gmail.com
Web:   http://www.carsonfarmer.com/
       http://www.ftools.ca/





More information about the Qgis-user mailing list