Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Woodrow NathanW2

View GitHub Profile
@NathanW2
NathanW2 / snapping.py
Last active Oct 17, 2015 — forked from mtravis/snapping.py
turn snapping on/off in QGIS
View snapping.py
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")
View 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
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')
expression.prepare(allFieldsMap)
if expression.hasParserError():
raise Exception('Parser error !!')
def getFeatures():
if self.selectedOnly:
You can’t perform that action at this time.