[Qgis-user] QgsVectorFileWriter
Carson Farmer
carson.farmer at gmail.com
Wed Jan 21 08:48:51 PST 2009
> In this way, it would be better to save in a temporary shapefile first,
> and if the process finishes successfully, remove the destination
> shapefile and copy the temporary shp to the new location.
>
hmm, I don't know about this...
Firstly, it's only useful to do this if you're concerned about the
initial file, but since you appear to be writing to a tmp directory,
this probably isn't all that critical...
Secondly, this creates the possibility that if something goes wrong, you
have TWO useless files lying about on your system (one you were trying
to replace, and the other that didn't finish writing properly).
The better implementation would probably be to use the memory provider
to create a temporary QgsVectorLayer in memory, and if the process
finishes successfully, remove the old version and write the memory layer
to file. Of course, this only works if you're working with relatively
'small' layers, if you have huge vector layers (> 500,000 features) then
you're probably better off just writing directly to file...
mem_layer = QgsVectorLayer('Point', 'layer_name', 'memory')
you'll have to double check the above, this is just from 'memory' ;-)
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