Friday 21 April 2017

pyqgis - Use delimited text Vector data provider in QGIS 3.0 Processing Algorithm


I am writing a Processing Algorithm based on this template. Can I populate the QgsProcessingParameterFeatureSink from a delimitedtext provider in a similar fashion to the iface.addVectorLayer() (i.e. the following code snippet) ?


uri = ('file:///{}?'
'type=regexp'
'&delimiter={}'
'&skipLines={}'
'&useHeader=No'
'&trimFields=Yes'

'&xField=field_11'
'&yField=field_12'
'&crs={}'
'&spatialIndex=Yes'
'&subsetIndex=no'
'&watchFile=Yes').format(myFile,
myRe,
countSkips(myFile),
myCrs)


layer = iface.addVectorLayer(uri, 'MY LAYER', 'delimitedtext')

Answer



You don't need to use feature sink parameters for a hard-coded layer like this. Just load it direct via


vl=QgsVectorLayer(uri, 'MY LAYER',  'delimitedtext')

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...