What could cause the layer.materialize() function to not copy all the features within a layer?
Similar Post: layer.materialize() does not copy all features
Steps to reproduce:
Drag an s57 file in qgis to load the layers contained within
Choose one layer and convert it to a geopackage file (I chose the "LIGHTS" layer. Further experimenting revealed that this issue does not occur with some layers)
Remove all layers except the geopackage layer created in step 2
Execute the following code to try to create a memory layer from the geopackage layer chosen in step 2:
for curLayer in QgsProject.instance().mapLayers().values():
request = QgsFeatureRequest().setFilterFids(curLayer.allFeatureIds())
print(request.filterFids())
clone = curLayer.materialize(request)
print(clone)
QgsProject.instance().addMapLayer(clone)
Result: A cloned layer with all the attributes but none of the features.
Upon further research I realized something of note:
After creating the geopackage layer in step 2, I deleted all columns (attributes) of the layer that contained null values for any features. After doing so, I got a memory layer containing all features ids.