Hot answers tagged

3 votes
Accepted

PyQGIS get active group

The layer tree is a QTreeView object where you can access any selected row via its selectionModel. def activeGroup(): tree_view = iface.layerTreeView() # retrieve current selected index ...
user avatar
  • 1,719
3 votes

Finding duplicates in field depending on another field's values using PyQGIS

I like collections.defaultdict(list): from collections import defaultdict layer = QgsProject.instance().mapLayersByName('ok_ak_riks')[0] fieldnames = ['kom_kod', 'lan_kod'] d = defaultdict(list) for f ...
user avatar
  • 52.1k
2 votes

PyQGIS generate WMS service description XML for TMS service

Read the OSM tile usage policies from https://operations.osmfoundation.org/policies/tiles/ What you hit here is this requirement: Technical Usage Requirements Valid HTTP User-Agent identifying ...
user avatar
  • 52.3k
2 votes

Finding duplicates in field depending on another field's values using PyQGIS

Try this: layer = iface.activeLayer() field_a = 'Field1' # set inside quotes the name of Field1 field_b = 'Field2' # set inside quotes the name of Field2 feat_list = [(feature.attribute(field_a), ...
user avatar
  • 811
1 vote

Deleting all fields from attributetable in qgis processing script

Try this: def deletecolumn(layer, output): #Drop all fields of the layer dropfields = [field.name() for field in layer.fields()] # iterate over the layer's fields and store the fieldnames in ...
user avatar
  • 25.5k
1 vote

Exporting several layers as GeoPackages at same time in QGIS

Another solution is to use the "Package layers" tool as a Batch Process.
user avatar
  • 24k
1 vote

Exporting several layers as GeoPackages at same time in QGIS

Try the Package layers tool, and you can export the styles and metadata. The problem in your code is the name of the OGR driver. You must set the OGR driver to GPKG instead of GeoPackage. myDir = '' ...
user avatar
  • 811
1 vote

Selecting only N records from layer using PyQGIS

Another option is to use the "Random selection" tool for selecting N random features. import processing layer = iface.activeLayer() processing.run("qgis:randomselection", { ...
user avatar
  • 24k

Only top scored, non community-wiki answers of a minimum length are eligible