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 ?Shiko– Shiko2016年09月26日 15:10:22 +00:00Commented Sep 26, 2016 at 15:10
-
I edited the questionMahdi.M– Mahdi.M2016年09月26日 16:19:58 +00:00Commented Sep 26, 2016 at 16:19
-
1Perhaps this post might help: How to draw polygons from the python console?Joseph– Joseph2016年09月27日 13:57:26 +00:00Commented 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.M– Mahdi.M2016年09月27日 14:33:44 +00:00Commented 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?artwork21– artwork212016年09月27日 17:09:33 +00:00Commented Sep 27, 2016 at 17:09
1 Answer 1
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.
answered Oct 15, 2016 at 3:31
default