I want to remove specific fields that I don't need from multiple shapefiles stored directly in memory (the raw file data stored in a variable).
Unfortunately I haven't found any way to do this without having to write those files on disk, loading them, removing the unwanted fields, then reloading the files to memory and deleting the copy on the disk. And due to the shapefiles sizes, it takes a lot of time that could be shortened.
I only know PyQGIS so far, but I'm not bounded to it.
I actually do the following (using disk):
to_keep = ['Layers', 'I want', 'To keep'] vl = QgsVectorLayer(path, "tmp", "ogr") attrib = vlIn.attributeList() for elem in to_keep: i = vl.dataProvider().fieldNameIndex(elem) del attrib[i] vl.dataProvider().deleteAttributes(attrib) vl.updateFields() QgsVectorFileWriter.writeAsVectorFormat(vl, path, "utf-8", crs, "ESRI Shapefile")
Note : Shapefiles are downloaded from internet and are zipped.