Skip to content

Commit

Permalink
Ajout de la méthode V3 pour filewritter
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Nov 21, 2023
1 parent e54e3fe commit f8c68c1
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/fonctions-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,27 @@ QgsVectorFileWriter.writeAsVectorFormat(

```

??? "Pour la version avec `writeAsVectorFormatV3`"
Il faut désormais donner le contexte pour une éventuelle reprojection que l'on trouve dans la classe
**QgsProject** : `QgsProject.instance().transformContext()`.

L'ensemble des options se donne via une nouvelle variable `QgsVectorFileWriter.SaveVectorOptions()`.

```python
options = QgsVectorFileWriter.SaveVectorOptions()
options.driverName = 'CSV'
options.fileEncoding = 'UTF-8'
options.layerOptions = ['CREATE_CSVT=YES', 'SEPARATOR=TAB']

base_name = QgsProject.instance().baseName()
QgsVectorFileWriter.writeAsVectorFormatV3(
layer_info,
join(QgsProject.instance().homePath(), f'{base_name}.csv'),
QgsProject.instance().transformContext(),
options,
)
```

!!! warning
Ajouter une couche raster et retester le script ... surprise 🎁

Expand Down

0 comments on commit f8c68c1

Please sign in to comment.