2

I am trying to export a layer same to like this question: https://gis.stackexchange.com/a/435753/215676

But the difference is I'd like to do it in PyQGIS with QgsVectorFileWriter. Is there a way to use that 'Use Key/Value' option in codes?

Here is my command which is not working:

QgsVectorFileWriter.writeAsVectorFormat(
    layer,
    outfile,
    'utf-8',
    QgsCoordinateReferenceSystem('EPSG:4326'),
    'GeoJSON',
    layerOptions=['COORDINATE_PRECISION=8'],
    onlySelected=True
    )

And I have this warning:

'DeprecationWarning: QgsVectorFileWriter.writeAsVectorFormat() is deprecated'

As I understand because of having those JSON fields, it works without JSON fields.

3
  • 1
    Link-only Answers are deleted because they lack an Answer. This appears to be a link-only Question. Please Edit it to contain sufficient details that it is not required to follow the link to understand the Question.
    – Vince
    Commented May 29, 2023 at 15:47
  • How are you exporting a layer to get the "Use Key/Value" option to show up? I dont see it when I right-click the layer and Export - Save features As.
    – Bera
    Commented May 29, 2023 at 17:08
  • It is possible when your layer has a JSON field, and probably your QGIS vers. should be 3.30 or more Commented May 29, 2023 at 20:22

1 Answer 1

4

'DeprecationWarning: QgsVectorFileWriter.writeAsVectorFormat() is deprecated' is a warning, not an error. If you check the documentation for that method you see that using QgsVectorFileWriter.writeAsVectorFormatV3() is recommended instead.

Once you adjust your code to use that method, the "error" will disappear.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.