Skip to content

Instantly share code, notes, and snippets.

View NathanW2's full-sized avatar

Nathan Woodrow NathanW2

View GitHub Profile
NathanW2 /
Last active October 17, 2015 11:54 — 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")
NathanW2 / bbox
Last active August 29, 2015 14:23 — forked from antoniolocandro/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
import os
import sys
import sip
from qgis.core import (
QgsApplication, QgsVectorLayer, QgsField,
QgsFields, QgsFeature, QgsGeometry, QgsPoint, QgsMapLayerRegistry)
from PyQt4.QtCore import QVariant
computeFieldIndex = layer.fieldNameIndex('population')
allFieldsMap = layer.pendingFields()
expression = QgsExpression('"affected" = 1')
if expression.hasParserError():
raise Exception('Parser error !!')
def getFeatures():
if self.selectedOnly: