[Qgis-developer] How to iterate over the vertices of a geometry from python

Ricardo Filipe Soares Garcia da ricardo.garcia.silva at gmail.com
Sun May 13 04:48:04 PDT 2012

Hi list

I'm trying to translate and rotate a geometry using python, in order
to create parallel lines.

For the translation I could use QgsGeometry's translate() method, but
for the rotation I haven't found a ready-made solution. So my current
strategy is to individually rotate each vertex, according to a
specified angle and length. For this i'd like to iterate over the
geometry's vertices.

The problem seems to be that the api methods that return vertex
coordinates (vertexAt(), adjacentVertices, ...) always return a value
even if the specified vertex index is wrong. For example, if I use a
geometry with 5 vertices and call:


-> (0,0)

I cannot know if there is a vertex placed at the (0, 0) coordinates or
if there is no vertex at all.
Is there some way to iterate over a geometry's vertices? Or maybe get
an exception when asking for an invalid one?


___________________________ ___ __
Ricardo Garcia Silva

More information about the Qgis-developer mailing list