Skip to content

Instantly share code, notes, and snippets.

View NathanW2's full-sized avatar

Nathan Woodrow NathanW2

View GitHub Profile
QToolTip
{
border: 1px solid #222;
background-color: #333;
color: @text;
}
QWidget
{
color: @text;
index = self.cmbConnectionsServices.findText(to_select)
if index == -1:
index = 0
if not to_select:
index = self.cmbConnectionServices.count() - 1
self.cmbConnectionServices.setCurrentIndex(index)

Usage:

js = JSCaller(frame)
js.someJsMethod({"arg1":'test'}, "Hello World")
e import QgsApplication, QgsMapLayerRegistry
from qgis.gui import QgsMapCanvas
from qgis.core import QgsVectorLayer
from contextlib import contextmanager
@contextmanager
def qgisapp():
GUIEnabled=True
app = QgsApplication([], GUIEnabled)
FOREACH(module core)
ADD_CUSTOM_TARGET(py${module} ALL)
FILE(GLOB_RECURSE PY_FILES "${module}/*.py")
INSTALL(FILES ${PY_FILES} DESTINATION "${QGIS_PYTHON_DIR}/${module}")
ADD_CUSTOM_COMMAND(TARGET py${module}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${QGIS_PYTHON_OUTPUT_DIRECTORY}/${module}"
COMMAND ${CMAKE_COMMAND} -E copy ${PY_FILES} "${QGIS_PYTHON_OUTPUT_DIRECTORY}/${module}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
@NathanW2
NathanW2 / .gitconfig
Last active August 29, 2015 14:05
.gitconfig
[core]
autocrlf = true
[alias]
st = status -s
ci = commit
br = branch
co = checkout
amend = commit --amend
aa = add --all
ac = add -u
def change_values(layer, **kwargs):
featuremap = {}
for feature, values in kwargs.iteritems():
attrs = {}
for field, value in values.iteritems():
index = layer.dataProvider().fieldNameIndex(field)
attrs[index] = value
featuremap[feature.id()] = attrs
return layer.dataProvider().changeAttributeValues(featuremap)

Usage:

>>> selection.update(field1=1, field2="balh")
>>> selection['mylayer'].update(field1=1, field2="balh")
import os
import sys
import glob
import expressions
from qgis.core import QgsApplication
def load_user_expressions(path):
"""
Load all user expressions from the given paths
@NathanW2
NathanW2 / import.bat
Last active August 29, 2015 14:16
Import file to SQL Sever using OGR2OGR (drag and drop file onto batch file to import that file)
REM Drag and drop OGR2OGR file for importing a layer into the database
REM Drop a file that OGR supports to kick off import
@ECHO OFF
SET dbserver=localhost\SQLEXPRESS
SET dbname=Test
SET db="MSSQL:server=%dbserver%;database=%dbname%;trusted_connection=yes"
SET ARGS=-s_src EPSG:28356 -progress -overwrite -lco GEOM_NAME:SP_GEOMETRY