Skip to content

Instantly share code, notes, and snippets.

View NathanW2's full-sized avatar

Nathan Woodrow NathanW2

View GitHub Profile
def counter(start, interval):
count = start
while True:
yield count
count += interval
count = counter(start=1, interval=1)
def autoIncrement():
return str(count.next()).zfill(3)
CALL "C:\Program Files\QGIS 3.4\bin\o4w_env.bat"
CALL "C:\Program Files\QGIS 3.4\bin\py3_env.bat"
CALL "C:\Program Files\QGIS 3.4\bin\qt5_env.bat"
SET PYTHONPATH=C:\Program Files\QGIS 3.4\apps\qgis-ltr\python
cmd
@NathanW2
NathanW2 / gist:4029400
Created November 7, 2012 03:21
Print composer
from qgis.core import *
from qgis.gui import *
from PyQt4.QtCore import *
from PyQt4.QtGui import QApplication
from PyQt4.QtXml import *
import sys
import xml.etree.ElementTree as ET
app = QgsApplication([], True)
import os, arcpy
#create blank text file
with open("C:\\Temp\\GISlayers.txt", "w") as txt:
for root, dirs, files in os.walk("C:\\Temp\\temp"):
for f in files:
#look for shapefiles
if f.endswith('.shp') or f.endswith('.lyr') or
f.endswith('.img'):
desc = arcpy.Describe(root + "\\" + f)
SET OSGEO4W_ROOT=C:\Program Files\QGIS 3.2
SET QGISNAME=qgis
SET QGIS=%OSGEO4W_ROOT%\apps\%QGISNAME%
set QGIS_PREFIX_PATH=%QGIS%
CALL "%OSGEO4W_ROOT%\bin\qt5_env.bat"
CALL "%OSGEO4W_ROOT%\bin\py3_env.bat"
set PATH=%OSGEO4W_ROOT%\bin;%QGIS%\bin;C:\Program Files (x86)\Git\bin;%PATH%;
set PYTHONPATH=%PYTHONPATH%;%QGIS%\python
SET ROOT=C:\Program Files\QGIS 3.0
CALL "%ROOT%\bin\o4w_env.bat"
CALL "%ROOT%\bin\py3_env.bat"
CALL "%ROOT%\bin\qt5_env.bat"
SET PYTHONPATH=%PYTHONPATH%;%ROOT%\apps\qgis\python
SET PYCHARM="C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.2\bin\pycharm64.exe"
start "PyCharm aware of QGIS" /B %PYCHARM% %*
@NathanW2
NathanW2 / svg.py
Last active February 12, 2018 18:19
Web images as QGIS markers
import requests
import base64
@qgsfunction(args='auto', group='Custom')
def show_camera(feed, feature, parent):
svg = """
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg>
<g>
<image xlink:href="data:image/jpeg;base64,{0}" height="256" width="320" />
string user = @"MULTIPOLYGON (
((497140.111504213 7000067.0051564, 497140.111504239 7000067.00515642,
497108.282321511 6999764.50865007, 496870.11273669 6999736.95241933,
496870.112736702 6999736.95241954, 496870.11273669 6999736.95241954,
496874.346768004 6999813.10375028, 497140.111504239 7000067.00515664,
497140.111504213 7000067.0051564)),
((497171.990745506 7000155.85678491,
497171.990745576 7000155.85678476, 496850.952737626 6999819.44373352,
496816.906830532 6999899.81645738, 496816.9068306 6999899.81645744,
496816.906830532 6999899.8164576, 497150.71415798 7000200.27434632,
@NathanW2
NathanW2 / walkexpressioon.py
Last active January 16, 2017 13:24
Walk a QgsExpression tree
def walk(node):
if node.nodeType() == QgsExpression.ntBinaryOperator:
handle_binary(node)
elif node.nodeType() == QgsExpression.ntUnaryOperator:
print("Unary")
elif node.nodeType() == QgsExpression.ntInOperator:
print("In")
elif node.nodeType() == QgsExpression.ntFunction:
handle_function(node)
elif node.nodeType() == QgsExpression.ntLiteral:
ogr2ogr -f "MSSQLSpatial" "MSSQL:DRIVER={SQL Server Native Client 11.0};SERVER=CC-CST-SQL3;DATABASE=GISPROD;TABLE=tech.trees;trusted_authentication=true;" "D:\Temp\Trees.sqlite" -SQL "SELECT * FROM Trees"