3

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.

closed as off-topic by Vince, Evil Genius, Mapperz Oct 4 '16 at 13:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – Vince, Evil Genius, Mapperz
If this question can be reworded to fit the rules in the help center, please edit the question.

5

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)] 
polygon.setGeometry(QgsGeometry.fromPolygon([points]))
pr.addFeatures([polygon])
layer.updateExtents()
QgsMapLayerRegistry.instance().addMapLayers([layer])

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

QgsPoint(x,y) 

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.