This might be a simple problem, but how does one load a simple two column CSV with no associated geometric data?

I have given a couple go's via QgsVectorlayer[delimited text, spatialite] types - but none seem to work.

for example:

    theMinistryOf = ':\...\sillyWalks.csv'
    uri = QgsDataSourceURI()
    notQuiteSillyEnough = QgsVectorLayer(uri.uri(), 'skip_step_slide', 'spatialite')


    uri = theMinistryOf+'?delimiter=%s' % (",")
    sillyWalks = QgsVectorLayer(uri, 'sillyWalks', "delimitedtext")

This need is easily fulfilled manually by selecting load vectorlayer, but programmatically?

Can a CSV data-table be loaded via pyqgis without geometry?


The following snippet works for me:

uri = "file:///C:/testdata/somecsv.csv?delimiter=%s" % (";")
lyr = QgsVectorLayer(uri, 'New CSV','delimitedtext')

For reference, if you wanted to add it with geometry:

uri = "file:///C:/testdata/somecsv.csv?delimiter=%s&crs=epsg:4326&xField=%s&yField=%s" % (";", "x", "y")
lyr = QgsVectorLayer(uri, 'New CSV','delimitedtext')

Most importantly, make sure the correct delimiter has been specified!

| improve this answer | |
  • 1
    I have to give you points for posting so quick with responses which indeed work. But I have figured out another solution - also posed for others references. – Katalpa Feb 7 '15 at 18:58

Wow. Way simpler than I expected. Should not have supposed that 'ogr' wouldn't be able.

    someTableLayer = QgsVectorLayer(ministryOf.csv, 'sillyWalks', 'ogr')
| improve this answer | |

Your Answer

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

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