2

I'm using QGIS 2.18.14 Las Palmas on Windows 8.1 I tried to import CSV layer to QGIS using this script:

uri = 'file://D:/26mei.csv?d?delimiter=%s&xField=%s&yField=%s' % (",", "Lon", "Lat")
layer_csv = QgsVectorLayer(uri, 'paramHilal', 'delimitedtext')
QgsMapLayerRegistry.instance().addMapLayer(layer_csv)

The last line is to add the CSV layer to layer panel in QGIS, but it didn't appear. It could be because the layer is not valid. I knew because I have tried layer_csv.isValid() and it return False. But I don't know where my mistake is. Does anyone knows why my script is not work?

PS: I have tried this on QGIS 2.8 Wien on Ubuntu 16.04 and it worked just fine.

1 Answer 1

3

Just a tip according to this: Use PyQGIS to import CSV and draw points using different color

use /// instead // after file.

1
  • It's working, there is a typo in the cookbook in the description but in the example it uses triple slash /// then I thought double slash // makes more sense since URL in web browser also uses //
    – Ayato
    Commented Dec 29, 2017 at 10:18

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.