How to automatically detect X/Y fields in CSV

178 views Asked by At

I am developing a plugin in QGIS that needs to import a csv file at some point. To do that, I use the common process :

uri = "file:///"+fileName+"?delimiter=%s&xField=%s&yField=%s" % (";", "X", "Y")
layer = QgsVectorLayer(uri, name, "delimitedtext")

The problem is, I cannot know in advance how the X and Y fields are written in the file (it may be "COORDX" or "COX" or whatever) and I do not particularly want to ask the user to provide them manually.

Now, I know that whenever you "manually" import a CSV file into QGIS, this latter is able to auto-detect the X and Y fields. I would like to know if there is a way to use this function to detect them, or if I'll have to do it by myself. (Bonus point to the one who can indicate if there is a way to auto-detect the delimiter as well!)

0

There are 0 answers