1

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:

  1. Drag an s57 file in qgis to load the layers contained within

  2. 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)

  3. Remove all layers except the geopackage layer created in step 2

  4. 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.

New contributor
Jonathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
7
  • 1
    I proceeded with the ENC file (S-57 format) and executed your four steps and did not get anything weird i.e. a cloned layer with all the attributes including features.
    – Taras
    Commented Dec 11 at 20:00
  • @Taras What s57 file did you use? I used several files from this website: charts.noaa.gov/InteractiveCatalog/nrnc.shtml#mapTabs-2 Specifcally, I tested with the following charts: US5NYCFJ.000 US5FL54M.000
    – Jonathan
    Commented Dec 11 at 20:24
  • I used files from the Office of Coast Survey: charts.noaa.gov/ENCs/ENCs.shtml
    – Taras
    Commented Dec 11 at 20:28
  • One more question, thank you for your quick replies. @Taras What operating system are you running qgis on? And what version? I am running the latest version of qgis on linux.
    – Jonathan
    Commented Dec 11 at 20:31
  • Also, the layer I performed the 4 steps with is the "LIGHTS" layer.
    – Jonathan
    Commented Dec 11 at 20:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.