rasterio/examples/decimate.py
Sean Gillies 92c4cea27a Driver management (#22) and sieving (#21).
Big ugly commit, forgive me.
2014-01-21 14:19:42 -07:00

32 lines
747 B
Python

import os.path
import subprocess
import tempfile
import rasterio
with rasterio.drivers():
with rasterio.open('rasterio/tests/data/RGB.byte.tif') as src:
b, g, r = (src.read_band(k) for k in (1, 2, 3))
meta = src.meta
tmpfilename = os.path.join(tempfile.mkdtemp(), 'decimate.tif')
meta.update(
width=src.width/2,
height=src.height/2)
with rasterio.open(
tmpfilename, 'w',
**meta
) as dst:
for k, a in [(1, b), (2, g), (3, r)]:
dst.write_band(k, a)
outfilename = os.path.join(tempfile.mkdtemp(), 'decimate.jpg')
rasterio.copy(tmpfilename, outfilename, driver='JPEG', quality='30')
info = subprocess.call(['open', outfilename])