-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
75 lines (63 loc) · 1.5 KB
/
test.py
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
from matplotlib.colors import LinearSegmentedColormap
import matplotlib.pyplot as plt
from mercantile import Tile
import rasterio
from openterrain import render_hillshade
POSITRON_RAMP = {
"red": [(0.0, 0.0, 0.0),
(1.0, 1.0, 1.0)],
"green": [(0.0, 0.0, 0.0),
(1.0, 1.0, 1.0)],
"blue": [(0.0, 0.0, 0.0),
(1.0, 1.0, 1.0)],
"alpha": [(0.0, 1.0, 1.0),
(180 / 255.0, 0.0, 0.0),
(1.0, 1.0, 1.0)]
}
POSITRON = LinearSegmentedColormap("positron", POSITRON_RAMP)
meta = {}
hs = render_hillshade(Tile(722, 1579, 12), src_meta=meta, resample_factor=0.8)
meta.update(
driver="GTiff",
dtype=rasterio.uint8,
compress="deflate",
predictor=1,
nodata=None,
tiled=True,
sparse_ok=True,
blockxsize=256,
blockysize=256,
)
with rasterio.open("/tmp/12_722_1579_resampled.tif", "w", **meta) as tmp:
tmp.write(hs, 1)
plt.imsave(
"/tmp/12_722_1579_resampled.png",
hs,
cmap=POSITRON,
vmin=0,
vmax=255,
format="png",
)
meta = {}
hs = render_hillshade(Tile(722, 1579, 12), src_meta=meta, resample_factor=1.0)
meta.update(
driver="GTiff",
dtype=rasterio.uint8,
compress="deflate",
predictor=1,
nodata=None,
tiled=True,
sparse_ok=True,
blockxsize=256,
blockysize=256,
)
with rasterio.open("/tmp/12_722_1579.tif", "w", **meta) as tmp:
tmp.write(hs, 1)
plt.imsave(
"/tmp/12_722_1579.png",
hs,
cmap=POSITRON,
vmin=0,
vmax=255,
format="png",
)