I'm building a QGIS 3 plugin that generates a CSV file and then adds it as a layer to QGIS map. However when I try to create the QgsVectorLayerwith the delimitedtext provider it will no open the CSV file.

I have

f = resFile.replace('\\','/')
uri = 'file://%s?crs=%s&delimiter=%s&xField=%s&yField=%s&decimal=%s' % (f, 'EPSG:4326', ',', 'lon', 'lat', '.')
# return file:///tmp/myfile.csv?crs=EPSG:4326&delimiter=,&xField=lon&yField=lat&decimal=.
resLayer = QgsVectorLayer(resFile, 'Result', 'delimitedtext')
# False

I striped my result csv file to one row one attribute and my lat and lon fields.

Name    lat         lon
a       34.0913004  -118.147289

Chainging ghe qgsVectorLayer data proiver from delimitedtext to org allows me to add the data layer. I've also tried converting csv file line endings and changing the quoting.

I've been trying to pull form this example among others.

I always receive this message in teh DelimitedText Log file:

2018-07-03T10:40:07     WARNING    Errors in file 
2018-07-03T10:40:07     WARNING    File cannot be opened or delimiter parameters are not valid
  • Without seeing more of your code, it looks like your file path is missing a designated directory like C: or D: etc. – cm1 Jul 3 '18 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.