[Qgis-user] Loading CSV using pyqgis
Michael Schulz
mandschulz at googlemail.com
Mon Feb 6 07:22:46 PST 2017
Dear QGIS-Users,
I try to add non-geographic table data from a CSV file using the python
console (QGIS 2.14). The idea is to load this data from a URL. The
following lines work and the table is added as a layer:
lyrData = QgsVectorLayer('http://intranet/637D573E40113572-export.csv',
'einwohner_dt', 'ogr')
lyrData.dataProvider().setEncoding(u'latin1')
QgsMapLayerRegistry.instance().addMapLayer(lyrData)
When the table is added all fields are imported/converted as strings. Now
it seems that one way to overcome this issue is using the 'delimitedtext'
provider instead of 'ogr'. However I couldn't get this provider to work
with a URL. On the ogr csv-driver page I read that ogr version >= 2 should
accept an open option "AUTODETECT_TYPE=YES', that should do something
similar. But I couldn't find a way how to pass this option to the data
provider. I tried adding it to the datasource URI like this:
lyrData = QgsVectorLayer('
http://mapbender/637D573E40113572-export.csv|AUTODETECT_TYPE=YES',
'einwohner_dt', 'ogr')
but to no avail. Is that possible somehow?
Thanks, Michael
--
-----------------------------------------------------------
Michael Schulz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20170206/643a0449/attachment.html>
More information about the Qgis-user
mailing list