Skip to content

Instantly share code, notes, and snippets.

View NathanW2's full-sized avatar

Nathan Woodrow NathanW2

View GitHub Profile
@NathanW2
NathanW2 / snapping.py
Last active October 17, 2015 11:54 — forked from mtravis/snapping.py
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(layer.id())
QgsProject.instance().setSnapSettingsForLayer(layer.id(), not enabled, 0, 1, 10, True)
print "set {} snapping {}".format(layer.name(), "Off" if not enabled else "On")
@NathanW2
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
@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')
expression.prepare(allFieldsMap)
if expression.hasParserError():
raise Exception('Parser error !!')
def getFeatures():
if self.selectedOnly: