2

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)

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 26, 2016 at 15:07
7
  • 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 ? Commented Sep 26, 2016 at 15:10
  • I edited the question Commented Sep 26, 2016 at 16:19
  • 1
    Perhaps this post might help: How to draw polygons from the python console? Commented 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.? Commented 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? Commented Sep 27, 2016 at 17:09

1 Answer 1

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.

answered Oct 15, 2016 at 3:31

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.