QGIS - PHIntelligence/CodingStandards GitHub Wiki
Settings keys
Get a list of all QGIS settings keys from the python console:
print('\n'.join(QSettings().allKeys() ) )
Copy the list into Excel to search for specific keys.
To see what the current value of a key is:
QSettings().value('browser/favourites')
Startup script example
For QGIS 3.6, the script will be here: C:/Users/%username%/AppData/Roaming/QGIS/QGIS3/startup.py
from qgis.PyQt.QtCore import QSettings
from datetime import *
import shutil
import os
# get the latest version of statup.py
src = '//ServerName/Folder/Folder/StartUpMaster/startup.py'
usr = os.environ['username']
dst = 'C:/Users/' + usr + '/AppData/Roaming/QGIS/QGIS3/startup.py'
now = datetime.now()
# Update this script from the master copy
# The changes will take effect the next time QGIS is launched
shutil.copy2(src, dst)
# User variables
QSettings().setValue('variables/os_copyright', "\xa9 Crown Copyright and database right " + str(now.year) + ". Ordnance Survey")
# Layout template path
QSettings().setValue('core/Layout/searchPathsForTemplates', '//ServerName/Folder/Folder/TemplateFolder')
# Network settings
QSettings().setValue('proxy/proxyEnabled', True)
Batch file to perform the initial install:
xcopy //ServerName/Folder/Folder/StartUpMaster/startup.py C:\Users\%username%\AppData\Roaming\QGIS\QGIS3\ /Y
QGIS Atlas
Load the vector boundary layer for the atlas
Create a new print layout
Add the map to the layout
Go to the Atlas Settings (right-most button on the top toolbar)
Check "Generate an atlas"
Choose the "Coverage layer" from the drop down
Select the map item in the layout and in its Item Properties check "Controlled by Atlas"
Now click the Atlas Preview button on the top toolbar
Make title text change to the name of the selected area from the coverage layer
In a text box, use this expression:
[% @atlas_pagename %]
Style the layer so that only the selected boundary is shown in the atlas
In the layer styling for the boundary layer, change the layer styling type to "Rule-based"
This, by default, will style everything as the same style using a blank rule
Edit the rule and enter in the "Filter" text box: $id = @atlas_featureid
Set the style fill and stroke as desired.
Go back to the print layout and cycle through the boundaries in the atlas preview.
Make a point layer only show when it is related to the coverage layer
Layer styling rule:
PCN = @atlas_pagename
This assumes that the point layer, e.g., GPs, contains a column called PCN which can join to the names in the column being used for the atlas page name.
Make a point layer only show when it is within the coverage layer
Layer styling rule:
within( $geometry , @atlas_geometry)