File: decimate.py

package info (click to toggle)
rasterio 1.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 22,744 kB
  • sloc: python: 22,881; sh: 795; makefile: 275; xml: 29
file content (31 lines) | stat: -rw-r--r-- 761 bytes parent folder | download | duplicates (7)
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
import os.path
import subprocess
import tempfile

import rasterio
import rasterio.shutil

with rasterio.Env():

    with rasterio.open('tests/data/RGB.byte.tif') as src:
        b, g, r = (src.read(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(a, indexes=k)

    outfilename = os.path.join(tempfile.mkdtemp(), 'decimate.jpg')

    rasterio.shutil.copy(tmpfilename, outfilename, driver='JPEG', quality='30')

info = subprocess.call(['open', outfilename])