I've been trying to create a plugin in QGIS that browse an excel sheet containing XY coordinates (points) and convert them (automatically) to a shapefile (polygon on this case). If done manually, I would add the data from the CSV file and link the points one by one to get a polygon. But am trying to automate this procedure for the users by creating this plugin.

My first question would be : is this even possible ? If so, can someone please indicate how it could be done, expecially the python code that can be used.

1 Answer 1


You load the points into a list and create the polygon from the list of points:

layer =  QgsVectorLayer('Polygon', 'polygon' , "memory")
pr = layer.dataProvider() 
polygon = QgsFeature()
points = [QgsPoint(50,50),QgsPoint(50,150),QgsPoint(100,150)] 

I found the code here by the way: How to draw polygons from the python console?

The list 'points' can be created in a loop by appending


to the list for all x,y in the spreadsheet.

Not the answer you're looking for? Browse other questions tagged or ask your own question.