QgsVectorLayer from delimitedtext fails

المشرف العام

Administrator
طاقم الإدارة
I am having trouble loading csv files into layers using QgsVectorLayer().

I know this looks like a repeat, but I have carefully read

Create a script to add delimited text layer in QGIS

and

http://hub.qgis.org/issues/7491

but still cannot get it work.

An example of my data file, test.csv:

Index,y,x0,37.7646618,-122.49608581,37.777494,-122.4163112,37.717707,-122.39970563,37.732284,-122.4981184,37.749998,-122.392333My code:

import osimport urllibimport pathlibfrom qgis.core import QgsVectorLayerlocal_path = 'C:\dev\FCMS_conflation\data\TMC_nodes.csv'abspath = os.path.abspath(local_path)params = {'delimiter': ',', 'decimalPoint': '.', 'xField': longitude, 'yField': latitude}uri = "%s?%s" %(pathlib.Path(abspath).as_uri(), urllib.unquote(urllib.urlencode(params)))layer = QgsVectorLayer(uri, node_layer, "delimitedtext")The formatted URI looks like:

[] uri>>> 'file:///C:/dev/FCMS_conflation/data/TMC_nodes.csv?decimalPoint=.&delimiter=,&xField=longitude&yField=latitude'I have tried many variations of the parameters, including the crs and type. But no matter what I try, I cannot create a valid layer.

[] layer.isValid()>>> FalseI have verified that I can add the file using the QGIS gui. I even tried using the uri provided by layer.metadata from within the Python plugin.

I am using QGIS 2.10.1 on Windows 7 64-bit machine.



أكثر...
 
أعلى