2

I'm copying a subset of features from a shapefile based QgsVectorLayer (polyline type shapefile) to a memory based QgsVectorLayer('LineString', layername ,'memory'):

self.lyr_flightlines_selected.startEditing()

selected = []
for f in self.lyr_flightlines.getFeatures(QgsFeatureRequest().setFilterExpression(u'"id"={}'.format(selected_id))):
                feat = QgsFeature()
                feat.setGeometry(f.geometry())
                feat.setAttributes(f.attributes())
                selected.append(feat)

                print f.geometry().type(), feat.geometry().type()


self.lyr_flightlines_selected.dataProvider().addFeatures(selected)
self.lyr_flightlines_selected.commitChanges()

Selected layer features are presented on the map without a problem, I can also access attributes of features I copied into the selection layer. But if I try to access the geometry I get an instance of QgsGeometry, but its type() returns unknown geometry. And if I print for example feat.geometry().asPolyline() I get an empty list. I don't know why, because the features are visible on map?! hence they have to have valid geometry. What am I missing here?

(Using QGIS 2.8.2)

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.