Hi Tim,
I executed an exact copy of your line of code and got the same error'
This is what I tried:
canvas = iface.mapCanvas()
aLayer = iface.activeLayer()
if aLayer.dataProvider().name() == 'postgres':
writer = QgsVectorFileWriter
error = writer.writeAsVectorFormat(aLayer, r"/tmp/out.shp", "CP1250", None,
"ESRI Shapefile", False, None,"","", False, None,
QgsVectorFileWriter.NoSymbology, 1.0)
if error == QgsVectorFileWriter.NoError:
vlayer = QgsVectorLayer(r"D:\Documenten_Travelingo\SkyDrive Pro\Horeca
routes\Projectbestanden\deBaak Driebergen\Shape bronnen", aLayer.name() +
".shp", "ogr")
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
And the error: Tceback (most recent call last):
File "<input>", line 1, in <module>
File "D:/Documenten_Travelingo/SkyDrive Pro/Horeca
routes/PostgrestoShape.py", line 5, in <module>
error = writer.writeAsVectorFormat(aLayer, r"/tmp/out.shp", "CP1250", None,
"ESRI Shapefile", False, None,"","", False, None,
QgsVectorFileWriter.NoSymbology, 1.0)
AttributeError: type object 'QgsVectorFileWriter' has no attribute 'NoSymbology'
I work with the console of a Dufour 64 bits version on a Windows 8.1 machine.
The qgis_core.dll is present in C:\Program Files\QGIS Dufour\apps\qgis\bin. Can
it be that the windows version is an old compilation because as I understand
the SymbologyExport parameter was just recently added to the source code?
Kind regards
Van: Tim Sutton [mailto:[email protected]]
Verzonden: zaterdag 28 december 2013 22:19
Aan: Pim Verver
CC: [email protected]
Onderwerp: Re: [Qgis-developer] SymbologyExport parameter
Hi
I'm not sure why the Symbology flag is not working (havent time to look sorry)
but a quick fix might be to do this (which worked for me in a quick test):
error = writer.writeAsVectorFormat(aLayer, r"/tmp/out.shp", "CP1250", None,
"ESRI Shapefile", False, None,"","", False, None,
QgsVectorFileWriter.NoSymbology, 1.0)
aLayer.saveNamedStyle("/tmp/out.qml")
(u'Created default style file as /tmp/out.qml', True)
Hope that helps!
Regards
Tim
On Sat, Dec 28, 2013 at 4:25 PM, Pim Verver
<[email protected]<mailto:[email protected]>> wrote:
Hi,
I am using the QGis python console for the use of exporting an active layer
from postgist to a shape file layer. I want to include the symbology as is
possible through the GUI of QGis 2 (Dufour).
I am using the
writeAsVectorFormat<http://www.qgis.org/api/classQgsVectorFileWriter.html#a289af78b5b609fbcb0572aaf505f2822>
method of the QgsVectorFileWriter class, but keep getting the message that
there are "Too many arguments" as if the parameter doesn´t exist. That seems
correct given the fact that the mouse popup for the parameters doesn't indicate
a Symbology parameter. However in the official QGis API the parameter is
mentioned:
http://www.qgis.org/api/classQgsVectorFileWriter.html#a1aac90d30d811d2888d1aab4098ad63c.
The symbology parameter seems tob e added in the latest release (QGis 2)
Am I using it the wrong way or is someting else going on?
The alternative would be save the style als SLD and import the style file after
creating the shape layer, but if I can avoid that ...
The console code sofar:
canvas = iface.mapCanvas()
aLayer = iface.activeLayer()
if aLayer.dataProvider().name() == 'postgres':
writer = QgsVectorFileWriter
error = writer.writeAsVectorFormat(aLayer,
r"D:\Documenten_Travelingo\SkyDrive Pro\Horeca routes\Projectbestanden\deBaak
Driebergen\Shape bronnen\\"+ aLayer.name() + ".shp", "CP1250", None, "ESRI
Shapefile", False, None,"","", False, None, "NoSymbology", 1.0)
# then import the shape file in a new layer
if error == QgsVectorFileWriter.NoError:
vlayer = QgsVectorLayer(r"D:\Documenten_Travelingo\SkyDrive Pro\Horeca
routes\Projectbestanden\deBaak Driebergen\Shape bronnen", aLayer.name() +
".shp", "ogr")
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
Th error is raised at the writeAsVectorFormat method and its parameter
NoSymbology.
Thanx in advance
Kinds regards,
Pim Verver
_______________________________________________
Qgis-developer mailing list
[email protected]<mailto:[email protected]>
http://lists.osgeo.org/mailman/listinfo/qgis-developer
--
Tim Sutton - QGIS Project Steering Committee Member
==============================================
Please do not email me off-list with technical
support questions. Using the lists will gain
more exposure for your issues and the knowledge
surrounding your issue will be shared with all.
Irc: timlinux on #qgis at freenode.net<http://freenode.net>
==============================================
_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer