[Qgis-developer] SymbologyExport parameter
Tim Sutton
lists at linfiniti.com
Sat Dec 28 13:18:47 PST 2013
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 <pim at travelingo.nl> 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
> Qgis-developer at lists.osgeo.org
> 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
==============================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20131228/eaa37eae/attachment.html>
More information about the Qgis-developer
mailing list