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?

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

2 Answers 2

2

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.

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

1
  • 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.
    Commented Jul 31, 2015 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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