-
Notifications
You must be signed in to change notification settings - Fork 1
/
Example.txt
82 lines (63 loc) · 2.75 KB
/
Example.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Richard Wen @ Ryerson University (rwen@ryerson.ca)
# Last Updated: 03 April 2015
# -------------------------------------------------------------------------
# Setup in Python Console on QGIS
# -------------------------------------------------------------------------
import sys
sys.path.append("path\\to\\folder\\QGIS_RasterArray")
from RasterArray import *
# -------------------------------------------------------------------------
# Game of Life with Random Raster
# -------------------------------------------------------------------------
# 1. Create Game of Life Object with a Random Raster (x) of dimension 10w by 10h
x = GameofLife(width=10,height=10)
# 2. Cycle the Game Board
# Run through 10 cycles
x.cycle(10)
# Run through 5 cycles
x.cycle(5)
# 3. Reset the Game Board
x.reset() # Reset to the beginning board
# 4. Change Settings
x.speed = 1 # pause for 1 second every cycle
x.overwrite = False # do not overwrite cycles, display all of them as layers
# 5. Cycle the Game Board after a Reset
# Run through 8 cycles
x.cycle(8)
# -------------------------------------------------------------------------
# Game of Life with Cell Manipulated Raster
# -------------------------------------------------------------------------
# 1. Create a Cell Array (y) with 10w by 10h Cell filled with Alive Cells (1)
y = Cells(inRaster=1)
# 2. See Cell Values at (x,y): (5,5) (2,3) (1,6) (8,4)
print y.get(5,5,geographic=False)
print y.get(2,3,geographic=False)
print y.get(1,6,geographic=False)
print y.get(8,4,geographic=False)
# 3. Modify Cell Values at (x,y): (5,5) (2,3) (1,6) (8,4)
y.modify(5,5,0,geographic=False)
y.modify(2,3,0,geographic=False)
y.modify(1,6,0,geographic=False)
y.modify(8,4,0,geographic=False)
# 4. See Modified Cell Values at (x,y): (5,5) (2,3) (1,6) (8,4)
print y.get(5,5,geographic=False)
print y.get(2,3,geographic=False)
print y.get(1,6,geographic=False)
print y.get(8,4,geographic=False)
# 5. Create Raster with Modified Cells
y.toRaster("path\\to\\raster\\file.tif")
# 5. Start Game of Life with Created Raster
x = GameofLife(raster="path\\to\\raster\\file.tif")
x.cycle(10) ## cycle 10 times
x.cycle(10,5) ## cycle 10 times, but jump by 5 cycles each time
# -------------------------------------------------------------------------
# Game of Life with Custom Created Raster
# -------------------------------------------------------------------------
# 1. Create a Cell Array (y) with 5w by 5h Cell with Custom Values
y = Cells(inRaster=[(1,1,1,0,1),(1,0,0,0,0),(0,0,0,1,1),(0,1,1,0,1),(1,0,1,0,1)])
# 2. Create Raster with Custom Cells
y.toRaster("path\\to\\raster\\file.tif")
# 3. Start Game of Life with Custom Raster
x = GameofLife(raster="path\\to\\raster\\file.tif")
x.cycle(10) ## cycle 10 times
x.cycle(10,2) ## cycle 10 times, but jump by 2 cycles each time