I have a vector layer with lots of features and I'd like to create a new layer in Python, containing only a subset of those features.
To be more specific, I downloaded OpenStreetMaps data of Austria (http://download.geofabrik.de/europe/austria-latest.osm.pbf) and I'd like to extract features with "leisure"=>"playground" and put them to a new layer. I would like to create about 20 layers with various key-value pairs extracted from the original OSM data.
The problem is, that my current implementation is too slow:
layer = iface.layerTreeView().selectedLayers() layer_new = layer.materialize(QgsFeatureRequest().setFilterExpression('("other_tags" LIKE \'%"leisure"=>"playground"%\') OR ("leisure" = \'playground\')'))
On Austria's multipolygons layer, it takes about 2 minutes. On Corsica's multipolygon layer, which has much less features, it takes just few seconds. But I need it to run also on larger countries.
When I converted the Austria's OSM data to a SpatiaLite database and ran this query in the spatialite-gui client:
SELECT COUNT(*) FROM multipolygons WHERE other_tags LIKE '%"leisure"=>"playground"%' OR leisure='playground';
It took about four seconds (the result was 4708).
Is there any way to speed up the processing in the QGIS Python console or a script?