Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import rasterio
- from rasterio.transform import from_bounds
- with rasterio.open(source_path) as src:
- kwds = {
- 'transform': from_bounds(*tile_bounds, tile_size, tile_size),
- 'driver': 'PNG',
- 'dtype': 'uint8',
- 'height': tile_size,
- 'width': tile_size,
- 'crs': dst_srs,
- 'count': src.count + 1
- }
- # create the output directory
- os.makedirs(os.path.dirname(output_path), exist_ok=True)
- with rasterio.open(output_path, 'w', **kwds) as dst:
- for i in range(1, src.count + 1):
- reproject_args = {
- 'source': rasterio.band(src, i),
- 'destination': rasterio.band(dst, i),
- 'resampling': self._get_resample_alg_value(resample_alg),
- 'dst_alpha': src.count + i
- }
- # can only specify nan nodata value on float32 and float64 input bands
- if src.dtypes[i-1].startswith('float'):
- reproject_args['src_nodata'] = numpy.nan
- reproject(**reproject_args)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement