1

I am new to QGIS and python.

Titles says it all. I'm modifying a plugin that creates some temporary files (layers) during it's run and I need to loop it a couple times. The algorithm works fine for the first 2 loops then it crashes (usually with a "Bad file descriptor" error). I believe the fact that it's creating all those extra files is causing problems, because even if I run the unmodified version of this algorithm a couple of times the 3rd run always gives me an error.

In more detail what I'm doing. I am modifying the ConcaveHull algorithm so that instead of just taking all the features from a layer and making one big hull for all of them, the user has the option to group the features from input layer by their values in a chosen field and make a separate hull for each group. I use a separate layer (assistant_layer) and copy features from a chosen group onto it, then I feed the layer into the code of unmodified ConcaveHull as the input layer (that part works right), it does its thing, at the end I simply remove all features from my assistant_layer and move onto the next group.

Suspect parts of the code:

#dissolve all Delaunay triangles
progress.setText('Dissolving Delaunay triangles ...')
dissolved = processing.runalg("qgis:dissolve", delaunay_layer,
                                              True, '', None)['OUTPUT']
dissolved_layer = processing.getObject(dissolved)
#save result
progress.setText('Saving data ...')
feat = QgsFeature()
dissolved_layer.getFeatures(QgsFeatureRequest().setFilterFid(0)).nextFeature(feat)
writer = self.getOutputFromName(
                        self.OUTPUT).getVectorWriter(layer.pendingFields().toList(),
                                                     QGis.WKBPolygon, layer.crs())
geom = feat.geometry()

On the 3rd iteration the code crashes on either the "dissolved_layer = processing.getObject(dissolved)" line with the "Bad file descriptor" error or (in rare cases) on "dissolved_layer.getFeatures(QgsFeatureRequest().setFilterFid(0)).nextFeature(feat)" with an error message "'NoneType' object has no attribute 'getFeatures'"

At the end of each loop I delete the writer using "del writer".

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.