2

I'm trying to run the following algorithm which runs fine when I select a layer I imported from the CSV file in question but not when I just try to run if from the file itself.

input = '/media/path/points.csv=csv&detectTypes=yes&xField=long&yField=lat&crs=EPSG:103172&spatialIndex=no&subsetIndex=no&watchFile=no'
layers = QgsProject.instance().mapLayersByName('points')
#input = layers[0]
output = '/media/path/outline.shp'
params = { 'DATE_FORMAT' : '', 'GROUP_FIELD' : 'rid', 'INPUT' : input, 'ORDER_FIELD' : 'vertex_ind', 'OUTPUT' : output }
res = processing.run('qgis:pointstopath', params)

I'm getting:

File "/usr/share/qgis/python/plugins/processing/core/Processing.py", line 137, in runAlgorithm raise QgsProcessingException(msg) _core.QgsProcessingException: Unable to execute algorithm Could not load source layer for INPUT: /media/path/points.csv=csv&detectTypes=yes&xField=long&yField=lat&crs=EPSG:103172&spatialIndex=no&subsetIndex=no&watchFile=no not found

asked Aug 12, 2019 at 14:03
2
  • 1
    Try replacing layers = QgsProject.instance().mapLayersByName('points') with layers = QgsVectorLayer("file:///" + input, "point", "delimitedtext") and then replace 'INPUT' : input with 'INPUT' : layers in params. Commented Aug 12, 2019 at 14:36
  • This seems to get me closer, it looks to be reading the file but now I'm getting: TypeError: 'QgsVectorLayer' object is not subscriptable Commented Aug 12, 2019 at 16:52

1 Answer 1

2

With Joseph's insight this is what worked.

input_uri = 'file:////media/path/points.csv?delimiter=,&xField=long&yField=lat&crs=espg:103172&spatialIndex=no&subsetIndex=no&watchFile=no'
output_uri = '/media/spath/out_paths.shp'
lyr = QgsVectorLayer(input_uri, 'New CSV','delimitedtext')
params = { 'DATE_FORMAT' : '', 'GROUP_FIELD' : 'rid', 'INPUT' : lyr, 'ORDER_FIELD' : 'vertex_ind', 'OUTPUT' : output_uri }
res = processing.run('qgis:pointstopath', params)
answered Aug 12, 2019 at 17:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.