[Qgis-user] QgsVectorFileWriter
Lionel Roubeyrie
lroubeyrie at limair.asso.fr
Thu Jan 22 01:02:55 PST 2009
Hi Carson,
Le mercredi 21 janvier 2009 à 16:48 +0000, Carson Farmer a écrit :
> > 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...
Sometimes I don't want to get 2 versions of a shp and select the source
shp to be overwritten. If something goes wrong and the source is deleted
first, all is lost...
>
> 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).
A simple test where if a problem occurs, we delete the tmp file...
>
> 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' ;-)
It may be a solution :-)
>
> Carson
>
--
Lionel Roubeyrie
chargé d'études
LIMAIR - La Surveillance de l'Air en Limousin
http://www.limair.asso.fr
More information about the Qgis-user
mailing list