You will need to find some way to determine how to group and order the points.
Depending on the organisation of your source data this may limit the amount of automation possible.
Once that issue is resolved the following two samples may help you get started.
This one will create a new layer with a single polygon connecting all points found in the active layer:
#derive points list from active layer
pointslayer = qgis.utils.iface.activeLayer()
pointsprovider = pointslayer.dataProvider()
pointsprovider.select([]) #no attributes
points=[]
pointsfeature = QgsFeature()
while pointsprovider.nextFeature(pointsfeature):
coord = pointsfeature.geometry().asPoint()
points.append(QgsPoint(coord[0],coord[1]))
points.append(points[0]) # repeat the first point to close the polygon
#create polygon from points list
polylayer = QgsVectorLayer("Polygon?crs=" + pointslayer.crs().authid(),\
pointslayer.name()+" as poly", "memory")
polyfeature = QgsFeature()
polyfeature.setGeometry(QgsGeometry.fromPolygon([points]))
polylayer.dataProvider().addFeatures([polyfeature])
QgsMapLayerRegistry.instance().addMapLayer(polylayer)
While this one creates a line in a similar manner:
#derive points list from active layer
pointslayer = qgis.utils.iface.activeLayer()
pointsprovider = pointslayer.dataProvider()
pointsprovider.select([]) #no attributes
points=[]
pointsfeature = QgsFeature()
while pointsprovider.nextFeature(pointsfeature):
coord = pointsfeature.geometry().asPoint()
points.append(QgsPoint(coord[0],coord[1]))
#create line from points list
linelayer = QgsVectorLayer("LineString?crs=" + pointslayer.crs().authid(),\
pointslayer.name()+" as line", "memory")
linefeature = QgsFeature()
linefeature.setGeometry(QgsGeometry.fromPolyline(points))
linelayer.dataProvider().addFeatures([linefeature])
QgsMapLayerRegistry.instance().addMapLayer(linelayer)