[QGIS-Developer] QgsVectorFileWriter for GeoJSON
Nyall Dawson
nyall.dawson at gmail.com
Wed May 22 17:08:39 PDT 2019
On Thu, 23 May 2019 at 02:02, matteo <matteo.ghetta at gmail.com> wrote:
>
> Hi all,
>
> I cannot export a layer as GeoJSON using a very simple syntax:
>
> error = QgsVectorFileWriter.writeAsVectorFormat(layer=vl,
> fileName="/home/matteo/Desktop/my_json.geojson",
> driverName="GeoJSON")
>
> I always get an error like:
>
> TypeError: QgsVectorFileWriter.writeAsVectorFormat(): arguments did not
> match any overloaded call:
> overload 1: 'driverName' is not a valid keyword argument
> overload 2: 'driverName' is not a valid keyword argument
> overload 3: 'driverName' is not a valid keyword argument
>
It's a rubbish error message. Blame sip. It should be saying:
"arguments did not match any overloaded call:
missing 1 required positional argument: 'fileEncoding'"
Because, as the dox show, fileEncoding is a required argument. And
indeed, this works fine for me:
error = QgsVectorFileWriter.writeAsVectorFormat(layer=iface.activeLayer(),fileEncoding='UTF-8',fileName='/home/nyall/Temporary/test.geojson',driverName='GeoJSON')
Nyall
More information about the QGIS-Developer
mailing list