Skip to content

Instantly share code, notes, and snippets.


Nathan Woodrow NathanW2

View GitHub Profile
NathanW2 /
Last active Oct 17, 2015 — forked from mtravis/
turn snapping on/off in QGIS
from qgis.utils import iface
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def snapping_toggle():
#layer = QgsMapLayerRegistry.instance().mapLayersByName("topographicline")[0]
layer = iface.activeLayer()
_, enabled, _, _, _, _ = QgsProject.instance().snapSettingsForLayer(
QgsProject.instance().setSnapSettingsForLayer(, not enabled, 0, 1, 10, True)
print "set {} snapping {}".format(, "Off" if not enabled else "On")
View bbox
from qgis.utils import iface
from qgis.core import QGis
from qgiscommand.command import command
def bbox():
layer = iface.activeLayer()
def pbounds (Lextent,s):
e = Lextent
View gist:6726789
import os
import sys
import sip
from qgis.core import (
QgsApplication, QgsVectorLayer, QgsField,
QgsFields, QgsFeature, QgsGeometry, QgsPoint, QgsMapLayerRegistry)
from PyQt4.QtCore import QVariant
View gist:4443083
computeFieldIndex = layer.fieldNameIndex('population')
allFieldsMap = layer.pendingFields()
expression = QgsExpression('"affected" = 1')
if expression.hasParserError():
raise Exception('Parser error !!')
def getFeatures():
if self.selectedOnly:
You can’t perform that action at this time.