-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (32 loc) · 1.37 KB
/
main.py
File metadata and controls
40 lines (32 loc) · 1.37 KB
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
import matplotlib.pyplot as plt
from gis.algorithms.fjallstrom import fjallstrom_convert
from gis.algorithms.lee import lee_convert
from gis.utils.raster_generator import generate_correlated_raster
def convert(sidelength=30, algorithm='fjallstrom', error=0.3):
"""
Performs a demo of the Grid to TIN conversion algorithms using pyplot.
:param sidelength: Controls the sidelength of the randomly generated raster image.
:param algorithm: Controls the algorithm used to perform the conversion. Acceptable
values are 'fjallstrom' or 'lee'.
:param error: A float value between zero and one controlling the error rate at which
the generated TIN will have.
"""
raster = generate_correlated_raster(sidelength, 500)
if algorithm == 'fjallstrom':
dt, grid = fjallstrom_convert(raster, error)
elif algorithm == 'lee':
dt, grid = lee_convert(raster, error)
else:
return
plt.figure()
plt.title('Original Raster')
plt.imshow(raster, extent=[0, sidelength, 0, sidelength], cmap='gist_earth')
plt.xticks([])
plt.yticks([])
raster = grid.convert_to_raster()
plt.figure()
plt.title('Converted raster at {}% Error'.format(error * 100))
plt.imshow(raster, extent=[0, sidelength, 0, sidelength], cmap='gist_earth')
plt.xticks([])
plt.yticks([])
plt.show()