[Qgis-developer] VectorFileWriter

Nicolas B. piklas at gmail.com
Mon Nov 26 04:43:41 EST 2007


Hi list !
I'm developping a QGIS plugin using Python Bindings
I recently managed to automatically create a shp layer from a csv file using
this code
**************************************************************************************************************************************************

uri =
"C:\G77\driftx_multi_level\txtfile.csv?delimiter=%s&xField=%s&yField=%s" %
(";", "x", "y")
vlayer = QgsVectorLayer(uri, "vectorial puff", "delimitedtext")
error = QgsVectorFileWriter.writeAsShapefile(vlayer,
"python/plugins/DriftxPlugin/data/vectorial_puff.shp", "CP1360")

if error == QgsVectorFileWriter.NoError:QgsMapLayerRegistry.instance
().addMapLayer(vlayer)QMessageBox.warning(self.iface.getMainWindow(),
self.MSG_BOX_TITLE, ("shapefile created !"), QMessageBox.Ok, QMessageBox.Ok)
else:
QMessageBox.warning(self.iface.getMainWindow(), self.MSG_BOX_TITLE, ("Error
creating your shapefile\n"), QMessageBox.Ok, QMessageBox.Ok)

******************************************************************************************************************************************************
The code works but i still have the following error message just before the
created shp loads " Note: the following lines were not loaded because Qgis
was unable to determine values for the x and y coordinates:"
I don't understand why. Any ideas ??

As you can see in the code, i create the shp in a data folder in my plugin
directory.
The main problem is if i use my plugin again, the shp doesn't want to be
created again because it already exists in the data folder.
I'd like to destroy the previous existing folder every time the
VectorFileWriter is launched. How can i do that ?

Finally, i'd like to apply symbology properties (graduated colors, field to
use, number of classes...) on the loaded shp.
Is there a Qgs class to do this ?

Thanks 4 answers.

Nick BOZON
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20071126/4699811b/attachment.html


More information about the Qgis-developer mailing list