import rastereasy
Resampling
name_im='./data/demo/sentinel.tif'
image=rastereasy.Geoimage(name_im)
image.info()
- Size of the image:
- Rows (height): 1000
- Cols (width): 1000
- Bands: 12
- Spatial resolution: 10.0 meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: int16
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands:
{'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
help(image.resampling)
Help on method resampling in module rastereasy.rastereasy:
resampling(
final_resolution,
dest_name=None,
inplace=False,
method='cubic_spline',
update_history=True
) method of rastereasy.rastereasy.Geoimage instance
Resample the image to a different resolution in-place.
This method changes the spatial resolution of the image by resampling the pixel values.
The resampling process creates a new grid of pixels at the target resolution and
interpolates values from the original grid.
Parameters
----------
final_resolution : float
The target resolution in the image's coordinate system units (typically meters or degrees).
A smaller value results in a higher-resolution (larger) image.
dest_name : str, optional
Path to save the resampled image. If None, the image is not saved.
Default is None.
inplace : bool, default False
If False, return a copy. Otherwise, do the resampling in place and return None.
method : str, optional
Resampling algorithm to use. Options include:
- 'cubic_spline' (default): High-quality interpolation, good for continuous data
- 'nearest': Nearest neighbor interpolation, preserves original values, best for categorical data
- 'bilinear': Linear interpolation between points, faster than cubic
- 'cubic': Standard cubic interpolation
- 'lanczos': High-quality downsampling
- 'average': Takes the average of all contributing pixels, useful for downsampling
update_history : bool, optional
Whether to update the image processing history. Default is True.
Returns
-------
Geoimage
A copy of the resampled image
Examples
--------
>>> # Resample to 30 meter resolution
>>> image_resampled = image.resampling(30)
>>> print(f"New resolution: {image.resolution}")
>>>
>>> # Resample using nearest neighbor (best for categorical data)
>>> classified_image_resampled = classified_image.resampling(10, method='nearest')
>>>
>>> # Resample and save the result
>>> image_resampled = image.resampling(20, dest_name='resampled_20m.tif')
>>>
>>>
>>> # Resample directly the image to 30 meter resolution
>>> image.resampling(30, inplace=True)
>>> print(f"New resolution: {image.resolution}")
>>>
>>> # Resample directly the image using nearest neighbor (best for categorical data)
>>> classified_image.resampling(10, method='nearest', inplace=True)
>>>
>>> # Resample and save the result
>>> image.resampling(20, dest_name='resampled_20m.tif', inplace=True)
Notes
-----
- When upsampling (to higher resolution), no new information is created;
the function only interpolates between existing pixels
- When downsampling (to lower resolution), information is lost
- The choice of resampling method is important:
- For continuous data (e.g., elevation, reflectance): 'cubic_spline', 'bilinear', or 'cubic'
- For categorical data (e.g., land classifications): 'nearest' or 'mode'
- This method changes the dimensions (shape) of the image
Two options
Return a resampled image (function
resampling
)Resample the image (function
resampling
with optioninplace=True
)
1) Return a resampled image
final_resolution=150
print('Before resampling')
image.info()
image.visu("4",title='Original image',extent='pixel')
resampled_image=image.resampling(final_resolution=final_resolution,dest_name='./data/results/resampling/resampled.tif')
print('After resampling')
resampled_image.info()
resampled_image.visu("4",title='Resampled image',extent='pixel')
Before resampling
- Size of the image:
- Rows (height): 1000
- Cols (width): 1000
- Bands: 12
- Spatial resolution: 10.0 meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: int16
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands:
{'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
<Figure size 640x480 with 0 Axes>

After resampling
- Size of the image:
- Rows (height): 66
- Cols (width): 66
- Bands: 12
- Spatial resolution: 151.51515151515153 meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04035679, 38.39122988)
- Driver: GTiff
- Data type: int16
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands:
{'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
<Figure size 640x480 with 0 Axes>

2) Resampled the image directly
final_resolution=15
print('Before resampling')
image.info()
image.resampling(final_resolution=final_resolution, inplace=True)
print('Before resampling')
image.info()
Before resampling
- Size of the image:
- Rows (height): 1000
- Cols (width): 1000
- Bands: 12
- Spatial resolution: 10.0 meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04099599, 38.39058840)
- Driver: GTiff
- Data type: int16
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands:
{'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
Before resampling
- Size of the image:
- Rows (height): 666
- Cols (width): 666
- Bands: 12
- Spatial resolution: 15.015015015015013 meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.04097334, 38.39061114)
- Driver: GTiff
- Data type: int16
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands:
{'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}