Wednesday, 11 September 2013

How to create a Layer from a list of points in PyQgis

How to create a Layer from a list of points in PyQgis

I`ve developed an algorithm that generated an two dimensional array with
points. Each subList of this array must be displayed as an polygon on the
map view, and the recently created Vectors should be displayed in the map
legend. And the points must be connected in the order that they stand
within the lists.
Info: I'm using Quantum GIS 1.8.0 with Python 2.7.2 installed on it.
The code is basically this:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
vlayer = qgis.utils.iface.activeLayer()
provider = vlayer.dataProvider()
feat = QgsFeature()
allAttrs = provider.attributeIndexes()
provider.select(allAttrs)
provider.nextFeature(feat)
geom = feat.geometry()
x = geom.asPolygon()
#after this i make some processing with points within the vector layer
#And i do this to create the two dimentsional array (this is just an example)
layersPoints = []
layersPoints.append([])
layersPoints[a].append(x[0][i])
So, what i need is to create a polygon layer connecting the points for
each a in layersPoints[a], and display it on the map view.
Thanks in advance.

No comments:

Post a Comment