I wrote the following script to save only the selected features after have a selection by location done. But I have got an error when the saving line is executed. I don't want to load these layers in the map canvas.
How could I do it right?
I'm using QGIS 2.18.17 and Linux Mint 19.
#
import processing
# Load vector layers
rio = QgsVectorLayer('/home/tiago/Documentos/PRIM_Mineracao/rio/mata/rio_doce.shp', 'rio_doce','ogr')
drenagem = QgsVectorLayer('/home/tiago/Documentos/PRIM_Mineracao/rio/mata/rio_mata_disol.shp','rio_mata_disol','ogr')
# Selection by Location
sel = processing.runalg("qgis:selectbylocation", drenagem, rio,['intersects'],0,0)
# Save selected features
crs = QgsCoordinateReferenceSystem("EPSG:4674")
nome1 = '/home/tiago/Documentos/PRIM_Mineracao/rio/mata/'
nome2 = 'rio_doce_P'
caminho = nome1+nome2+'.shp'
QgsVectorFileWriter.writeAsVectorFormat(sel, caminho, crs, "ESRI Shapefile", True)
That's the error message thar I've got:
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: arguments did not match any overloaded call:
writeAsVectorFormat(QgsVectorLayer, str, str, QgsCoordinateReferenceSystem, driverName: str = '', onlySelected: bool = False, errorMessage: str = '', datasourceOptions: Sequence[str] = [], layerOptions: Sequence[str] = [], skipAttributeCreation: bool = False, newFilename: str = '', symbologyExport: QgsVectorFileWriter.SymbologyExport = QgsVectorFileWriter.NoSymbology, symbologyScale: float = 1, filterExtent: QgsRectangle = None, overrideGeometryType: QgsWKBTypes.Type = QgsWKBTypes.Unknown, forceMulti: bool = False, includeZ: bool = False, attributes: Sequence[int] = [], fieldValueConverter: QgsVectorFileWriter.FieldValueConverter = nullptr): argument 1 has unexpected type 'dict'
writeAsVectorFormat(QgsVectorLayer, str, str, QgsCoordinateTransform, driverName: str = '', onlySelected: bool = False, errorMessage: str = '', datasourceOptions: Sequence[str] = [], layerOptions: Sequence[str] = [], skipAttributeCreation: bool = False, newFilename: str = '', symbologyExport: QgsVectorFileWriter.SymbologyExport = QgsVectorFileWriter.NoSymbology, symbologyScale: float = 1, filterExtent: QgsRectangle = None, overrideGeometryType: QgsWKBTypes.Type = QgsWKBTypes.Unknown, forceMulti: bool = False, includeZ: bool = False, attributes: Sequence[int] = [], fieldValueConverter: QgsVectorFileWriter.FieldValueConverter = nullptr): argument 1 has unexpected type 'dict'
writeAsVectorFormat(QgsVectorLayer, str, QgsVectorFileWriter.SaveVectorOptions, newFilename: str = '', errorMessage: str = ''): argument 1 has unexpected type 'dict'
QgsVectorFileWriter.writeAsVectorFormat(rio, caminho, "utf-8", crs, "ESRI Shapefile", onlySelected=True)