QGis 2.18 (Las Palmas)
Notepad++ (or your favorite editor)
Plugin Builder
Plugin Reloader (experimental)
QOSM
QuickOSM
Available on Github
> import sys
> sys.version
'2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]'
Python 2
Qt 4
Python 3
Qt 5
> a = 1
> type(a)
type 'int'
> b = 1.0
> type(b)
type 'float'
> 3/2
1
> 3.0/2.0
1.5
> int(3.0/2.0)
1
> c = 'a'
> type(c)
type 'str'
> d = "b"
> type(d)
type 'str'
> c+d
'ab'
> a = 1
> a = a + 1
> a += 1
> a
3
> a == 4
False
> l = [1, 2, 3]
> type(l)
type 'list'
> len(l)
3
> (l[0], l[-1])
(1, 3)
> l.append(4)
> l
[1, 2, 3, 4]
> l = [1, 2, 3]
> [i*2 for i in l if i < 3]
[2, 4]
> max(-2, 0)
0
> 'bugs:bunny'.split(':')
['bugs', 'bunny']
> import random
> random.randint(0, 10)
4
if a:
print('a')
elif b:
print('b')
else:
print('c')
if a:
print('a')
if b:
print('b')
else:
print('c')
if a:
print('a')
if b:
print('b')
else:
print('c')
def longer(text, letterCount=3):
return text + text[-1]*letterCount
> longer('YOLO')
'YOLOOOO'
> longer('YOLO', 6)
'YOLOOOOOOO'
def sumOfDoubles(list):
def double(number):
return number*2
sum = 0
for item in list:
sum += double(item)
return sum
sum([i*2 for i in list])
class Game(object):
def __init__(self, name, maxPlayers):
self.name = name
self.maxPlayers = maxPlayers
def play(self, players):
if players > self.maxPlayers:
return 'Too many players!'
else:
return 'Enjoy your game of ' + self.name + '!'
stratego = Game('Stratego', 2)
risk = Game('Risk', 6)
stratego.play(3)
# Too many players!
risk.play(3)
# Enjoy your game of Risk!
Framework for graphical user interfaces
(and other things)
label = QLabel("Initial text.")
label.setText("Text changed to this text.")
label.setText("Or this.")
scorePanel = QLCDNumber()
scorePanel.display(42)
scorePanel.display(1337)
def start():
print('The game is on!')
button = QPushButton("Start")
button.setEnabled(True)
button.clicked.connect(start)
webView = QWebView()
webView.setUrl(QUrl("http://www.qgis.org"))
webView.setHtml("")
> iface
qgis._gui.QgisInterface object at 0x0000000006E7D0D07
> iface.actionAddWmsLayer()
PyQt4.QtGui.QAction object at 0x000000001B53FAE8
> iface.actionAddWmsLayer().trigger()
> point1 = QgsPoint(100.0, 200.0)
> point2 = QgsPoint(100.0, 500.0)
> point1.x()
100.0
> point1.y()
200.0
> point1.distance(point2)
300.0
> point1.azimuth(QgsPoint(200.0,500.0))
18.43494882292201
def printPoint(self, point):
print(point.x(), point.y())
canvas = iface.mapCanvas()
canvas.xyCoordinates.connect(printPoint)
def printPoint(self, point):
print(point.x(), point.y())
canvas = iface.mapCanvas()
mapToolPoint = QgsMapToolEmitPoint(canvas)
mapToolPoint.canvasClicked.connect(printPoint)
canvas.setMapTool(mapToolPoint)
wgs84 = QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId)
lambert72 = QgsCoordinateReferenceSystem(31370, QgsCoordinateReferenceSystem.EpsgCrsId)
webmercator = QgsCoordinateReferenceSystem(3857, QgsCoordinateReferenceSystem.EpsgCrsId)
canvasCRS = canvas.mapRenderer().destinationCrs()
t = QgsCoordinateTransform(wgs84, canvasCRS)
transformedPoint = t.transform(QgsPoint(100.0, 200.0))
> vectorLayer = iface.activeLayer()
> vectorLayer
qgis._core.QgsVectorLayer object at 0x000000001B2720D0
> features = vectorLayer.getFeatures(QgsFeatureRequest(1))
> features.next()
qgis._core.QgsFeature object at 0x000000001B272158
> feature = vectorLayer.getFeatures(QgsFeatureRequest(1)).next()
> feature.attribute('name')
u'Manneken Pis'
> feature.geometry().asPoint()
(4.34999,50.845)
~/.qgis2/python/plugins/GeoGame
Shift + right click in plugin directory, then
'Open command window here'
"C:\Program Files\QGIS 2.18\bin\pyrcc4.exe" resources.qrc > resources.py