1

I've been trying to access the polygons of a dissolved layer in QGIS, and every time I query them, I get an empty polygon back. My procedure is as follows:

  1. I start with a layer of polygons, and use the dissolve feature to dissolve some of them (this is not a problem, and the layer is generated, and I can see it, highlight it, and interact with its features)
  2. In the python console, I find a feature in this layer, and type:

    feature.geometry().asPolygon()
    

    which returns

    []
    

    even though I can highlight it in the map interface.

Am I misunderstanding the scope of the asPolygon() function?


I figured out my mistake! To all future readers: the dissolve function may output multiple polygons as a single feature, meaning that they are a multipolygon, not a polygon. Thus, the function that should be called is geometry().asMultiPolygon() to return the co-ordinates.

  • Can you explain what you mean by "access the polygons" please? Do you just want to return the geometry of the selected polygon(s)? – Joseph Jun 29 '17 at 9:21
  • Yes, this is what I want to see. Normally when I apply asPolygon() to a feature, I get a list of co-ordinates for the boundary, but here I only get an empty list. – Assaf Bar-Natan Jun 29 '17 at 15:25
  • Could you please edit your question to include the full code you used? The asPolygon() method seems to work fine for me. – Joseph Jun 30 '17 at 11:45

Browse other questions tagged or ask your own question.