forked from acannistra/planet-snowcover
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
28 lines (25 loc) · 1.02 KB
/
__init__.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
import numpy as np
import rasterio
from rasterio.warp import calculate_default_transform, reproject, Resampling
def reproject_raster(raster_file, dst_crs, dst_file):
dst_crs = {"init" : "EPSG:{}".format(dst_crs)}
with rasterio.open(raster_file) as src:
transform, width, height = calculate_default_transform(
src.crs, dst_crs, src.width, src.height, *src.bounds)
kwargs = src.meta.copy()
kwargs.update({
'crs': dst_crs,
'transform': transform,
'width': width,
'height': height
})
with rasterio.open(dst_file, 'w', **kwargs) as dst:
for i in range(1, src.count + 1):
reproject(
source=rasterio.band(src, i),
destination=rasterio.band(dst, i),
src_transform=src.transform,
src_crs=src.crs,
dst_transform=transform,
dst_crs=dst_crs,
resampling=Resampling.nearest)