2

I'm making a plugin for Quantum GIS in python. I have a polygon layer and want to create a new feature.

So far, I have this because I need a polygon geometry to add the feature:

surface = QgsGeometry.fromPolygon (polygon)

The problem is that I do not create a polygon. I have a list of points where I want to place the polygon.

Can anyone help?

  • you would probably get a quicker answer by googling for QgsGeometry.fromPolygon – vinayan Jul 24 '13 at 6:53
1

You're creating a feature, but you're missing the step where you add this feature to the layer. Read through this page and replicate the samples. You'll work it through in no time.

http://www.qgis.org/pyqgis-cookbook/vector.html#add-features

  • The linked chapter in the cookbook concerns only point geometries. Polygons seem more complicated, simply substituting "polygon" for "point" and a list of vertices for a single vertex doesn't work. So your link is not directly applicable in OP's (and my) case. – Pavel V. Jul 31 '15 at 8:02
1

I just solved the same problem. The Cookbook (linked by Dan) is my main source, but this time it shows only how to make points, not polygons. I've solved it with gene's answer elsewhere:

surface = QgsGeometry.fromPolygon ([points])

Assumming you have your points stored in a list named points. Don't forget the square brackets around the list's name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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