|
import rasterio |
|
|
|
files = [ |
|
"urbanwatch-atlanta-2017.tif", |
|
"urbanwatch-boston-2014.tif", |
|
"urbanwatch-charlotte-2016.tif", |
|
"urbanwatch-chicago-2017.tif", |
|
"urbanwatch-dallas-2016.tif", |
|
"urbanwatch-denton-county-2020.tif", |
|
"urbanwatch-denver-2017.tif", |
|
"urbanwatch-des-moines-2017.tif", |
|
"urbanwatch-detroit-2014.tif", |
|
"urbanwatch-houston-2016.tif", |
|
"urbanwatch-los-angeles-2014.tif", |
|
"urbanwatch-miami-2017.tif", |
|
"urbanwatch-minneapolis-2017.tif", |
|
"urbanwatch-new-york-city-2017.tif", |
|
"urbanwatch-philadelphia-2017.tif", |
|
"urbanwatch-phoenix-2015.tif", |
|
"urbanwatch-raleigh-2016.tif", |
|
"urbanwatch-riverside-2014.tif", |
|
"urbanwatch-san-diego-2014.tif", |
|
"urbanwatch-san-francisco-2014.tif", |
|
"urbanwatch-seattle-2017.tif", |
|
"urbanwatch-st-louis-2014.tif", |
|
"urbanwatch-washington-dc-2017.tif" |
|
] |
|
|
|
with rasterio.Env(): |
|
|
|
for f in files: |
|
|
|
with rasterio.open('input/{}'.format(f)) as src: |
|
orig = src.read(1) |
|
meta = src.meta |
|
meta.update(compress='deflate', nodata=0) |
|
# deflate is better than the lzw used in the video |
|
|
|
with rasterio.open('output/{}'.format(f), 'w', **meta) as dst: |
|
dst.write(orig, indexes=1) |
|
dst.write_colormap( |
|
1, { |
|
0: (0, 0, 0, 255), |
|
1: (255, 0, 0, 255), |
|
2: (133, 133, 133, 255), |
|
3: (255, 0, 192, 255), |
|
4: (34, 139, 34, 255), |
|
5: (128, 236, 104, 255), |
|
6: (255, 193, 37, 255), |
|
7: (0, 0, 255, 255), |
|
8: (128, 0, 0, 255), |
|
9: (255, 255, 255, 255) }) |