@@ -1408,7 +1408,14 @@ def _resize(self, ratio_x, ratio_y, resampling):
1408
1408
"""Return raster resized by ratio."""
1409
1409
new_width = int (np .ceil (self .width * ratio_x ))
1410
1410
new_height = int (np .ceil (self .height * ratio_y ))
1411
- dest_affine = self .affine * Affine .scale (1 / ratio_x , 1 / ratio_y )
1411
+
1412
+ if self .crs is None and self .rpcs is not None :
1413
+ # resize raster with rpcs
1414
+ dest_rpcs = self ._resize_rpcs (ratio_x , ratio_y )
1415
+ dest_affine = self .affine
1416
+ else :
1417
+ dest_affine = self .affine * Affine .scale (1 / ratio_x , 1 / ratio_y )
1418
+ dest_rpcs = self .rpcs
1412
1419
1413
1420
window = rasterio .windows .Window (0 , 0 , self .width , self .height )
1414
1421
resized_raster = self .get_window (
@@ -1417,10 +1424,20 @@ def _resize(self, ratio_x, ratio_y, resampling):
1417
1424
ysize = new_height ,
1418
1425
resampling = resampling ,
1419
1426
affine = dest_affine ,
1427
+ rpcs = dest_rpcs
1420
1428
)
1421
1429
1422
1430
return resized_raster
1423
1431
1432
+ def _resize_rpcs (self , ratio_x , ratio_y ):
1433
+ """resize raster by using its rpcs"""
1434
+ dest_rpcs = copy (self .rpcs )
1435
+ dest_rpcs .line_off = dest_rpcs .line_off * ratio_y
1436
+ dest_rpcs .samp_off = dest_rpcs .samp_off * ratio_x
1437
+ dest_rpcs .line_scale = dest_rpcs .line_scale * ratio_y
1438
+ dest_rpcs .samp_scale = dest_rpcs .samp_scale * ratio_x
1439
+ return dest_rpcs
1440
+
1424
1441
def to_pillow_image (self , return_mask = False ):
1425
1442
"""Return Pillow. Image, and optionally also mask."""
1426
1443
img = np .rollaxis (np .rollaxis (self .image .data , 2 ), 2 )
@@ -1997,7 +2014,7 @@ def _read_with_mask(raster, masked):
1997
2014
1998
2015
def get_window (self , window , bands = None ,
1999
2016
xsize = None , ysize = None ,
2000
- resampling = Resampling .cubic , masked = None , affine = None
2017
+ resampling = Resampling .cubic , masked = None , affine = None , rpcs = None
2001
2018
):
2002
2019
"""Get window from raster.
2003
2020
@@ -2008,6 +2025,8 @@ def get_window(self, window, bands=None,
2008
2025
:param resampling: which Resampling to use on reading, default Resampling.cubic
2009
2026
:param masked: if True uses the maks, if False doesn't use the mask, if None looks to see if there is a mask,
2010
2027
if mask exists using it, the default None
2028
+ :param affine: Set destination affine otherwise calculate from output window shape
2029
+ :param rpcs: If not none set destination rpcs
2011
2030
:return: GeoRaster2 of tile
2012
2031
"""
2013
2032
bands = bands or list (range (1 , self .num_bands + 1 ))
@@ -2029,7 +2048,7 @@ def get_window(self, window, bands=None,
2029
2048
array = raster .read (bands , ** read_params )
2030
2049
nodata = 0 if not np .ma .isMaskedArray (array ) else None
2031
2050
affine = affine or self ._calculate_new_affine (window , out_shape [2 ], out_shape [1 ])
2032
- raster = self .copy_with (image = array , affine = affine , nodata = nodata )
2051
+ raster = self .copy_with (image = array , affine = affine , nodata = nodata , rpcs = rpcs )
2033
2052
2034
2053
return raster
2035
2054
0 commit comments