I am new to both Python and QGIS.
Here's a sample of my code:
unique = layer.uniqueValues(index) attributes = layer..dataProvider().fields().toList() assistant_layer = QgsVectorLayer("Point", "temporary_points", "memory") assistant_pr = assistant_layer.dataProvider() assistant_layer.startEditing() assistant_pr.addAttributes(attributes) for i in unique: features = vector.features(layer) for f in features: idVar = f[fieldName] if unicode(idVar).strip() == unicode(i).strip(): assistant_pr.addFeatures([f]) assistant_layer.commitChanges() delone_triangles = processing.runalg("qgis:delaunaytriangulation", assistant_layer, None)['OUTPUT'] #rest of the code is irrelevant to the question
Basically I'm trying to create a layer that has the same set of properties as my input layer. Much in the same way as here How to create a new empty vector layer programmatically? except there the Attributes have been defined in code, I want mine to load them from another input layer. Then I want to copy a specific subset of features onto that layer. Something however seems to be wrong with my method.
The broader issue that I'm trying to solve here is that I need to feed a subset of features from a layer into an algorithm that takes a whole layer as its input (specifically "qgis:delaunaytriangulation"), so my intended solution is to create another layer and then copy specific features that fit the criteria onto it. However, whereas normally qgis:delaunaytriangulation outputs a path to a file containing the triangulation, when I do the above it returns a path to a file that doesn't exist. I figure it's because either my assistant_layer or the method of copying features onto it is faulty.