I'm trying to make a script for converting polygons to lines. But I'm having some issues while generating temporary layers.

In this script, I iterate through all the features of the input layer to run the function "qgis:simplifygeometrics" on each of them, after that I merge all layers back together. (This is a simplified case of my script)

However, I'm getting the following error when I run my script : TypeError: 'QgsVectorLayer' object has no attribute '_getitem_' and can't find out why.

Any help is welcome, I'm new to Python and SEXTANTE!


#Creation of the virtual output layer
vOutputLayer = SextanteVectorWriter(vOutputLayer, None, fields, QGis.WKBPolygon, layer.crs())

feats = sextante.getfeatures(layer)
for inFeat in feats:

    #Creation of the virtual input layer
    vInputLayer = QgsVectorLayer("Polygon", "tmp_input_vector", "memory")

    #Creation of the virtual layer for the simplified geometries
    simplifiedLayer = QgsVectorLayer("Polygon", "tmp_simplified_vector", "memory")

    #Simplify Geometries function
    sextante.runalg("qgis:simplifygeometries", vInputLayer, 1.0, simplifiedLayer)

    #Merging of layers
    sextante.runalg("qgis:mergevectorlayers", simplifiedLayer, vOutputLayer, vOutputLayer)

Complete error :

Traceback (most recent call last):
File "C:\OSGeo4W\apps\qgis-dev\python\plugins\sextante\core\GeoAlgorithm.py", line 145, in execute
File "C:\OSGeo4W\apps\qgis-dev\python\plugins\sextante\core\GeoAlgorithm.py", line 238, in checkOutputFileExtensions
if not os.path.isabs(out.value):
File "C:\OSGeo4W\apps\Python27\lib\ntpath.py", line 57, in isabs
s = splitdrive(s)[1]
File "C:\OSGeo4W\apps\Python27\lib\ntpath.py", line 125, in splitdrive
if p[1:2] == ':':
TypeError: 'QgsVectorLayer' object has no attribute '__getitem__'
  • You are using qgis-dev, but the code is written for 1.8. It's not compatible. Check the API docs doc.qgis.org/api – underdark May 30 '13 at 10:35
  • Well, I'm using the API docs since the beginning. I checked again but I don't see anything that wouldn't be compatible... – Dar-Jee May 30 '13 at 14:01
  • "'QgsVectorLayer' object has no attribute 'getitem'" means that you're attempting to apply the index operator on something that is not an iterator (list for example). Why do not do it directly with PyQGIS, it is easier. – gene May 30 '13 at 20:16
  • Yes, I solved the problem by adding a shapefile and not only a layer. Thanks – Dar-Jee Jun 2 '13 at 11:21
  • @gene How so "directly with PyQGIS" I tried to create a memory layer (memoryRes = QgsVectorLayer("MultiLineString", "ResRotate", "memory"), add it (QgsMapLayerRegistry.instance().addMapLayer(memoryRes)), then run the alg (processing.runalg("qgis:explode lines",resLayer,memoryRes)). I get the same error as the original poster. resLayer was previously declared. Any ideas? – user25976 May 1 '14 at 1:38