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)
Asked
Active
Viewed 683 times
2
-
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 Sep 26 '16 at 15:10
-
I edited the question – Mahdi.M Sep 26 '16 at 16:19
-
1Perhaps this post might help: How to draw polygons from the python console? – Joseph Sep 27 '16 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 Sep 27 '16 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 Sep 27 '16 at 17:09
-
just imagine we have a closed line like this: [-76.515681 95.210066; -76.216625 87.733669; -77.113793 78.462936; -77.113793 71.734179; -76.814737 61.715806; -64.104862 46.314428; -63.955334 59.921471; -63.805806 66.799756; -63.506750 71.883707; -62.759110 77.864825; -62.609582 83.845942; -62.908638 91.770924; -66.945893 95.509122; -76.515681 95.210066] – Mahdi.M Sep 27 '16 at 17:36
-
Joseph's comment shows you a way how to do it, and parsing CSV or XLS is rather StackOverflow question – adamczi Sep 28 '16 at 11:43
1 Answers
0
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.
GeospatialPython.com
- 1,502
- 8
- 10