I need save selected attributes of layer as CSV with separator. This is my code:
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterVectorLayer('Input', 'Input', types=[QgsProcessing.TypeFile], defaultValue=None))
self.addParameter(QgsProcessingParameterFeatureSink('Output', 'Output', type=QgsProcessing.TypeFile, createByDefault=True, defaultValue= ''))
def processAlgorithm(self, parameters, context, model_feedback):
feedback = QgsProcessingMultiStepFeedback(1, model_feedback)
results = {}
outputs = {}
alg_params = {
'FIELDS_MAPPING': [{'expression': 'FID',
'length': 10,
'name': 'FID',
'precision': 0,
'type': 10},
],
'INPUT': parameters['Input'],
'OUTPUT': parameters['Output']
}
results['Result'] = processing.run('qgis:refactorfields', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
outputs['Outputs'] = results['Result']['OUTPUT']
crs = QgsCoordinateReferenceSystem("EPSG:5514")
uri = outputs['Outputs']
layer = QgsVectorLayer(uri, 'name', 'ogr' )
QgsVectorFileWriter.writeAsVectorFormat(layer, 'C:/Users/xxxx/OneDrive/xxxx', "utf-8", crs, "CSV", layerOptions=["GEOMETRY=AS_YX", "SEPARATOR=SEMICOLON"])
return outputs
Problem is that the CSV is exported, but with comma not separator.
In layerOptions I have I want separator as delimiter, but it isn´t working. I can´t find mistake, maybe in Output?