I have an excel file with x and y. how can I use this excel file in qgis' python console as point vector layer to make polygon with all the points in the file.(it is important for me to use python)
-
Can you clarify more, you want to create one polygon from all points in the excel file ? and do you want it specially with python or you are okay to use QGIS features to import the file ?– ShikoCommented Sep 26, 2016 at 15:10
-
I edited the question– Mahdi.MCommented Sep 26, 2016 at 16:19
-
1Perhaps this post might help: How to draw polygons from the python console?– JosephCommented Sep 27, 2016 at 13:57
-
I saw this document before, but my problem is how to read the points from an external file, and not adding the points manually.?– Mahdi.MCommented Sep 27, 2016 at 14:33
-
Can you edit your question and include a sample screen shot of what your excel/data looks like so we can see the structure?– artwork21Commented Sep 27, 2016 at 17:09
|
Show 2 more comments
1 Answer
PyQGIS supports delimited files including CSV. For example in the QGIS Python Console you could do the following:
uri = "file:///C:/data/points.csv?type=csv&xField=x&yField=y&spatialIndex=no&subsetIndex=no&watchFile=no"
vlayer = QgsVectorLayer(uri, 'My Points', "delimitedtext")
Just replace the xField and yField variables with the x,y column names in your CSV.