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 ...
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 ...
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 ...
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), ...
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 ...
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.
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 = ''
...
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", {
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
pyqgis × 6547qgis × 2719
python × 1104
qgis-3 × 928
qgis-plugins × 900
qgis-processing × 557
pyqgis-3 × 303
qgis-2 × 290
raster × 203
pyqt × 181
layers × 164
fields-attributes × 144
python-2.7 × 144
print-composer × 142
gdal × 141
shapefile × 122
postgis × 113
standalone × 105
coordinate-system × 102
attribute-table × 101
qgis-python-console × 96
pyqt5 × 88
symbology × 87
vector × 78
polygon × 76