1

I'm generating maps with QGis. What I do is generate a bunch of non-spatial data on a set of cities (using VBA), and still using VBA, generate a python code that will automaticaly output general map on the studied territory.

So far, I was importing the data into Qgis with the following code :

lyrData = QgsVectorLayer(u'C:/SomePlace/SomeFile.xlsx', ' ', 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(lyrData)

Which seemed to work, until it started to treat the header of the attributes/columns as data for some territories. Note that this bug is consistent : for some territories it will import header as header and for some it will import header as data...

I tried different things so far : If I import manually (without pyQgis), the bug is still here. I tried renaming the .xlsx file with the name of one that works, but it didn't work.

Another thing I tried is to import the file as an .csv instead of .xslx, but Qgis Cookbook only give exemple to import spatial data csv :

uri = "/some/path/file.csv?delimiter=%s&xField=%s&yField=%s" % (";", "x", "y")
vlayer = QgsVectorLayer(uri, "layer_name_you_like", "delimitedtext")

Or

uri = "file:///some/path/file.csv?delimiter=%s&crs=epsg:4723&wktField=%s" % (";", "shape")

And this, despite the fact that you can manually import CSV files without geometry

Using PyQGIS, is there a way to precise that imported excel files have an header, or is there a way to import csv files without geometry?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 29, 2015 at 8:15

1 Answer 1

2

So I've found out what was it !

I added into the code a column with city names to add as labels on the map. But it only contain a small number of them, and Qgis probably don't like Null values that much...

After replacing them with zeros the importation of the .xlsx files went smoothly ;) !

answered Jul 29, 2015 at 8:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.